You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/09/06 06:07:10 UTC
[incubator-servicecomb-java-chassis] 02/02: [SCB-886] add IT to
test path param encoding
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit b6095d783b413b5319a010fe6947a45555802226
Author: yaohaishi <ya...@huawei.com>
AuthorDate: Tue Sep 4 15:01:23 2018 +0800
[SCB-886] add IT to test path param encoding
---
.../org/apache/servicecomb/it/ConsumerMain.java | 3 +-
.../it/testcase/base/TestParamCodec.java | 53 ++++++++++++++++++++++
.../servicecomb/it/schema/ParamCodecSchema.java | 39 ++++++++++++++++
3 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
index 1086801..32f1764 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
@@ -29,9 +29,9 @@ import org.apache.servicecomb.it.testcase.TestTraceEdge;
import org.apache.servicecomb.it.testcase.base.TestDataTypeJaxrs;
import org.apache.servicecomb.it.testcase.base.TestDataTypePojo;
import org.apache.servicecomb.it.testcase.base.TestDataTypeSpringmvc;
+import org.apache.servicecomb.it.testcase.base.TestParamCodec;
import org.apache.servicecomb.it.testcase.support.ProducerDevMode;
-
public class ConsumerMain {
private static ResultPrinter resultPrinter = new ResultPrinter();
@@ -109,6 +109,7 @@ public class ConsumerMain {
testDataType();
ITJUnitUtils.runWithHighwayAndRest(TestTrace.class);
ITJUnitUtils.run(TestTraceEdge.class);
+ ITJUnitUtils.runWithHighwayAndRest(TestParamCodec.class);
ITJUnitUtils.getParents().pop();
deploys.getBaseProducer().stop();
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestParamCodec.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestParamCodec.java
new file mode 100644
index 0000000..d6ec50c
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestParamCodec.java
@@ -0,0 +1,53 @@
+/*
+ * 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.servicecomb.it.testcase.base;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.servicecomb.it.Consumers;
+import org.apache.servicecomb.it.junit.ITJUnitUtils;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestParamCodec {
+ interface ParamCodecSchemaIntf {
+ String spaceCharCodec(String pathVal, String q);
+ }
+
+ static Consumers<ParamCodecSchemaIntf> consumers = new Consumers<>("paramCodec", ParamCodecSchemaIntf.class);
+
+ @BeforeClass
+ public static void classSetup() {
+ consumers.init(ITJUnitUtils.getTransport());
+ }
+
+ @Test
+ public void spaceCharEncode_intf() {
+ String paramString = "a%2B+%20b%% %20c";
+ String result = consumers.getIntf().spaceCharCodec(paramString, paramString);
+ assertEquals(paramString + " +%20%% " + paramString + " true", result);
+ }
+
+ @Test
+ public void spaceCharEncode_rt() {
+ String paramString = "a%2B+%20b%% %20c";
+ String result = consumers.getSCBRestTemplate()
+ .getForObject("/spaceCharCodec/" + paramString + "?q=" + paramString, String.class);
+ assertEquals(paramString + " +%20%% " + paramString + " true", result);
+ }
+}
diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/ParamCodecSchema.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/ParamCodecSchema.java
new file mode 100644
index 0000000..2620ecb
--- /dev/null
+++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/ParamCodecSchema.java
@@ -0,0 +1,39 @@
+/*
+ * 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.servicecomb.it.schema;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+
+@RestSchema(schemaId = "paramCodec")
+@Path("/base/v1/paramCodec")
+public class ParamCodecSchema {
+ /**
+ * Test path param and query param encode&decode
+ */
+ @Path("spaceCharCodec/{pathVal}")
+ @GET
+ public String spaceCharCodec(@PathParam("pathVal") String pathVal, @QueryParam("q") String q) {
+ String expectedParamString = "a%2B+%20b%% %20c";
+ return pathVal + " +%20%% " + q + " " + (expectedParamString.equals(pathVal) && expectedParamString.equals(q));
+ }
+}