Skip to content

Commit

Permalink
[Integrated-Test] Fix the integrated test of request plugin (apache#2360
Browse files Browse the repository at this point in the history
)

* Fix the integrated test of request plugin

* add pom dependency for request plugin
  • Loading branch information
JooKS-me authored Nov 15, 2021
1 parent 1017939 commit 78dc790
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
8 changes: 8 additions & 0 deletions shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@
<version>${project.version}</version>
</dependency>

<!-- apache shenyu request plugin start-->
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-request</artifactId>
<version>${project.version}</version>
</dependency>
<!-- apache shenyu request plugin end-->

<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-integrated-test-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class RequestPluginTest extends AbstractPluginDataInit {

@BeforeClass
public static void setup() throws IOException {
String pluginResult = initPlugin(PluginEnum.SENTINEL.getName(), "{\"model\":\"black\"}");
String pluginResult = initPlugin(PluginEnum.REQUEST.getName(), null);
assertThat(pluginResult, is("success"));
String selectorAndRulesResult = initSelectorAndRules(PluginEnum.REQUEST.getName(), "", buildSelectorConditionList(), buildRuleLocalDataList());
assertThat(selectorAndRulesResult, is("success"));
Expand All @@ -58,20 +58,20 @@ public static void setup() throws IOException {
public void test() throws IOException {
Map<String, Object> paramMap = new HashMap<>();

Map<String, Object> result = HttpHelper.INSTANCE.getFromGateway("/http/test/request/parameter/pass?requestParameter=requestParameter", paramMap, Map.class);
Map<String, Object> result = HttpHelper.INSTANCE.getFromGateway("/http/test/request/parameter/pass?requestParameter=NULL", paramMap, Map.class);
assertNotNull(result);
assertEquals("pass", result.get("msg"));
assertEquals("requestParameter", GsonUtils.getInstance().convertToMap(String.valueOf(result.get("data"))).get("requestParameter"));

paramMap.clear();
paramMap.put("requestHeader", "requestHeader");
paramMap.put("requestHeader", "NULL");
result = HttpHelper.INSTANCE.getFromGateway("/http/test/request/header/pass", paramMap, Map.class);
assertNotNull(result);
assertEquals("pass", result.get("msg"));
assertEquals("requestHeader", GsonUtils.getInstance().convertToMap(String.valueOf(result.get("data"))).get("requestHeader"));

paramMap.clear();
paramMap.put("cookie", new HttpCookie("cookie", "cookie"));
paramMap.put("cookie", new HttpCookie("cookie", "NULL"));
result = HttpHelper.INSTANCE.getFromGateway("/http/test/request/cookie/pass", paramMap, Map.class);
assertNotNull(result);
assertEquals("pass", result.get("msg"));
Expand All @@ -88,11 +88,11 @@ private static List<ConditionData> buildSelectorConditionList() {

private static List<RuleLocalData> buildRuleLocalDataList() {
List<RuleLocalData> ruleLocalDataList = new ArrayList<>();
ruleLocalDataList.add(buildRuleLocalData("/http/test/request/pass"));
ruleLocalDataList.add(buildRuleLocalData());
return ruleLocalDataList;
}

private static RuleLocalData buildRuleLocalData(final String paramValue) {
private static RuleLocalData buildRuleLocalData() {
final RuleLocalData ruleLocalData = new RuleLocalData();
RequestHandle requestHandle = new RequestHandle();
final RequestHandle.ShenyuRequestParameter requestParameter = requestHandle.new ShenyuRequestParameter();
Expand All @@ -101,24 +101,24 @@ private static RuleLocalData buildRuleLocalData(final String paramValue) {

Map<String, String> paramMap = new HashMap<>();
paramMap.put("requestParameter", "requestParameter");
requestParameter.setSetParameters(paramMap);
requestParameter.setSetParameters(new HashMap<>(paramMap));
requestHandle.setParameter(requestParameter);

paramMap.clear();
paramMap.put("requestHeader", "requestHeader");
requestHeader.setSetHeaders(paramMap);
requestHeader.setSetHeaders(new HashMap<>(paramMap));
requestHandle.setHeader(requestHeader);

paramMap.clear();
paramMap.put("cookie", "cookie");
cookie.setSetCookies(paramMap);
cookie.setSetCookies(new HashMap<>(paramMap));
requestHandle.setCookie(cookie);

ruleLocalData.setRuleHandler(JsonUtils.toJson(requestHandle));
ConditionData conditionData = new ConditionData();
conditionData.setParamType(ParamTypeEnum.URI.getName());
conditionData.setOperator(OperatorEnum.EQ.getAlias());
conditionData.setParamValue(paramValue);
conditionData.setOperator(OperatorEnum.MATCH.getAlias());
conditionData.setParamValue("/http/test/request/**");
ruleLocalData.setConditionDataList(Collections.singletonList(conditionData));
return ruleLocalData;
}
Expand Down

0 comments on commit 78dc790

Please sign in to comment.