Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public void before() {
*/
@Test
public void testOnPluginChanged() {
String message = "{\"groupType\":\"PLUGIN\",\"eventType\":\"UPDATE\",\"data\":[{\"id\":\"2\",\"name\":\"waf\","
+ "\"config\":\"{\\\\\\\"model\\\\\\\":\\\\\\\"black\\\\\\\"}\",\"role\":\"1\",\"enabled\":true,\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
String message = "{\"groupType\":\"PLUGIN\",\"eventType\":\"UPDATE\",\"data\":[{\"config\":\"{\\\\\\\"model\\\\\\\":\\\\\\\"black\\\\\\\"}\","
+ "\"role\":\"1\",\"id\":\"2\",\"name\":\"waf\",\"enabled\":true,\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
MockedStatic.Verification verification = () -> WebsocketCollector.send(Constants.SYS_DEFAULT_NAMESPACE_ID, message, DataEventTypeEnum.UPDATE);
try (MockedStatic<WebsocketCollector> mockedStatic = mockStatic(WebsocketCollector.class)) {
mockedStatic.when(verification).thenAnswer((Answer<Void>) invocation -> null);
Expand All @@ -88,19 +88,25 @@ public void testOnPluginChanged() {
@Test
public void testOnSelectorChanged() {
String message = "{\"groupType\":\"SELECTOR\",\"eventType\":\"UPDATE\",\"data\":"
+ "[{\"id\":\"1336329408516136960\",\"pluginId\":\"5\",\"pluginName\":\"divide\",\"name\":"
+ "\"/http\",\"matchMode\":0,\"type\":1,\"sort\":1,\"enabled\":true,\"logged\":true,"
+ "[{\"pluginId\":\"5\",\"pluginName\":\"divide\","
+ "\"matchMode\":0,\"type\":1,\"logged\":true,"
+ "\"continued\":true,\"handle\":\"[{\\\\\\\"upstreamHost\\\\\\\":\\\\\\\"localhost\\\\\\\","
+ "\\\\\\\"protocol\\\\\\\":\\\\\\\"http://\\\\\\\",\\\\\\\"upstreamUrl\\\\\\\":"
+ "\\\\\\\"127.0.0.1:8187\\\\\\\",\\\\\\\"weight\\\\\\\":\\\\\\\"51\\\\\\\"},"
+ "{\\\\\\\"upstreamHost\\\\\\\":\\\\\\\"localhost\\\\\\\",\\\\\\\"protocol\\\\\\\":"
+ "\\\\\\\"http://\\\\\\\",\\\\\\\"upstreamUrl\\\\\\\":\\\\\\\"127.0.0.1:8188\\\\\\\","
+ "\\\\\\\"weight\\\\\\\":\\\\\\\"49\\\\\\\"}]\",\"conditionList\":[{\"paramType\":\"uri\","
+ "\"operator\":\"match\",\"paramName\":\"/\",\"paramValue\":\"/http/**\"}],\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
+ "\"operator\":\"match\",\"paramName\":\"/\",\"paramValue\":\"/http/**\"}],\"id\":\"1336329408516136960\","
+ "\"name\":\"/http\",\"enabled\":true,\"sort\":1,\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
MockedStatic.Verification verification = () -> WebsocketCollector.send(Constants.SYS_DEFAULT_NAMESPACE_ID, message, DataEventTypeEnum.UPDATE);

try (MockedStatic<WebsocketCollector> mockedStatic = mockStatic(WebsocketCollector.class)) {
mockedStatic.when(verification).thenAnswer((Answer<Void>) invocation -> null);

// 调用被测试的方法
websocketDataChangedListener.onSelectorChanged(selectorDataList, DataEventTypeEnum.UPDATE);

// 验证
mockedStatic.verify(verification);
}
}
Expand All @@ -110,12 +116,13 @@ public void testOnSelectorChanged() {
*/
@Test
public void testOnRuleChanged() {
String message = "{\"groupType\":\"RULE\",\"eventType\":\"UPDATE\",\"data\":[{\"id\":\"1336350040008105984\","
+ "\"name\":\"test\",\"pluginName\":\"waf\",\"selectorId\":\"1336349806465064960\","
+ "\"matchMode\":1,\"sort\":1,\"enabled\":true,\"loged\":true,\"handle\":"
String message = "{\"groupType\":\"RULE\",\"eventType\":\"UPDATE\",\"data\":[{"
+ "\"pluginName\":\"waf\",\"selectorId\":\"1336349806465064960\","
+ "\"matchMode\":1,\"loged\":true,\"handle\":"
+ "\"{\\\\\\\"permission\\\\\\\":\\\\\\\"reject\\\\\\\",\\\\\\\"statusCode\\\\\\\":"
+ "\\\\\\\"503\\\\\\\"}\",\"conditionDataList\":[{\"paramType\":\"header\",\"operator\":"
+ "\"\\u003d\",\"paramName\":\"test\",\"paramValue\":\"a\"}],\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
+ "\"\\u003d\",\"paramName\":\"test\",\"paramValue\":\"a\"}],\"id\":\"1336350040008105984\",\"name\":\"test\","
+ "\"enabled\":true,\"sort\":1,\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
MockedStatic.Verification verification = () -> WebsocketCollector.send(Constants.SYS_DEFAULT_NAMESPACE_ID, message, DataEventTypeEnum.UPDATE);
try (MockedStatic<WebsocketCollector> mockedStatic = mockStatic(WebsocketCollector.class)) {
mockedStatic.when(verification).thenAnswer((Answer<Void>) invocation -> null);
Expand Down
151 changes: 151 additions & 0 deletions shenyu-common/src/main/java/org/apache/shenyu/common/dto/BaseData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shenyu.common.dto;

/**
* Base class for common data transfer objects.
* Contains common fields shared across SelectorData, RuleData, and PluginData.
*/

public class BaseData {

/**
* primary key id.
*/
private String id;

/**
* name.
*/
private String name;

/**
* whether enabled.
*/
private Boolean enabled;

/**
* sort order.
*/
private Integer sort;

/**
* namespace id.
*/
private String namespaceId;

/**
* get id.
*
* @return id
*/
public String getId() {
return id;
}

/**
* set id.
*
* @param id id
* @return this
*/
public BaseData setId(final String id) {
this.id = id;
return this;
}

/**
* get name.
*
* @return name
*/
public String getName() {
return name;
}

/**
* set name.
*
* @param name name
* @return this
*/
public BaseData setName(final String name) {
this.name = name;
return this;
}

/**
* get enabled.
*
* @return enabled
*/
public Boolean getEnabled() {
return enabled;
}

/**
* set enabled.
*
* @param enabled enabled
* @return this
*/
public BaseData setEnabled(final Boolean enabled) {
this.enabled = enabled;
return this;
}

/**
* get sort.
*
* @return sort
*/
public Integer getSort() {
return sort;
}

/**
* set sort.
*
* @param sort sort
* @return this
*/
public BaseData setSort(final Integer sort) {
this.sort = sort;
return this;
}

/**
* get namespaceId.
*
* @return namespaceId
*/
public String getNamespaceId() {
return namespaceId;
}

/**
* set namespaceId.
*
* @param namespaceId namespaceId
* @return this
*/
public BaseData setNamespaceId(final String namespaceId) {
this.namespaceId = namespaceId;
return this;
}
}
Loading
Loading