@@ -72,8 +72,8 @@ public void before() {
7272 */
7373 @ Test
7474 public void testOnPluginChanged () {
75- String message = "{\" groupType\" :\" PLUGIN\" ,\" eventType\" :\" UPDATE\" ,\" data\" :[{\" id \" :\" 2 \" , \" name \ " :\" waf \" ,"
76- + "\" config \" :\" { \\ \\ \\ \" model \\ \\ \\ \ " :\\ \\ \\ \" black \\ \\ \\ \" } \" ,\" role \" :\" 1 \" ,\" enabled\" :true,\" namespaceId\" :\" 649330b6-c2d7-4edc-be8e-8a54df9eb385\" }]}" ;
75+ String message = "{\" groupType\" :\" PLUGIN\" ,\" eventType\" :\" UPDATE\" ,\" data\" :[{\" config \" :\" { \\ \\ \\ \" model \\ \\ \\ \ " :\\ \\ \\ \" black \\ \\ \\ \" } \" ,"
76+ + "\" role \" :\" 1 \" , \" id \ " :\" 2 \" ,\" name \" :\" waf \" ,\" enabled\" :true,\" namespaceId\" :\" 649330b6-c2d7-4edc-be8e-8a54df9eb385\" }]}" ;
7777 MockedStatic .Verification verification = () -> WebsocketCollector .send (Constants .SYS_DEFAULT_NAMESPACE_ID , message , DataEventTypeEnum .UPDATE );
7878 try (MockedStatic <WebsocketCollector > mockedStatic = mockStatic (WebsocketCollector .class )) {
7979 mockedStatic .when (verification ).thenAnswer ((Answer <Void >) invocation -> null );
@@ -88,19 +88,25 @@ public void testOnPluginChanged() {
8888 @ Test
8989 public void testOnSelectorChanged () {
9090 String message = "{\" groupType\" :\" SELECTOR\" ,\" eventType\" :\" UPDATE\" ,\" data\" :"
91- + "[{\" id \" : \" 1336329408516136960 \" , \" pluginId\" :\" 5\" ,\" pluginName\" :\" divide\" ,\" name \" : "
92- + "\" /http \" , \" matchMode\" :0,\" type\" :1, \" sort \" :1, \" enabled \" :true ,\" logged\" :true,"
91+ + "[{\" pluginId\" :\" 5\" ,\" pluginName\" :\" divide\" ,"
92+ + "\" matchMode\" :0,\" type\" :1,\" logged\" :true,"
9393 + "\" continued\" :true,\" handle\" :\" [{\\ \\ \\ \" upstreamHost\\ \\ \\ \" :\\ \\ \\ \" localhost\\ \\ \\ \" ,"
9494 + "\\ \\ \\ \" protocol\\ \\ \\ \" :\\ \\ \\ \" http://\\ \\ \\ \" ,\\ \\ \\ \" upstreamUrl\\ \\ \\ \" :"
9595 + "\\ \\ \\ \" 127.0.0.1:8187\\ \\ \\ \" ,\\ \\ \\ \" weight\\ \\ \\ \" :\\ \\ \\ \" 51\\ \\ \\ \" },"
9696 + "{\\ \\ \\ \" upstreamHost\\ \\ \\ \" :\\ \\ \\ \" localhost\\ \\ \\ \" ,\\ \\ \\ \" protocol\\ \\ \\ \" :"
9797 + "\\ \\ \\ \" http://\\ \\ \\ \" ,\\ \\ \\ \" upstreamUrl\\ \\ \\ \" :\\ \\ \\ \" 127.0.0.1:8188\\ \\ \\ \" ,"
9898 + "\\ \\ \\ \" weight\\ \\ \\ \" :\\ \\ \\ \" 49\\ \\ \\ \" }]\" ,\" conditionList\" :[{\" paramType\" :\" uri\" ,"
99- + "\" operator\" :\" match\" ,\" paramName\" :\" /\" ,\" paramValue\" :\" /http/**\" }],\" namespaceId\" :\" 649330b6-c2d7-4edc-be8e-8a54df9eb385\" }]}" ;
99+ + "\" operator\" :\" match\" ,\" paramName\" :\" /\" ,\" paramValue\" :\" /http/**\" }],\" id\" :\" 1336329408516136960\" ,"
100+ + "\" name\" :\" /http\" ,\" enabled\" :true,\" sort\" :1,\" namespaceId\" :\" 649330b6-c2d7-4edc-be8e-8a54df9eb385\" }]}" ;
100101 MockedStatic .Verification verification = () -> WebsocketCollector .send (Constants .SYS_DEFAULT_NAMESPACE_ID , message , DataEventTypeEnum .UPDATE );
102+
101103 try (MockedStatic <WebsocketCollector > mockedStatic = mockStatic (WebsocketCollector .class )) {
102104 mockedStatic .when (verification ).thenAnswer ((Answer <Void >) invocation -> null );
105+
106+ // 调用被测试的方法
103107 websocketDataChangedListener .onSelectorChanged (selectorDataList , DataEventTypeEnum .UPDATE );
108+
109+ // 验证
104110 mockedStatic .verify (verification );
105111 }
106112 }
@@ -110,12 +116,13 @@ public void testOnSelectorChanged() {
110116 */
111117 @ Test
112118 public void testOnRuleChanged () {
113- String message = "{\" groupType\" :\" RULE\" ,\" eventType\" :\" UPDATE\" ,\" data\" :[{\" id \" : \" 1336350040008105984 \" , "
114- + "\" name \" : \" test \" , \" pluginName\" :\" waf\" ,\" selectorId\" :\" 1336349806465064960\" ,"
115- + "\" matchMode\" :1,\" sort \" :1, \" enabled \" :true, \" loged\" :true,\" handle\" :"
119+ String message = "{\" groupType\" :\" RULE\" ,\" eventType\" :\" UPDATE\" ,\" data\" :[{"
120+ + "\" pluginName\" :\" waf\" ,\" selectorId\" :\" 1336349806465064960\" ,"
121+ + "\" matchMode\" :1,\" loged\" :true,\" handle\" :"
116122 + "\" {\\ \\ \\ \" permission\\ \\ \\ \" :\\ \\ \\ \" reject\\ \\ \\ \" ,\\ \\ \\ \" statusCode\\ \\ \\ \" :"
117123 + "\\ \\ \\ \" 503\\ \\ \\ \" }\" ,\" conditionDataList\" :[{\" paramType\" :\" header\" ,\" operator\" :"
118- + "\" \\ u003d\" ,\" paramName\" :\" test\" ,\" paramValue\" :\" a\" }],\" namespaceId\" :\" 649330b6-c2d7-4edc-be8e-8a54df9eb385\" }]}" ;
124+ + "\" \\ u003d\" ,\" paramName\" :\" test\" ,\" paramValue\" :\" a\" }],\" id\" :\" 1336350040008105984\" ,\" name\" :\" test\" ,"
125+ + "\" enabled\" :true,\" sort\" :1,\" namespaceId\" :\" 649330b6-c2d7-4edc-be8e-8a54df9eb385\" }]}" ;
119126 MockedStatic .Verification verification = () -> WebsocketCollector .send (Constants .SYS_DEFAULT_NAMESPACE_ID , message , DataEventTypeEnum .UPDATE );
120127 try (MockedStatic <WebsocketCollector > mockedStatic = mockStatic (WebsocketCollector .class )) {
121128 mockedStatic .when (verification ).thenAnswer ((Answer <Void >) invocation -> null );
0 commit comments