diff --git a/common-rest/src/main/java/io/servicecomb/common/rest/definition/RestOperationMeta.java b/common-rest/src/main/java/io/servicecomb/common/rest/definition/RestOperationMeta.java index 643f3de2ea6..f2b031c2c64 100644 --- a/common-rest/src/main/java/io/servicecomb/common/rest/definition/RestOperationMeta.java +++ b/common-rest/src/main/java/io/servicecomb/common/rest/definition/RestOperationMeta.java @@ -16,6 +16,14 @@ package io.servicecomb.common.rest.definition; +import io.servicecomb.common.rest.codec.produce.ProduceProcessor; +import io.servicecomb.common.rest.codec.produce.ProduceProcessorManager; +import io.servicecomb.common.rest.definition.path.PathRegExp; +import io.servicecomb.common.rest.definition.path.URLPathBuilder; +import io.servicecomb.core.definition.OperationMeta; +import io.swagger.models.Operation; +import io.swagger.models.Swagger; +import io.swagger.models.parameters.Parameter; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.ArrayList; @@ -23,23 +31,11 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import javax.ws.rs.core.MediaType; - -import io.servicecomb.common.rest.codec.produce.ProduceProcessor; -import io.servicecomb.common.rest.codec.produce.ProduceProcessorManager; -import io.servicecomb.common.rest.definition.path.URLPathBuilder; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.servicecomb.common.rest.definition.path.PathRegExp; -import io.servicecomb.core.definition.OperationMeta; - -import io.swagger.models.Operation; -import io.swagger.models.Swagger; -import io.swagger.models.parameters.Parameter; - public class RestOperationMeta { private static final Logger LOGGER = LoggerFactory.getLogger(RestOperationMeta.class); @@ -109,31 +105,15 @@ public void setOperationMeta(OperationMeta operationMeta) { // 输出b/c/形式的url private String concatPath(String basePath, String operationPath) { - basePath = removeHeadTailSlash(basePath); - operationPath = removeHeadTailSlash(operationPath); - - if (StringUtils.isEmpty(operationPath)) { - return basePath + "/"; - } - - return basePath + "/" + operationPath + "/"; + return ("/" + nonNullify(basePath) + "/" + nonNullify(operationPath) + "/") + .replaceAll("/{2,}", "/"); } - protected String removeHeadTailSlash(String path) { - if (path == null) { - path = ""; - } - - if (path.startsWith("/")) { - path = path.substring(1); - } - if (path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } - return path; + private String nonNullify(String path) { + return path == null ? "" : path; } - public String getAbsolutePath() { + public String getAbsolutePath() { return this.absolutePath; } @@ -202,7 +182,7 @@ public List getParamList() { return paramList; } - public void addParam(RestParam param) { + private void addParam(RestParam param) { paramList.add(param); paramMap.put(param.getParamName(), param); } diff --git a/common-rest/src/main/java/io/servicecomb/common/rest/locator/OperationLocator.java b/common-rest/src/main/java/io/servicecomb/common/rest/locator/OperationLocator.java index 8423699c971..14435b4e191 100644 --- a/common-rest/src/main/java/io/servicecomb/common/rest/locator/OperationLocator.java +++ b/common-rest/src/main/java/io/servicecomb/common/rest/locator/OperationLocator.java @@ -16,15 +16,12 @@ package io.servicecomb.common.rest.locator; +import io.servicecomb.common.rest.definition.RestOperationMeta; +import io.servicecomb.swagger.invocation.exception.InvocationException; import java.util.Collection; import java.util.HashMap; import java.util.Map; - import javax.ws.rs.core.Response.Status; - -import io.servicecomb.common.rest.definition.RestOperationMeta; -import io.servicecomb.swagger.invocation.exception.InvocationException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,17 +101,11 @@ protected RestOperationMeta locateDynamicPathOperation(String path, Collection a/b/c/ - public static String getStandardPath(String path) { - if (path.startsWith(SLASH)) { - path = path.substring(1); - } + // Path: /a/b/c -> /a/b/c/ + static String getStandardPath(String path) { if (path.length() > 0 && !path.endsWith(SLASH)) { path += SLASH; } diff --git a/common-rest/src/main/java/io/servicecomb/common/rest/locator/ServicePathManager.java b/common-rest/src/main/java/io/servicecomb/common/rest/locator/ServicePathManager.java index d13eb51d7b0..50ff206fb76 100644 --- a/common-rest/src/main/java/io/servicecomb/common/rest/locator/ServicePathManager.java +++ b/common-rest/src/main/java/io/servicecomb/common/rest/locator/ServicePathManager.java @@ -16,6 +16,9 @@ package io.servicecomb.common.rest.locator; +import io.servicecomb.common.rest.definition.RestOperationComparator; +import io.servicecomb.common.rest.definition.RestOperationMeta; +import io.servicecomb.core.definition.MicroserviceMeta; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -24,14 +27,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; - -import io.servicecomb.common.rest.definition.RestOperationComparator; -import io.servicecomb.common.rest.definition.RestOperationMeta; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.servicecomb.core.definition.MicroserviceMeta; - /** * 对静态路径和动态路径的operation进行预先处理,加速operation的查询定位 */ diff --git a/common-rest/src/test/java/io/servicecomb/common/rest/TestRestEngineSchemaListener.java b/common-rest/src/test/java/io/servicecomb/common/rest/TestRestEngineSchemaListener.java index 434dc018f54..244b80f648d 100644 --- a/common-rest/src/test/java/io/servicecomb/common/rest/TestRestEngineSchemaListener.java +++ b/common-rest/src/test/java/io/servicecomb/common/rest/TestRestEngineSchemaListener.java @@ -16,14 +16,6 @@ package io.servicecomb.common.rest; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mockito; -import org.springframework.context.ApplicationContext; - import io.servicecomb.common.rest.locator.ServicePathManager; import io.servicecomb.core.definition.MicroserviceMeta; import io.servicecomb.core.definition.SchemaMeta; @@ -32,11 +24,17 @@ import io.servicecomb.swagger.generator.core.SwaggerGeneratorContext; import io.servicecomb.swagger.generator.pojo.PojoSwaggerGeneratorContext; import io.swagger.models.Swagger; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.context.ApplicationContext; public class TestRestEngineSchemaListener { - SwaggerGeneratorContext context = new PojoSwaggerGeneratorContext(); + private final SwaggerGeneratorContext context = new PojoSwaggerGeneratorContext(); - static class Impl { + private static class Impl { public int add(int x, int y) { return 0; } @@ -63,6 +61,6 @@ public void test() { ServicePathManager spm = ServicePathManager.getServicePathManager(mm); Assert.assertEquals(mm, spm.getMicroserviceMeta()); - Assert.assertNotNull(spm.getStaticPathOperationMap().get("Impl/add/")); + Assert.assertNotNull(spm.getStaticPathOperationMap().get("/Impl/add/")); } } diff --git a/common-rest/src/test/java/io/servicecomb/common/rest/definition/TestRestOperationMeta.java b/common-rest/src/test/java/io/servicecomb/common/rest/definition/TestRestOperationMeta.java index 113b73519be..0f035a7181e 100644 --- a/common-rest/src/test/java/io/servicecomb/common/rest/definition/TestRestOperationMeta.java +++ b/common-rest/src/test/java/io/servicecomb/common/rest/definition/TestRestOperationMeta.java @@ -16,34 +16,37 @@ package io.servicecomb.common.rest.definition; -import javax.ws.rs.core.MediaType; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import io.servicecomb.common.rest.codec.produce.ProduceProcessorManager; -import org.junit.After; +import io.servicecomb.core.definition.OperationMeta; +import io.servicecomb.core.definition.SchemaMeta; +import io.swagger.models.Operation; +import io.swagger.models.Swagger; +import javax.ws.rs.core.MediaType; import org.junit.Assert; import org.junit.Before; import org.junit.Test; - -import io.servicecomb.core.definition.OperationMeta; +import org.mockito.Mockito; public class TestRestOperationMeta { - private RestOperationMeta operationMeta; + private final Swagger swagger = Mockito.mock(Swagger.class); + private final SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class); + private final Operation operation = Mockito.mock(Operation.class); + private final OperationMeta meta = mock(OperationMeta.class); + private final RestOperationMeta operationMeta = new RestOperationMeta(); @Before - public void beforeTest() { - operationMeta = new RestOperationMeta() { - @Override - public void init(OperationMeta operationMeta) { - } - }; - } - - @After - public void afterTest() { - - operationMeta = null; + public void setUp() throws Exception { + when(meta.getSchemaMeta()).thenReturn(schemaMeta); + when(meta.getSwaggerOperation()).thenReturn(operation); + when(meta.getMethod()).thenReturn(SomeRestController.class.getMethod("sayHi")); + when(schemaMeta.getSwagger()).thenReturn(swagger); } @Test @@ -78,4 +81,60 @@ public void testEnsureFindProduceProcessor() { Assert.assertEquals(null, operationMeta.findProduceProcessor("test")); } + + @Test + public void generatesAbsolutePathWithRootBasePath() { + when(swagger.getBasePath()).thenReturn("/"); + when(meta.getOperationPath()).thenReturn("/sayHi/"); + + operationMeta.init(meta); + + assertThat(operationMeta.getAbsolutePath(), is("/sayHi/")); + } + + @Test + public void generatesAbsolutePathWithNonRootBasePath() { + when(swagger.getBasePath()).thenReturn("/rest"); + when(meta.getOperationPath()).thenReturn("/sayHi"); + + operationMeta.init(meta); + + assertThat(operationMeta.getAbsolutePath(), is("/rest/sayHi/")); + } + + @Test + public void generatesAbsolutePathWithNullPath() { + when(swagger.getBasePath()).thenReturn(null); + when(meta.getOperationPath()).thenReturn(null); + + operationMeta.init(meta); + + assertThat(operationMeta.getAbsolutePath(), is("/")); + } + + @Test + public void generatesAbsolutePathWithEmptyPath() { + when(swagger.getBasePath()).thenReturn(""); + when(meta.getOperationPath()).thenReturn(""); + + operationMeta.init(meta); + + assertThat(operationMeta.getAbsolutePath(), is("/")); + } + + @Test + public void consecutiveSlashesAreRemoved() { + when(swagger.getBasePath()).thenReturn("//rest//"); + when(meta.getOperationPath()).thenReturn("//sayHi//"); + + operationMeta.init(meta); + + assertThat(operationMeta.getAbsolutePath(), is("/rest/sayHi/")); + } + + private static class SomeRestController { + public String sayHi() { + return "Hi"; + } + } } diff --git a/common-rest/src/test/java/io/servicecomb/common/rest/definition/TestRestSchemaMeta.java b/common-rest/src/test/java/io/servicecomb/common/rest/definition/TestRestSchemaMeta.java deleted file mode 100644 index 3805f53f263..00000000000 --- a/common-rest/src/test/java/io/servicecomb/common/rest/definition/TestRestSchemaMeta.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd - * - * Licensed 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 io.servicecomb.common.rest.definition; - -import org.junit.Test; - -public class TestRestSchemaMeta { - - @Test - public void testRestSchemaMeta() throws Exception { - // new ConfigurationSpringInitializer(); - // - // RestSchemaMeta oRestSchema = new RestSchemaMeta("test"); - // Assert.assertEquals("test", oRestSchema.getName()); - // oRestSchema = new RestSchemaMeta("test2"); - // RestSchemaMeta oSecondRestSchema = new RestSchemaMeta(oRestSchema); - // Assert.assertEquals("test2", oSecondRestSchema.getName()); - // oSecondRestSchema.init("testOperationKey"); - // RestOperationMeta oMeta = new RestOperationMeta(); - // oMeta.setServiceName("test2"); - // oMeta.setMethod(null); - // Assert.assertEquals(null, oMeta.getOperationMeta()); - // Assert.assertEquals(null, oMeta.getAbsolutePath()); - // Assert.assertEquals(null, oMeta.getMethod()); - // oMeta.setHttpMethod("POST"); - // Assert.assertEquals("POST", oMeta.getHttpMethod()); - // oMeta.setDefaultHttpMethod(); - // Assert.assertEquals("GET", oMeta.getHttpMethod()); - // Assert.assertEquals("test2", oMeta.getServiceName()); - // DynamicObject oObject = new DynamicObject() { - // }; - // oObject.putAttr("testKey", "testvalue"); - // oObject.removeAttr("testKey"); - // RestParam oParam = new RestParam(); - // - // Type oType = String.class.getGenericSuperclass(); - // - // oParam.init(oType); - // oMeta.addParam(new RestParam()); - // Assert.assertEquals(1, oMeta.getParamList().size()); - // oMeta.setPath("/root"); - // oMeta.setProvider("providerName"); - // oMeta.setName("Name"); - // Assert.assertEquals("root/", oMeta.getPath()); - // Assert.assertEquals("providerName:root/:GET:Name", oMeta.getMergeKey()); - // Assert.assertEquals(null, oMeta.getAbsolutePathRegExp()); - // Assert.assertNotEquals(null, oParam.getValueAsStrings(new String[] {"test"})); - // String[] oSeArrayStringObject = new String[] {"test"}; - // Assert.assertNotEquals(null, oParam.getValueAsStrings(oSeArrayStringObject)); - // Assert.assertArrayEquals(null, oParam.getValueAsStrings(new String[][] {null})); - } -} diff --git a/common-rest/src/test/java/io/servicecomb/common/rest/loader/swagger/TestSwaggerRestSchemaLoader.java b/common-rest/src/test/java/io/servicecomb/common/rest/loader/swagger/TestSwaggerRestSchemaLoader.java deleted file mode 100644 index ba56bc84df6..00000000000 --- a/common-rest/src/test/java/io/servicecomb/common/rest/loader/swagger/TestSwaggerRestSchemaLoader.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd - * - * Licensed 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 io.servicecomb.common.rest.loader.swagger; - -public class TestSwaggerRestSchemaLoader { - - // private SwaggerRestSchemaLoader swaggerRestSchemaLoader = null; - // private RestProducerConfig restSchemaMeta = null; - // private String restSchemaMetaName = "RestSchemaMetaName"; - // @SuppressWarnings("unused") - // private RegisterManager schemaMgr = null; - // private RestOperationMeta restOperationMeta = new RestOperationMeta(); - // private Swagger swagger = new Swagger(); - // - // @Before - // public void setUp() throws Exception { - // swaggerRestSchemaLoader = new SwaggerRestSchemaLoader(); - // restSchemaMeta = new RestProducerConfig(restSchemaMetaName); - // schemaMgr = new RegisterManager<>("test"); - // } - // - // @After - // public void tearDown() throws Exception { - // swaggerRestSchemaLoader = null; - // restSchemaMeta = null; - // schemaMgr = null; - // } - // - // @Test - // public void testCreateRestSchemaMeta() { - // boolean status = true; - // Swagger swagger = Mockito.mock(Swagger.class); - // MicroserviceMeta microserviceMeta = Mockito.mock(MicroserviceMeta.class); - // String schemaId = "schemaId"; - // new MockUp() { - // @Mock - // public Class getJavaInterface(String schemaId, Swagger swagger) { - // try { - // return Class.forName("java.lang.String"); - // } catch (ClassNotFoundException e) { - // /* Do not worry */ - // } - // return null; - // } - // }; - // - // new MockUp() { - // @Mock - // private void initOperations() throws Exception { - // /* do not worry */ - // } - // }; - // try { - // RestProducerConfig restSchemaMeta = swaggerRestSchemaLoader - // .createRestSchemaMeta(new SchemaMeta(swagger, microserviceMeta, schemaId)); - // Assert.assertNotNull(restSchemaMeta); - // } catch (Exception e) { - // status = false; - // } - // Assert.assertTrue(status); - // } - // - // @Test - // public void testLoadServiceDefine() { - // boolean status = true; - // - // new MockUp() { - // @Mock - // public Map getPaths() { - // Map map = new HashMap(); - // map.put("firstPath", new Path()); - // return map; - // } - // }; - // - // new MockUp() { - // @Mock - // public Map getOperationMap() { - // Map result = new HashMap(); - // result.put(HttpMethod.GET, new Operation()); - // return result; - // } - // }; - // - // new MockUp() { - // @Mock - // public String getName() { - // return "Name"; - // } - // }; - // - // Class cls = null; - // try { - // cls = Class.forName("java.lang.String"); - // } catch (ClassNotFoundException e) { - // status = false; - // } - // Assert.assertNotNull(swagger); - // Assert.assertNotNull(restSchemaMetaName); - // try { - // swaggerRestSchemaLoader.loadServiceDefine(restSchemaMeta, cls, swagger); - // } catch (Exception e) { - // status = false; - // } - // - // Assert.assertTrue(status); - // } - // - // @Test - // public void testScanOperation() { - // boolean status = true; - // Operation operation = new Operation(); - // Class cls = null; - // Assert.assertNotNull(restOperationMeta); - // Assert.assertNotNull(operation); - // Assert.assertNull(cls); - // try { - // swaggerRestSchemaLoader.scanOperation(restOperationMeta, operation, cls); - // } catch (Exception e) { - // status = false; - // } - // Assert.assertTrue(status); - // } - // - // @Test - // public void testScanOperationName() { - // boolean status = true; - // Class cls = null; - // Operation operation = new Operation(); - // operation.setOperationId("indexOf"); - // try { - // cls = Class.forName("java.lang.String"); - // } catch (ClassNotFoundException e) { - // status = false; - // } - // Assert.assertNotNull(operation); - // Assert.assertNotNull(restOperationMeta); - // Assert.assertNotNull(cls); - // try { - // swaggerRestSchemaLoader.scanOperation(restOperationMeta, operation, cls); - // } catch (Exception e) { - // status = false; - // } - // Assert.assertTrue(status); - // } - // - // @Test - // public void testScanOperationWithInvalidName() { - // boolean status = true; - // Class cls = null; - // Operation operation = new Operation(); - // operation.setOperationId("OperationId"); - // try { - // cls = Class.forName("java.lang.String"); - // } catch (ClassNotFoundException e) { - // status = false; - // } - // Assert.assertNotNull(operation); - // Assert.assertNotNull(restOperationMeta); - // try { - // swaggerRestSchemaLoader.scanOperation(restOperationMeta, operation, cls); - // } catch (Exception e) { - // status = false; - // } - // Assert.assertTrue(status); - // } - // - // @Test - // public void testScanParameters() { - // boolean status = true; - // List paramList = new ArrayList(); - // paramList.add(new BodyParameter()); - // Method method = this.getClass().getMethods()[0]; - // Assert.assertNotNull(paramList); - // Assert.assertNotNull(restOperationMeta); - // Assert.assertNotNull(method); - // try { - // swaggerRestSchemaLoader.scanParameters(restOperationMeta, paramList, method); - // } catch (Exception e) { - // status = false; - // } - // Assert.assertTrue(status); - // } - // - // @Test - // public void testScanParametersWithEmptyList() { - // boolean status = true; - // List paramList = new ArrayList(); - // paramList.add(new BodyParameter()); - // Method method = null; - // try { - // method = RestParam.class.getMethod("setParamProcessor", ParamValueProcessor.class); - // } catch (NoSuchMethodException e) { - // status = false; - // } catch (SecurityException e) { - // status = false; - // } - // Assert.assertNotNull(paramList); - // Assert.assertNotNull(restOperationMeta); - // Assert.assertNotNull(method); - // try { - // swaggerRestSchemaLoader.scanParameters(restOperationMeta, paramList, method); - // } catch (Exception e) { - // status = false; - // } - // Assert.assertTrue(status); - // } - // - // @Test - // public void testSetProduce() { - // boolean status = true; - // List produces = new ArrayList(); - // produces.add("producesString"); - // Assert.assertNotNull(restOperationMeta); - // Assert.assertNotNull(produces); - // try { - // swaggerRestSchemaLoader.setProduce(restOperationMeta, produces); - // } catch (Exception e) { - // status = false; - // } - // Assert.assertTrue(status); - // } - // - // @Test - // public void testFindMethod() { - // - // Class cls = null; - // try { - // cls = Class.forName("java.lang.String"); - // } catch (ClassNotFoundException e) { - // // Do not worry - // } - // Method method = swaggerRestSchemaLoader.findMethod(cls, "operationName"); - // Assert.assertNull(method); - // } - // - // @Test - // public void testFindMethodIndexOf() { - // Class cls = null; - // try { - // cls = Class.forName("java.lang.String"); - // } catch (ClassNotFoundException e) { - // // Do not worry - // } - // Method method = swaggerRestSchemaLoader.findMethod(cls, "indexOf"); - // Assert.assertNotNull(method); - // } - -} diff --git a/coverage-reports/pom.xml b/coverage-reports/pom.xml new file mode 100644 index 00000000000..5489d202b7d --- /dev/null +++ b/coverage-reports/pom.xml @@ -0,0 +1,268 @@ + + + + + + java-chassis + io.servicecomb + 0.1.0-m3-SNAPSHOT + + 4.0.0 + + coverage-reports + pom + + + + io.servicecomb + foundation-common + + + io.servicecomb + foundation-ssl + + + io.servicecomb + foundation-config + + + io.servicecomb + foundation-vertx + + + io.servicecomb + foundation-metrics + + + io.servicecomb + java-chassis-core + + + io.servicecomb + handler-bizkeeper + + + io.servicecomb + handler-loadbalance + + + io.servicecomb + handler-flowcontrol-qps + + + io.servicecomb + common-rest + + + io.servicecomb + transport-rest-client + + + io.servicecomb + transport-rest-vertx + + + io.servicecomb + transport-rest-servlet + + + io.servicecomb + common-protobuf + + + io.servicecomb + common-javassist + + + io.servicecomb + swagger-generator-core + + + io.servicecomb + swagger-generator-jaxrs + + + io.servicecomb + swagger-generator-springmvc + + + io.servicecomb + swagger-invocation-core + + + io.servicecomb + swagger-invocation-jaxrs + + + io.servicecomb + swagger-invocation-springmvc + + + io.servicecomb + service-registry + + + io.servicecomb + provider-pojo + + + io.servicecomb + provider-rest-common + + + io.servicecomb + provider-jaxrs + + + io.servicecomb + provider-springmvc + + + io.servicecomb + transport-highway + + + io.servicecomb + spring-boot-starter-configuration + + + io.servicecomb + spring-boot-starter-provider + + + io.servicecomb + spring-boot-starter-transport + + + io.servicecomb + spring-boot-starter-discovery + + + io.servicecomb.demo + pojo-client + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + pojo-server + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + jaxrs-client + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + jaxrs-server + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + springmvc-client + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + springmvc-server + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + crossapp-client + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + crossapp-server + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + demo-spring-boot-jaxrs-server + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + demo-spring-boot-jaxrs-client + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + demo-spring-boot-pojo-client + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + demo-spring-boot-pojo-server + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + demo-spring-boot-discovery-server + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + demo-spring-boot-discovery-client + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.demo + demo-spring-boot-zuul-proxy + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.tests + jaxrs-tests + 0.1.0-m3-SNAPSHOT + + + io.servicecomb.tests + springmvc-tests + 0.1.0-m3-SNAPSHOT + + + + + + jacoco + + false + + + + + org.jacoco + jacoco-maven-plugin + + + verify + + report-aggregate + + + + + + + + + + diff --git a/demo/demo-jaxrs/pom.xml b/demo/demo-jaxrs/pom.xml index 10c57a54c9a..b774bec2b07 100644 --- a/demo/demo-jaxrs/pom.xml +++ b/demo/demo-jaxrs/pom.xml @@ -28,6 +28,6 @@ jaxrs-server jaxrs-client - + diff --git a/demo/demo-springmvc/pom.xml b/demo/demo-springmvc/pom.xml index 1bb6bfa864f..e57f5fa3b87 100644 --- a/demo/demo-springmvc/pom.xml +++ b/demo/demo-springmvc/pom.xml @@ -28,6 +28,6 @@ springmvc-server springmvc-client - + diff --git a/integration-tests/jaxrs-tests/pom.xml b/integration-tests/jaxrs-tests/pom.xml new file mode 100644 index 00000000000..868f2e90d13 --- /dev/null +++ b/integration-tests/jaxrs-tests/pom.xml @@ -0,0 +1,41 @@ + + + + + + integration-tests + io.servicecomb.tests + 0.1.0-m3-SNAPSHOT + + 4.0.0 + + jaxrs-tests + + + + io.servicecomb.demo + demo-schema + + + io.servicecomb + provider-jaxrs + + + + \ No newline at end of file diff --git a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTest.java b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTest.java new file mode 100644 index 00000000000..bdbf7664123 --- /dev/null +++ b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.demo.jaxrs.tests; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.springframework.http.HttpStatus.OK; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +public class JaxrsIntegrationTest { + + private final RestTemplate restTemplate = new RestTemplate(); + + @BeforeClass + public static void setUp() throws Exception { + JaxrsTestMain.main(new String[0]); + } + + @Test + public void ableToQueryAtRootBasePath() { + ResponseEntity responseEntity = restTemplate + .getForEntity("http://127.0.0.1:8080/sayHi?name=Mike", String.class); + + assertThat(responseEntity.getStatusCode(), is(OK)); + assertThat(responseEntity.getBody(), is("Hi Mike")); + } + + @Test + public void ableToQueryAtRootPath() { + ResponseEntity responseEntity = restTemplate + .getForEntity("http://127.0.0.1:8080/", String.class); + + assertThat(responseEntity.getStatusCode(), is(OK)); + assertThat(responseEntity.getBody(), is("Welcome home")); + } + + @Test + public void ableToQueryAtNonRootPath() { + ResponseEntity responseEntity = restTemplate + .getForEntity("http://127.0.0.1:8080/french/bonjour?name=Mike", String.class); + + assertThat(responseEntity.getStatusCode(), is(OK)); + assertThat(responseEntity.getBody(), is("Bonjour Mike")); + } +} diff --git a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsTestMain.java b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsTestMain.java new file mode 100644 index 00000000000..eee3c62d0eb --- /dev/null +++ b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsTestMain.java @@ -0,0 +1,28 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.demo.jaxrs.tests; + +import io.servicecomb.foundation.common.utils.BeanUtils; +import io.servicecomb.foundation.common.utils.Log4jUtils; + +public class JaxrsTestMain { + + public static void main(String[] args) throws Exception { + Log4jUtils.init(); + BeanUtils.init(); + } +} diff --git a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/EnglishGreetingRestEndpoint.java b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/EnglishGreetingRestEndpoint.java new file mode 100644 index 00000000000..b40309b2d0a --- /dev/null +++ b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/EnglishGreetingRestEndpoint.java @@ -0,0 +1,44 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.demo.jaxrs.tests.endpoints; + +import static javax.ws.rs.core.MediaType.TEXT_PLAIN; + +import io.servicecomb.provider.rest.common.RestSchema; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +@RestSchema(schemaId = "englishGreetingRestEndpoint") +@Path("/") +public class EnglishGreetingRestEndpoint { + + @GET + @Path("/sayHi") + @Produces(TEXT_PLAIN) + public String sayHi(@QueryParam("name") String name) { + return "Hi " + name; + } + + @GET + @Path("") + @Produces(TEXT_PLAIN) + public String home() { + return "Welcome home"; + } +} diff --git a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/FrenchGreetingRestEndpoint.java b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/FrenchGreetingRestEndpoint.java new file mode 100644 index 00000000000..6b1c1905106 --- /dev/null +++ b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/FrenchGreetingRestEndpoint.java @@ -0,0 +1,36 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.demo.jaxrs.tests.endpoints; + +import io.servicecomb.provider.rest.common.RestSchema; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +@RestSchema(schemaId = "frenchGreetingRestEndpoint") +@Path("/french") +public class FrenchGreetingRestEndpoint { + + @GET + @Path("/bonjour") + @Produces(MediaType.TEXT_PLAIN) + public String bonjour(@QueryParam("name") String name) { + return "Bonjour " + name; + } +} diff --git a/integration-tests/jaxrs-tests/src/test/resources/microservice.yaml b/integration-tests/jaxrs-tests/src/test/resources/microservice.yaml new file mode 100644 index 00000000000..e5481957f65 --- /dev/null +++ b/integration-tests/jaxrs-tests/src/test/resources/microservice.yaml @@ -0,0 +1,14 @@ +APPLICATION_ID: jaxrstest +service_description: + name: jaxrs + version: 0.0.2 +cse: + service: + registry: + address: http://127.0.0.1:9980 + rest: + address: 0.0.0.0:8080 + handler: + chain: + Provider: + default: bizkeeper-provider diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index be013575b9d..96e12706b56 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -9,33 +9,25 @@ 4.0.0 + io.servicecomb.tests integration-tests + pom + + jaxrs-tests + springmvc-tests + + + + + + io.servicecomb.demo + demo-schema + 0.1.0-m3-SNAPSHOT + + + - - io.servicecomb - foundation-common - - - io.servicecomb - foundation-ssl - - - io.servicecomb - foundation-config - - - io.servicecomb - foundation-vertx - - - io.servicecomb - foundation-metrics - - - io.servicecomb - java-chassis-core - io.servicecomb handler-bizkeeper @@ -46,196 +38,23 @@ io.servicecomb - handler-flowcontrol-qps - - - io.servicecomb - common-rest - - - io.servicecomb - transport-rest-client + transport-highway io.servicecomb transport-rest-vertx - io.servicecomb - transport-rest-servlet + javax.servlet + javax.servlet-api io.servicecomb - common-protobuf - - - io.servicecomb - common-javassist - - - io.servicecomb - swagger-generator-core - - - io.servicecomb - swagger-generator-jaxrs + handler-flowcontrol-qps io.servicecomb swagger-generator-springmvc - - io.servicecomb - swagger-invocation-core - - - io.servicecomb - swagger-invocation-jaxrs - - - io.servicecomb - swagger-invocation-springmvc - - - io.servicecomb - service-registry - - - io.servicecomb - provider-pojo - - - io.servicecomb - provider-rest-common - - - io.servicecomb - provider-jaxrs - - - io.servicecomb - provider-springmvc - - - io.servicecomb - transport-highway - - - io.servicecomb - spring-boot-starter-configuration - - - io.servicecomb - spring-boot-starter-provider - - - io.servicecomb - spring-boot-starter-transport - - - io.servicecomb - spring-boot-starter-discovery - - - io.servicecomb.demo - pojo-client - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - pojo-server - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - jaxrs-client - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - jaxrs-server - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - springmvc-client - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - springmvc-server - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - crossapp-client - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - crossapp-server - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - demo-spring-boot-jaxrs-server - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - demo-spring-boot-jaxrs-client - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - demo-spring-boot-pojo-client - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - demo-spring-boot-pojo-server - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - demo-spring-boot-discovery-server - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - demo-spring-boot-discovery-client - 0.1.0-m3-SNAPSHOT - - - io.servicecomb.demo - demo-spring-boot-zuul-proxy - 0.1.0-m3-SNAPSHOT - - - - - jacoco - - false - - - - - org.jacoco - jacoco-maven-plugin - - - verify - - report-aggregate - - - - - - - - - diff --git a/integration-tests/springmvc-tests/pom.xml b/integration-tests/springmvc-tests/pom.xml new file mode 100644 index 00000000000..a9cbefc27ea --- /dev/null +++ b/integration-tests/springmvc-tests/pom.xml @@ -0,0 +1,41 @@ + + + + + + integration-tests + io.servicecomb.tests + 0.1.0-m3-SNAPSHOT + + 4.0.0 + + springmvc-tests + + + + io.servicecomb.demo + demo-schema + + + io.servicecomb + provider-springmvc + + + + \ No newline at end of file diff --git a/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/EnglishGreetingRestEndpoint.java b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/EnglishGreetingRestEndpoint.java new file mode 100644 index 00000000000..752512c9890 --- /dev/null +++ b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/EnglishGreetingRestEndpoint.java @@ -0,0 +1,42 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.demo.springmvc.tests; + +import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE; + +import io.servicecomb.provider.rest.common.RestSchema; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +@RestSchema(schemaId = "englishGreetingRestEndpoint") +@RequestMapping(path = "/") +public class EnglishGreetingRestEndpoint { + + @RequestMapping(path = "/sayHi", method = RequestMethod.GET, produces = TEXT_PLAIN_VALUE) + @ResponseBody + public String sayHi(@RequestParam("name") String name) { + return "Hi " + name; + } + + @RequestMapping(path = "", method = RequestMethod.GET, produces = TEXT_PLAIN_VALUE) + @ResponseBody + public String home() { + return "Welcome home"; + } +} diff --git a/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/FrenchGreetingRestEndpoint.java b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/FrenchGreetingRestEndpoint.java new file mode 100644 index 00000000000..76fecf8cd28 --- /dev/null +++ b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/FrenchGreetingRestEndpoint.java @@ -0,0 +1,36 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.demo.springmvc.tests; + +import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE; + +import io.servicecomb.provider.rest.common.RestSchema; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +@RestSchema(schemaId = "frenchGreetingRestEndpoint") +@RequestMapping(path = "/french") +public class FrenchGreetingRestEndpoint { + + @RequestMapping(path = "/bonjour", method = RequestMethod.GET, produces = TEXT_PLAIN_VALUE) + @ResponseBody + public String bonjour(@RequestParam("name") String name) { + return "Bonjour " + name; + } +} diff --git a/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/SpringMvcIntegrationTest.java b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/SpringMvcIntegrationTest.java new file mode 100644 index 00000000000..ac0639bef1d --- /dev/null +++ b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/SpringMvcIntegrationTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.demo.springmvc.tests; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.springframework.http.HttpStatus.OK; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +public class SpringMvcIntegrationTest { + + private final RestTemplate restTemplate = new RestTemplate(); + + @BeforeClass + public static void setUp() throws Exception { + SpringMvcTestMain.main(new String[0]); + } + + @Test + public void ableToQueryAtRootBasePath() { + ResponseEntity responseEntity = restTemplate + .getForEntity("http://127.0.0.1:8080/sayHi?name=Mike", String.class); + + assertThat(responseEntity.getStatusCode(), is(OK)); + assertThat(responseEntity.getBody(), is("Hi Mike")); + } + + @Test + public void ableToQueryAtRootPath() { + ResponseEntity responseEntity = restTemplate + .getForEntity("http://127.0.0.1:8080/", String.class); + + assertThat(responseEntity.getStatusCode(), is(OK)); + assertThat(responseEntity.getBody(), is("Welcome home")); + } + + @Test + public void ableToQueryAtNonRootPath() { + ResponseEntity responseEntity = restTemplate + .getForEntity("http://127.0.0.1:8080/french/bonjour?name=Mike", String.class); + + assertThat(responseEntity.getStatusCode(), is(OK)); + assertThat(responseEntity.getBody(), is("Bonjour Mike")); + } +} diff --git a/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/SpringMvcTestMain.java b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/SpringMvcTestMain.java new file mode 100644 index 00000000000..dade42e8886 --- /dev/null +++ b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/SpringMvcTestMain.java @@ -0,0 +1,28 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.demo.springmvc.tests; + +import io.servicecomb.foundation.common.utils.BeanUtils; +import io.servicecomb.foundation.common.utils.Log4jUtils; + +public class SpringMvcTestMain { + + public static void main(String[] args) throws Exception { + Log4jUtils.init(); + BeanUtils.init(); + } +} diff --git a/integration-tests/springmvc-tests/src/test/resources/microservice.yaml b/integration-tests/springmvc-tests/src/test/resources/microservice.yaml new file mode 100644 index 00000000000..01b62ca63e7 --- /dev/null +++ b/integration-tests/springmvc-tests/src/test/resources/microservice.yaml @@ -0,0 +1,14 @@ +APPLICATION_ID: springmvctest +service_description: + name: springmvc + version: 0.0.2 +cse: + service: + registry: + address: http://127.0.0.1:9980 + rest: + address: 0.0.0.0:8080?sslEnabled=false + handler: + chain: + Provider: + default: bizkeeper-provider diff --git a/parent/pom.xml b/parent/pom.xml index c1b6c7569c6..580687e2605 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -77,7 +77,7 @@ 4.3.0 - ${project.basedir}/integration-tests/target/site/jacoco-aggregate/jacoco.xml + ${project.basedir}/coverage-reports/target/site/jacoco-aggregate/jacoco.xml diff --git a/pom.xml b/pom.xml index b809884d54b..fd5dc70d046 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,7 @@ demo integration-tests java-chassis-distribution + coverage-reports