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/19 06:43:41 UTC
[incubator-servicecomb-java-chassis] 02/02: [SCB-215] add IT for
ApiParam
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 c019638318ba2556e53e55c26d51b4bb607d9600
Author: wujimin <wu...@huawei.com>
AuthorDate: Mon Sep 17 22:03:03 2018 +0800
[SCB-215] add IT for ApiParam
---
.../apache/servicecomb/it/schema/CommonModel.java | 29 +++++
.../org/apache/servicecomb/it/ConsumerMain.java | 2 +
.../servicecomb/it/schema/ApiParamJaxrsSchema.java | 62 +++++++++++
.../servicecomb/it/schema/ApiParamPojoSchema.java | 34 ++++++
.../it/schema/ApiParamSpringmvcSchema.java | 69 ++++++++++++
.../servicecomb/it/testcase/TestApiParam.java | 118 +++++++++++++++++++++
6 files changed, 314 insertions(+)
diff --git a/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/CommonModel.java b/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/CommonModel.java
new file mode 100644
index 0000000..1dcebb0
--- /dev/null
+++ b/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/CommonModel.java
@@ -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.
+ */
+package org.apache.servicecomb.it.schema;
+
+public class CommonModel {
+ private int iValue;
+
+ public int getiValue() {
+ return iValue;
+ }
+
+ public void setiValue(int iValue) {
+ this.iValue = iValue;
+ }
+}
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 22113d4..23ede5f 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
@@ -21,6 +21,7 @@ import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.it.deploy.Deploys;
import org.apache.servicecomb.it.junit.ITJUnitUtils;
import org.apache.servicecomb.it.testcase.TestAnnotatedAttribute;
+import org.apache.servicecomb.it.testcase.TestApiParam;
import org.apache.servicecomb.it.testcase.TestChangeTransport;
import org.apache.servicecomb.it.testcase.TestDataTypePrimitive;
import org.apache.servicecomb.it.testcase.TestDefaultJsonValueJaxrsSchema;
@@ -66,6 +67,7 @@ public class ConsumerMain {
// deploys.getZuul().ensureReady(zuul);
ITJUnitUtils.run(TestIgnoreMethod.class);
+ ITJUnitUtils.run(TestApiParam.class);
// 1.base test case
// include all extension point abnormal scenes test case
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/ApiParamJaxrsSchema.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/ApiParamJaxrsSchema.java
new file mode 100644
index 0000000..f5b8143
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/ApiParamJaxrsSchema.java
@@ -0,0 +1,62 @@
+/*
+ * 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.CookieParam;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+
+import io.swagger.annotations.ApiParam;
+
+@RestSchema(schemaId = "apiParamJaxrs")
+@Path("/apiParamJaxrs")
+public class ApiParamJaxrsSchema {
+ @POST
+ @Path("/body")
+ public void body(@ApiParam(value = "desc of body param") CommonModel model) {
+
+ }
+
+ @POST
+ @Path("/query")
+ public void query(@ApiParam(value = "desc of query param") @QueryParam("input") int input) {
+
+ }
+
+ @POST
+ @Path("/header")
+ public void header(@ApiParam(value = "desc of header param") @HeaderParam("input") int input) {
+
+ }
+
+ @POST
+ @Path("/cookie")
+ public void cookie(@ApiParam(value = "desc of cookie param") @CookieParam("input") int input) {
+
+ }
+
+ @POST
+ @Path("/form")
+ public void form(@ApiParam(value = "desc of form param") @FormParam("input") int input) {
+
+ }
+}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/ApiParamPojoSchema.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/ApiParamPojoSchema.java
new file mode 100644
index 0000000..1673ba8
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/ApiParamPojoSchema.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.servicecomb.provider.pojo.RpcSchema;
+
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.SwaggerDefinition;
+
+@RpcSchema(schemaId = "apiParamPojo")
+@SwaggerDefinition(basePath = "/apiParamPojo")
+public class ApiParamPojoSchema {
+ public void model(@ApiParam(value = "desc of model param") CommonModel model) {
+
+ }
+
+ public void simple(@ApiParam(value = "desc of simple param") int input) {
+
+ }
+}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/ApiParamSpringmvcSchema.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/ApiParamSpringmvcSchema.java
new file mode 100644
index 0000000..b291692
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/ApiParamSpringmvcSchema.java
@@ -0,0 +1,69 @@
+/*
+ * 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 org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.web.bind.annotation.CookieValue;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.Example;
+import io.swagger.annotations.ExampleProperty;
+
+@RestSchema(schemaId = "apiParamSpringmvc")
+@RequestMapping(path = "/apiParamSpringmvc")
+public class ApiParamSpringmvcSchema {
+ @PostMapping(path = "/body")
+ public void body(@ApiParam(value = "desc of body param",
+ required = true,
+ name = "modelEx",
+ examples = @Example(value = {
+ @ExampleProperty(mediaType = "k1", value = "v1"),
+ @ExampleProperty(mediaType = "k2", value = "v2")})) @RequestBody CommonModel model) {
+
+ }
+
+ @PostMapping(path = "/query")
+ public void query(@ApiParam(value = "desc of query param",
+ required = true,
+ readOnly = true,
+ allowEmptyValue = true,
+ name = "inputEx",
+ example = "example",
+ collectionFormat = "fmt") int input) {
+
+ }
+
+ @PostMapping(path = "/header")
+ public void header(@ApiParam(value = "desc of header param") @RequestHeader("input") int input) {
+
+ }
+
+ @PostMapping(path = "/cookie")
+ public void cookie(@ApiParam(value = "desc of cookie param") @CookieValue("input") int input) {
+
+ }
+
+ @PostMapping(path = "/form")
+ public void form(@ApiParam(value = "desc of form param") @RequestAttribute("input") int input) {
+
+ }
+}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestApiParam.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestApiParam.java
new file mode 100644
index 0000000..3178742
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestApiParam.java
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+import org.apache.servicecomb.core.SCBEngine;
+import org.apache.servicecomb.core.definition.MicroserviceMeta;
+import org.apache.servicecomb.core.definition.OperationMeta;
+import org.apache.servicecomb.core.definition.SchemaMeta;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.parameters.BodyParameter;
+import io.swagger.models.parameters.Parameter;
+import io.swagger.models.parameters.QueryParameter;
+
+public class TestApiParam {
+ MicroserviceMeta microserviceMeta = SCBEngine.getInstance().getProducerMicroserviceMeta();
+
+ Parameter parameter;
+
+ protected void check(String schemaId, String opName) {
+ check(schemaId, opName, opName);
+ }
+
+ protected void check(String schemaId, String opName, String paramType) {
+ SchemaMeta schemaMeta = microserviceMeta.findSchemaMeta(schemaId);
+ OperationMeta operationMeta = schemaMeta.findOperation(opName);
+ parameter = operationMeta.getSwaggerOperation().getParameters().get(0);
+ Assert.assertEquals("desc of " + opName + " param", parameter.getDescription());
+ Assert.assertEquals(paramType, parameter.getIn());
+ }
+
+ @Test
+ public void pojoModel() {
+ check("apiParamPojo", "model", "body");
+ }
+
+ @Test
+ public void pojoSimple() {
+ check("apiParamPojo", "simple", "body");
+ }
+
+ @Test
+ public void jaxrsBody() {
+ check("apiParamJaxrs", "body");
+ }
+
+ @Test
+ public void jaxrsQuery() {
+ check("apiParamJaxrs", "query");
+ }
+
+ @Test
+ public void jaxrsHeader() {
+ check("apiParamJaxrs", "header");
+ }
+
+ @Test
+ public void jaxrsCookie() {
+ check("apiParamJaxrs", "cookie");
+ }
+
+ @Test
+ public void jaxrsForm() {
+ check("apiParamJaxrs", "form", "formData");
+ }
+
+ @Test
+ public void springmvcBody() {
+ check("apiParamSpringmvc", "body");
+
+ Assert.assertTrue(parameter.getRequired());
+ Assert.assertEquals("modelEx", parameter.getName());
+ Assert.assertEquals("v1", ((BodyParameter) parameter).getExamples().get("k1"));
+ Assert.assertEquals("v2", ((BodyParameter) parameter).getExamples().get("k2"));
+ }
+
+ @Test
+ public void springmvcQuery() {
+ check("apiParamSpringmvc", "query");
+
+ Assert.assertTrue(parameter.getRequired());
+ Assert.assertTrue(parameter.isReadOnly());
+ Assert.assertTrue(parameter.getAllowEmptyValue());
+ Assert.assertEquals("inputEx", parameter.getName());
+ Assert.assertEquals("example", ((QueryParameter) parameter).getExample());
+ Assert.assertEquals("fmt", ((QueryParameter) parameter).getCollectionFormat());
+ }
+
+ @Test
+ public void springmvcHeader() {
+ check("apiParamSpringmvc", "header");
+ }
+
+ @Test
+ public void springmvcCookie() {
+ check("apiParamSpringmvc", "cookie");
+ }
+
+ @Test
+ public void springmvcForm() {
+ check("apiParamSpringmvc", "form", "formData");
+ }
+}