diff --git a/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/objectParams/QueryObjectModel.java b/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/objectParams/QueryObjectModel.java new file mode 100644 index 00000000000..094014d549f --- /dev/null +++ b/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/objectParams/QueryObjectModel.java @@ -0,0 +1,57 @@ +/* + * 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.objectParams; + +public class QueryObjectModel { + private int index; + + private String name; + + public QueryObjectModel() { + } + + public QueryObjectModel(int index, String name) { + this.index = index; + this.name = name; + } + + public int getIndex() { + return index; + } + + public QueryObjectModel setIndex(int index) { + this.index = index; + return this; + } + + public String getName() { + return name; + } + + public QueryObjectModel setName(String name) { + this.name = name; + return this; + } + + @Override + public String toString() { + return "QueryObject{" + + "index=" + index + + ", name='" + name + '\'' + + '}'; + } +} 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 63772a2868a..924c0e8338f 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 @@ -49,6 +49,7 @@ import org.apache.servicecomb.it.testcase.TestTraceEdge; import org.apache.servicecomb.it.testcase.TestUpload; import org.apache.servicecomb.it.testcase.base.TestGeneric; +import org.apache.servicecomb.it.testcase.objectParams.TestSpringMVCObjectParam; import org.apache.servicecomb.it.testcase.thirdparty.Test3rdPartyInvocation; public class ConsumerMain { @@ -103,6 +104,7 @@ protected static void run() throws Throwable { } private static void runShareTestCases() throws Throwable { + ITJUnitUtils.runWithHighwayAndRest(TestSpringMVCObjectParam.class); ITJUnitUtils.runWithHighwayAndRest(TestChangeTransport.class); ITJUnitUtils.runWithHighwayAndRest(TestDataTypePrimitive.class); ITJUnitUtils.runWithHighwayAndRest(TestAnnotatedAttribute.class); diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/objectParams/TestSpringMVCObjectParam.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/objectParams/TestSpringMVCObjectParam.java new file mode 100644 index 00000000000..d4404b50a9d --- /dev/null +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/objectParams/TestSpringMVCObjectParam.java @@ -0,0 +1,172 @@ +/* + * 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.objectParams; + +import static org.junit.Assert.assertEquals; + +import org.apache.servicecomb.it.Consumers; +import org.apache.servicecomb.it.schema.objectParams.QueryObjectModel; +import org.junit.Test; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; + +public class TestSpringMVCObjectParam { + interface SpringMVCObjectIntf { + String testQueryObjectParam(int index, String name); + + String testQueryObjectWithHeader(String prefix, int index, String name); + + String testQueryObjectWithHeaderName(String prefix, int index, String name); + + String testQueryObjectWithHeaderValue(String prefix, int index, String name); + + String testQueryObjectWithHeaderValueAndName(String prefix, String suffix, int index, String name); + + String testQueryObjectWithParam(String prefix, int index, String name); + + String testQueryObjectWithParamName(String prefix, int index, String name); + + String testQueryObjectWithParamValue(String prefix, int index, String name); + } + + private String prefix = "prefix-"; + + private String suffix = "-suffix"; + + private QueryObjectModel queryModel = new QueryObjectModel(23, "demo"); + + private String queryParam = "index=23&name=demo"; + + private static Consumers consumersSpringmvc = new Consumers<>("springMVCObjectParamSchema", + SpringMVCObjectIntf.class); + + @Test + public void testQueryObjectParam_rt() { + assertEquals(queryModel.toString(), consumersSpringmvc.getSCBRestTemplate() + .getForObject("/testQueryObjectParam?" + queryParam, String.class)); + } + + @Test + public void testQueryObjectParam_pojo() { + assertEquals(queryModel.toString(), consumersSpringmvc.getIntf().testQueryObjectParam(23, "demo")); + } + + @Test + public void testQueryObjectWithHeader_rt() { + HttpHeaders headers = new HttpHeaders(); + headers.add("prefix", prefix); + assertEquals(prefix + queryModel.toString(), + queryObjectHeader(consumersSpringmvc, headers, "/testQueryObjectWithHeader?" + queryParam)); + } + + @Test + public void testQueryObjectWithHeader_pojo() { + assertEquals(prefix + queryModel.toString(), + consumersSpringmvc.getIntf().testQueryObjectWithHeader(prefix, 23, "demo")); + } + + @Test + public void testQueryObjectWithHeaderName_rt() { + HttpHeaders headers = new HttpHeaders(); + headers.add("prefix", prefix); + assertEquals(prefix + queryModel.toString(), + queryObjectHeader(consumersSpringmvc, headers, "/testQueryObjectWithHeaderName?" + queryParam)); + } + + @Test + public void testQueryObjectWithHeaderName_pojo() { + assertEquals(prefix + queryModel.toString(), + consumersSpringmvc.getIntf().testQueryObjectWithHeaderName(prefix, 23, "demo")); + } + + @Test + public void testQueryObjectWithHeaderValue_rt() { + HttpHeaders headers = new HttpHeaders(); + headers.add("prefix", prefix); + assertEquals(prefix + queryModel.toString(), + queryObjectHeader(consumersSpringmvc, headers, "/testQueryObjectWithHeaderValue?" + queryParam)); + } + + @Test + public void testQueryObjectWithHeaderValue_pojo() { + assertEquals(prefix + queryModel.toString(), + consumersSpringmvc.getIntf().testQueryObjectWithHeaderValue(prefix, 23, "demo")); + } + + @Test + public void testQueryObjectWithHeaderValueAndName_rt() { + HttpHeaders headers = new HttpHeaders(); + headers.add("prefix", prefix); + headers.add("suffix", suffix); + assertEquals(prefix + queryModel.toString() + suffix, + queryObjectHeader(consumersSpringmvc, headers, "/testQueryObjectWithHeaderValueAndName?" + queryParam)); + } + + @Test + public void testQueryObjectWithHeaderValueAndName_pojo() { + assertEquals(prefix + queryModel.toString() + suffix, + consumersSpringmvc.getIntf().testQueryObjectWithHeaderValueAndName(prefix, suffix, 23, "demo")); + } + + @Test + public void testQueryObjectWithParam_rt() { + assertEquals(prefix + queryModel.toString(), consumersSpringmvc.getSCBRestTemplate() + .getForObject("/testQueryObjectWithParam?prefix=" + prefix + "&" + queryParam, String.class)); + } + + @Test + public void testQueryObjectWithParam_pojo() { + assertEquals(prefix + queryModel.toString(), + consumersSpringmvc.getIntf().testQueryObjectWithParam(prefix, 23, "demo")); + } + + @Test + public void testQueryObjectWithParamName_rt() { + assertEquals(prefix + queryModel.toString(), consumersSpringmvc.getSCBRestTemplate() + .getForObject("/testQueryObjectWithParamName?prefix=" + prefix + "&" + queryParam, String.class)); + } + + @Test + public void testQueryObjectWithParamName_pojo() { + assertEquals(prefix + queryModel.toString(), + consumersSpringmvc.getIntf().testQueryObjectWithParamName(prefix, 23, "demo")); + } + + @Test + public void testQueryObjectWithParamValue_rt() { + assertEquals(prefix + queryModel.toString(), consumersSpringmvc.getSCBRestTemplate() + .getForObject("/testQueryObjectWithParamValue?prefix=" + prefix + "&" + queryParam, String.class)); + } + + @Test + public void testQueryObjectWithParamValue_pojo() { + assertEquals(prefix + queryModel.toString(), + consumersSpringmvc.getIntf().testQueryObjectWithParamValue(prefix, 23, "demo")); + } + + protected String queryObjectHeader(Consumers consumers, HttpHeaders headers, String url) { + HttpEntity entity = new HttpEntity<>(headers); + ResponseEntity response = consumers.getSCBRestTemplate() + .exchange(url, + HttpMethod.GET, + entity, + String.class); + return response.getBody(); + } +} diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/EmptyScheam.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/EmptySchema.java similarity index 90% rename from integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/EmptyScheam.java rename to integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/EmptySchema.java index 583c361ea50..064a41994ca 100644 --- a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/EmptyScheam.java +++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/EmptySchema.java @@ -20,7 +20,7 @@ import org.apache.servicecomb.provider.rest.common.RestSchema; import org.springframework.web.bind.annotation.RequestMapping; -@RestSchema(schemaId = "EmptyScheam") -@RequestMapping(path = "/v1/EmptyScheam") -public class EmptyScheam { +@RestSchema(schemaId = "EmptySchema") +@RequestMapping(path = "/v1/EmptySchema") +public class EmptySchema { } diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/objectParams/SpringMVCObjectParamSchema.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/objectParams/SpringMVCObjectParamSchema.java new file mode 100644 index 00000000000..87e745d2087 --- /dev/null +++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/objectParams/SpringMVCObjectParamSchema.java @@ -0,0 +1,79 @@ +/* + * 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.objectParams; + +import org.apache.servicecomb.provider.rest.common.RestSchema; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@RestSchema(schemaId = "springMVCObjectParamSchema") +@RequestMapping(path = "/v1/springMVCObjectParamSchema") +public class SpringMVCObjectParamSchema { + + /** + * SCB-708 SpringMVC only + */ + @GetMapping("testQueryObjectParam") + public String testQueryObjectParam(QueryObjectModel QueryObjectModel) { + return QueryObjectModel.toString(); + } + + @GetMapping("testQueryObjectWithHeader") + public String testQueryObjectWithHeader(@RequestHeader("prefix") String prefix, QueryObjectModel QueryObjectModel) { + return prefix + QueryObjectModel.toString(); + } + + @GetMapping("testQueryObjectWithHeaderName") + public String testQueryObjectWithHeaderName(@RequestHeader(name = "prefix") String prefix, + QueryObjectModel QueryObjectModel) { + return prefix + QueryObjectModel.toString(); + } + + /** + * SCB-1793 support @RequestHeader(value ="xxx") + */ + @GetMapping("testQueryObjectWithHeaderValue") + public String testQueryObjectWithHeaderValue(@RequestHeader(value = "prefix") String prefix, + QueryObjectModel QueryObjectModel) { + return prefix + QueryObjectModel.toString(); + } + + @GetMapping("testQueryObjectWithHeaderValueAndName") + public String testQueryObjectWithHeaderValueAndName(@RequestHeader(name = "prefix") String prefix, + @RequestHeader(value = "suffix") String suffix, QueryObjectModel QueryObjectModel) { + return prefix + QueryObjectModel.toString() + suffix; + } + + @GetMapping("testQueryObjectWithParam") + public String testQueryObjectWithParam(@RequestParam("prefix") String prefix, QueryObjectModel QueryObjectModel) { + return prefix + QueryObjectModel.toString(); + } + + @GetMapping("testQueryObjectWithParamName") + public String testQueryObjectWithParamName(@RequestParam(name = "prefix") String prefix, + QueryObjectModel QueryObjectModel) { + return prefix + QueryObjectModel.toString(); + } + + @GetMapping("testQueryObjectWithParamValue") + public String testQueryObjectWithParamValue(@RequestParam(value = "prefix") String prefix, + QueryObjectModel QueryObjectModel) { + return prefix + QueryObjectModel.toString(); + } +}