-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge branch 'master' into dev-branch
Showing
13 changed files
with
639 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
shenyu-integrated-test/shenyu-integrated-test-rewrite/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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. | ||
|
||
FROM openjdk:8-jre-alpine | ||
|
||
ENV APP_NAME shenyu-integrated-test-rewrite | ||
ENV LOCAL_PATH /opt/${APP_NAME} | ||
|
||
RUN mkdir -p ${LOCAL_PATH} | ||
|
||
ADD target/${APP_NAME}.jar ${LOCAL_PATH} | ||
|
||
WORKDIR ${LOCAL_PATH} | ||
EXPOSE 9195 | ||
|
||
CMD java -jar ${APP_NAME}.jar |
135 changes: 135 additions & 0 deletions
135
shenyu-integrated-test/shenyu-integrated-test-rewrite/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# 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. | ||
version: "3.9" | ||
services: | ||
shenyu-zk: | ||
container_name: shenyu-zk | ||
image: zookeeper:latest | ||
restart: always | ||
networks: | ||
- shenyu | ||
expose: | ||
- 2181 | ||
healthcheck: | ||
test: [ "CMD-SHELL", "echo srvr | nc localhost 2181" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 3 | ||
start_period: 30s | ||
|
||
shenyu-redis: | ||
image: redis:latest | ||
container_name: shenyu-redis | ||
restart: always | ||
command: redis-server --requirepass abc | ||
networks: | ||
- shenyu | ||
healthcheck: | ||
test: [ "CMD", "redis-cli", "ping" ] | ||
|
||
shenyu-examples-http: | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 2048M | ||
container_name: shenyu-examples-http | ||
image: shenyu-examples-http:latest | ||
restart: always | ||
environment: | ||
- shenyu.register.serverLists=http://shenyu-admin:9095 | ||
healthcheck: | ||
test: ["CMD-SHELL", "wget -q -O - http://shenyu-examples-http:8189/actuator/health | grep UP || exit 1"] | ||
timeout: 2s | ||
retries: 30 | ||
ports: | ||
- "8189:8189" | ||
depends_on: | ||
shenyu-integrated-test-rewrite: | ||
condition: service_healthy | ||
networks: | ||
- shenyu | ||
|
||
shenyu-examples-apache-dubbo-service: | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 2048M | ||
container_name: shenyu-examples-apache-dubbo-service | ||
image: shenyu-examples-apache-dubbo-service:latest | ||
restart: always | ||
healthcheck: | ||
test: ["CMD-SHELL", "wget -q -O - http://localhost:8011/actuator/health | grep UP || exit 1"] | ||
timeout: 2s | ||
retries: 3 | ||
start_period: 5s | ||
ports: | ||
- "8011:8011" | ||
- "20888:20888" | ||
networks: | ||
- shenyu | ||
depends_on: | ||
shenyu-integrated-test-rewrite: | ||
condition: service_healthy | ||
environment: | ||
- dubbo.registry.address=zookeeper://shenyu-zk:2181 | ||
- shenyu.register.serverLists=http://shenyu-admin:9095 | ||
|
||
shenyu-admin: | ||
image: apache/shenyu-admin:latest | ||
container_name: shenyu-admin | ||
restart: always | ||
networks: | ||
- shenyu | ||
depends_on: | ||
shenyu-redis: | ||
condition: service_healthy | ||
ports: | ||
- "9095:9095" | ||
environment: | ||
- SPRING_PROFILES_ACTIVE=h2 | ||
- shenyu.database.init_script=sql-script/h2/schema.sql | ||
healthcheck: | ||
test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] | ||
timeout: 2s | ||
retries: 30 | ||
|
||
shenyu-integrated-test-rewrite: | ||
container_name: shenyu-integrated-test-rewrite | ||
image: apache/shenyu-integrated-test-rewrite:latest | ||
restart: always | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 2048M | ||
environment: | ||
- shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket | ||
depends_on: | ||
shenyu-zk: | ||
condition: service_healthy | ||
shenyu-admin: | ||
condition: service_healthy | ||
ports: | ||
- "9195:9195" | ||
networks: | ||
- shenyu | ||
healthcheck: | ||
test: [ "CMD", "wget", "http://shenyu-integrated-test-rewrite:9195/actuator/health" ] | ||
timeout: 2s | ||
retries: 30 | ||
|
||
networks: | ||
shenyu: | ||
name: shenyu |
139 changes: 139 additions & 0 deletions
139
shenyu-integrated-test/shenyu-integrated-test-rewrite/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>shenyu-integrated-test</artifactId> | ||
<groupId>org.apache.shenyu</groupId> | ||
<version>2.7.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>shenyu-integrated-test-rewrite</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.shenyu</groupId> | ||
<artifactId>shenyu-integrated-test-common</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.shenyu</groupId> | ||
<artifactId>shenyu-spring-boot-starter-plugin-divide</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!--shenyu apache dubbo plugin start--> | ||
<dependency> | ||
<groupId>org.apache.shenyu</groupId> | ||
<artifactId>shenyu-spring-boot-starter-plugin-apache-dubbo</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo</artifactId> | ||
<version>3.1.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-dependencies-zookeeper</artifactId> | ||
<version>3.1.1</version> | ||
<type>pom</type> | ||
</dependency> | ||
<!--shenyu apache dubbo plugin end--> | ||
|
||
<!-- shenyu rewrite plugin start--> | ||
<dependency> | ||
<groupId>org.apache.shenyu</groupId> | ||
<artifactId>shenyu-spring-boot-starter-plugin-rewrite</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<!-- shenyu rewrite plugin end--> | ||
|
||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>it</id> | ||
<properties> | ||
<docker.buildArg.APP_NAME>shenyu-integrated-test-rewrite</docker.buildArg.APP_NAME> | ||
<docker.image.tag.repo>apache/shenyu-integrated-test-rewrite</docker.image.tag.repo> | ||
<docker.image.tag.tagName>latest</docker.image.tag.tagName> | ||
</properties> | ||
<build> | ||
<finalName>shenyu-integrated-test-rewrite</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring-boot.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>org.apache.shenyu.integrated.test.rewrite.RewriteIntegratedBootstrap</mainClass> | ||
<executable>true</executable> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
<version>${docker-maven-plugin.version}</version> | ||
<configuration> | ||
<images> | ||
<image> | ||
<name>apache/shenyu-integrated-test-rewrite</name> | ||
<build> | ||
<contextDir>${project.basedir}</contextDir> | ||
</build> | ||
</image> | ||
</images> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>start</id> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skipTests>false</skipTests> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
shenyu-integrated-test/shenyu-integrated-test-rewrite/script/healthcheck.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
# | ||
# 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. | ||
# | ||
|
||
PRGDIR=`dirname "$0"` | ||
for service in `grep -v -E "^$|^#" ${PRGDIR}/services.list` | ||
do | ||
for loop in `seq 1 30` | ||
do | ||
status=`curl -o /dev/null -s -w %{http_code} $service` | ||
echo -e "curl $service response $status" | ||
|
||
if [ $status -eq 200 ]; then | ||
break | ||
fi | ||
|
||
sleep 2 | ||
done | ||
done | ||
|
||
sleep 3 | ||
echo -e "\n-------------------" |
20 changes: 20 additions & 0 deletions
20
shenyu-integrated-test/shenyu-integrated-test-rewrite/script/services.list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 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. | ||
|
||
http://localhost:9095/actuator/health | ||
http://localhost:8189/test/path/123?name=tom | ||
http://localhost:8011/actuator/health | ||
http://localhost:9195/actuator/health |
37 changes: 37 additions & 0 deletions
37
...e/src/main/java/org/apache/shenyu/integrated/test/rewrite/RewriteIntegratedBootstrap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.integrated.test.rewrite; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* The rewrite integrated bootstrap. | ||
*/ | ||
@SpringBootApplication | ||
public class RewriteIntegratedBootstrap { | ||
|
||
/** | ||
* main method of App. | ||
* | ||
* @param args args | ||
*/ | ||
public static void main(final String[] args) { | ||
SpringApplication.run(RewriteIntegratedBootstrap.class); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...u-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application-local.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 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. | ||
|
||
server: | ||
port: 9195 | ||
address: 0.0.0.0 | ||
|
||
spring: | ||
main: | ||
allow-bean-definition-overriding: true | ||
application: | ||
name: shenyu-bootstrap | ||
|
||
management: | ||
health: | ||
defaults: | ||
enabled: false | ||
|
||
shenyu: | ||
switchConfig: | ||
local: true | ||
cross: | ||
enabled: true | ||
sync: | ||
websocket: | ||
urls: ws://localhost:9095/websocket | ||
allowOrigin: ws://localhost:9195 | ||
exclude: | ||
enabled: true | ||
paths: | ||
- /favicon.ico | ||
- /actuator/health | ||
local: | ||
enabled: true | ||
sha512Key: "BA3253876AED6BC22D4A6FF53D8406C6AD864195ED144AB5C87621B6C233B548BAEAE6956DF346EC8C17F5EA10F35EE3CBC514797ED7DDD3145464E2A0BAB413" | ||
sharedPool: | ||
enable: true | ||
|
||
logging: | ||
level: | ||
root: info | ||
org.springframework.boot: info | ||
org.apache.ibatis: info | ||
org.apache.shenyu.bonuspoint: info | ||
org.apache.shenyu.lottery: info | ||
org.apache.shenyu: info | ||
|
18 changes: 18 additions & 0 deletions
18
shenyu-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 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. | ||
|
||
spring: | ||
profiles: | ||
active: local |
157 changes: 157 additions & 0 deletions
157
.../test/java/org/apache/shenyu/integrated/test/rewrite/ContextPathAndRewritePluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* 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.integrated.test.rewrite; | ||
|
||
import org.apache.shenyu.common.dto.ConditionData; | ||
import org.apache.shenyu.common.dto.convert.rule.RewriteHandle; | ||
import org.apache.shenyu.common.enums.OperatorEnum; | ||
import org.apache.shenyu.common.enums.ParamTypeEnum; | ||
import org.apache.shenyu.common.enums.PluginEnum; | ||
import org.apache.shenyu.common.utils.JsonUtils; | ||
import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit; | ||
import org.apache.shenyu.integratedtest.common.dto.OrderDTO; | ||
import org.apache.shenyu.integratedtest.common.helper.HttpHelper; | ||
import org.apache.shenyu.web.controller.LocalPluginController; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
/** | ||
* The integrated test for combination plugins about contextPath and rewrite. | ||
*/ | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class ContextPathAndRewritePluginTest extends AbstractPluginDataInit { | ||
|
||
@Order(1) | ||
@Test | ||
public void testRewriteCrossApplication() throws IOException { | ||
OrderDTO orderDTO = HttpHelper.INSTANCE.getFromGateway("/http/order/findById?id=1", OrderDTO.class); | ||
assertEquals("1", orderDTO.getId()); | ||
assertEquals("hello world findById", orderDTO.getName()); | ||
|
||
orderDTO = HttpHelper.INSTANCE.getFromGateway("/order/order/findById?id=3", OrderDTO.class); | ||
assertNotNull(orderDTO); | ||
assertNull(orderDTO.getId()); | ||
assertNull(orderDTO.getName()); | ||
|
||
setupRewriteContextPath(); | ||
|
||
OrderDTO result = HttpHelper.INSTANCE.getFromGateway("/order/order/findById?id=1", OrderDTO.class); | ||
assertEquals("1", result.getId()); | ||
assertEquals("hello world findById", result.getName()); | ||
|
||
// assertThat(cleanPluginData(PluginEnum.CONTEXT_PATH.getName()), is("success")); | ||
} | ||
|
||
@Order(2) | ||
@Test | ||
public void testRewriteCrossPlugin() throws IOException { | ||
OrderDTO orderDTO = HttpHelper.INSTANCE.getFromGateway("/http/order/findById?id=1", OrderDTO.class); | ||
assertEquals("1", orderDTO.getId()); | ||
assertEquals("hello world findById", orderDTO.getName()); | ||
|
||
setupRewrite(); | ||
|
||
Map<String, Object> request = new HashMap<>(); | ||
OrderDTO result = HttpHelper.INSTANCE.getFromGateway("/dubbo/findById?id=2", request, OrderDTO.class); | ||
assertEquals("2", result.getId()); | ||
assertEquals("hello world findById", result.getName()); | ||
|
||
assertThat(cleanPluginData(PluginEnum.CONTEXT_PATH.getName()), is("success")); | ||
assertThat(cleanPluginData(PluginEnum.REWRITE.getName()), is("success")); | ||
} | ||
|
||
private void setupRewrite() throws IOException { | ||
String pluginResult = initPlugin(PluginEnum.CONTEXT_PATH.getName(), ""); | ||
assertThat(pluginResult, CoreMatchers.is("success")); | ||
LocalPluginController.RuleLocalData ruleLocalData = new LocalPluginController.RuleLocalData(); | ||
ruleLocalData.setRuleHandler("{\"contextPath\":\"/dubbo\", \"addPrefix\":\"\", \"rewriteContextPath\":\"/http\", \"percentage\":100}"); | ||
ConditionData conditionData = new ConditionData(); | ||
conditionData.setParamType(ParamTypeEnum.URI.getName()); | ||
conditionData.setOperator(OperatorEnum.EQ.getAlias()); | ||
conditionData.setParamValue("/dubbo/findById"); | ||
ruleLocalData.setConditionDataList(Collections.singletonList(conditionData)); | ||
String message = initSelectorAndRules(PluginEnum.CONTEXT_PATH.getName(), "", 0, | ||
buildSelectorConditionList("/dubbo/findById"), Collections.singletonList(ruleLocalData)); | ||
assertThat(message, is("success")); | ||
|
||
pluginResult = initPlugin(PluginEnum.REWRITE.getName(), ""); | ||
assertThat(pluginResult, is("success")); | ||
String selectorAndRulesResult = initSelectorAndRules(PluginEnum.REWRITE.getName(), "", 0, | ||
buildSelectorConditionList("/http/findById"), buildRewriteRuleLocalDataList()); | ||
assertThat(selectorAndRulesResult, is("success")); | ||
} | ||
|
||
private static List<LocalPluginController.RuleLocalData> buildRewriteRuleLocalDataList() { | ||
final LocalPluginController.RuleLocalData ruleLocalData = new LocalPluginController.RuleLocalData(); | ||
|
||
ConditionData conditionData = new ConditionData(); | ||
conditionData.setParamType(ParamTypeEnum.URI.getName()); | ||
conditionData.setOperator(OperatorEnum.EQ.getAlias()); | ||
conditionData.setParamName("/"); | ||
conditionData.setParamValue("/http/findById"); | ||
ruleLocalData.setConditionDataList(Collections.singletonList(conditionData)); | ||
ruleLocalData.setRuleName("rewriteMetaData"); | ||
|
||
RewriteHandle rewriteHandle = new RewriteHandle(); | ||
rewriteHandle.setRegex("/http/findById"); | ||
rewriteHandle.setReplace("/order/findById"); | ||
rewriteHandle.setRewriteMetaData(true); | ||
rewriteHandle.setPercentage(100); | ||
|
||
ruleLocalData.setRuleHandler(JsonUtils.toJson(rewriteHandle)); | ||
return Collections.singletonList(ruleLocalData); | ||
} | ||
|
||
private void setupRewriteContextPath() throws IOException { | ||
String pluginResult = initPlugin(PluginEnum.CONTEXT_PATH.getName(), ""); | ||
assertThat(pluginResult, CoreMatchers.is("success")); | ||
LocalPluginController.RuleLocalData ruleLocalData = new LocalPluginController.RuleLocalData(); | ||
ruleLocalData.setRuleHandler("{\"contextPath\":\"/order\", \"addPrefix\":\"\", \"rewriteContextPath\":\"/http\", \"percentage\":100}"); | ||
ConditionData conditionData = new ConditionData(); | ||
conditionData.setParamType(ParamTypeEnum.URI.getName()); | ||
conditionData.setOperator(OperatorEnum.MATCH.getAlias()); | ||
conditionData.setParamValue("/order/order/findById"); | ||
ruleLocalData.setConditionDataList(Collections.singletonList(conditionData)); | ||
String message = initSelectorAndRules(PluginEnum.CONTEXT_PATH.getName(), "", | ||
buildSelectorConditionList("/order/order/findById"), Collections.singletonList(ruleLocalData)); | ||
assertThat(message, is("success")); | ||
} | ||
|
||
private List<ConditionData> buildSelectorConditionList(final String paramValue) { | ||
ConditionData conditionData = new ConditionData(); | ||
conditionData.setParamType(ParamTypeEnum.URI.getName()); | ||
conditionData.setOperator(OperatorEnum.EQ.getAlias()); | ||
conditionData.setParamValue(paramValue); | ||
return Collections.singletonList(conditionData); | ||
} | ||
} |