This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git
commit e26fac5d7edbe618e62e7697c88d0353cbec5c15 Author: Daniel Qian <chanjars...@gmail.com> AuthorDate: Tue Nov 5 22:56:35 2019 +0800 SCB-1553 Integrate oas-validator compliance check to cli Increase test coverage. --- .../apache/servicecomb/toolkit/cli/CliTest.java | 10 ++++ cli/src/test/resources/oas/parser-test.yaml | 48 +++++++++++++++ .../oas-validator-compatibility-spring/pom.xml | 8 ++- .../config/ValidatorConfigurationsTest.java | 64 ++++++++++++++++++++ .../src/test/resources/logback-test.xml | 22 +++++++ .../oas-validator-compliance-spring/pom.xml | 6 ++ .../config/ValidatorConfigurationsTest.java | 68 ++++++++++++++++++++++ .../src/test/resources/logback-test.xml | 22 +++++++ 8 files changed, 247 insertions(+), 1 deletion(-) diff --git a/cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java b/cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java index 631bf28..3c2fd7b 100755 --- a/cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java +++ b/cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java @@ -90,4 +90,14 @@ public class CliTest { tempDir.toFile().deleteOnExit(); } + + @Test + public void testCheckStyle() throws IOException { + String[] args = new String[] { + "checkstyle", + Paths.get("./src/test/resources/oas/parser-test.yaml").toFile().getCanonicalPath() + }; + ToolkitMain.main(args); + } + } diff --git a/cli/src/test/resources/oas/parser-test.yaml b/cli/src/test/resources/oas/parser-test.yaml new file mode 100644 index 0000000..f7b88b5 --- /dev/null +++ b/cli/src/test/resources/oas/parser-test.yaml @@ -0,0 +1,48 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +openapi: "3.0.0" +info: + version: 1.0.0 + title: Pet petstore +paths: + /pets: + get: + summary: List all pets + operationId: listpets + responses: + '200': + description: A paged array of pets + + post: + summary: List all pets + operationId: foo + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + foo: + type: string + bar: + type: string + encoding: + foo: + contentType: 'application/octet-stream' + responses: + '200': + description: A paged array of pets diff --git a/oas-validator/oas-validator-compatibility-spring/pom.xml b/oas-validator/oas-validator-compatibility-spring/pom.xml index 7a4c85b..f60ee7b 100644 --- a/oas-validator/oas-validator-compatibility-spring/pom.xml +++ b/oas-validator/oas-validator-compatibility-spring/pom.xml @@ -41,10 +41,16 @@ <groupId>org.apache.servicecomb.toolkit</groupId> <artifactId>oas-validator-core-spring</artifactId> </dependency> - + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> </dependency> </dependencies> diff --git a/oas-validator/oas-validator-compatibility-spring/src/test/java/org/apache/servicecomb/toolkit/oasv/compatibility/config/ValidatorConfigurationsTest.java b/oas-validator/oas-validator-compatibility-spring/src/test/java/org/apache/servicecomb/toolkit/oasv/compatibility/config/ValidatorConfigurationsTest.java new file mode 100644 index 0000000..e2ca246 --- /dev/null +++ b/oas-validator/oas-validator-compatibility-spring/src/test/java/org/apache/servicecomb/toolkit/oasv/compatibility/config/ValidatorConfigurationsTest.java @@ -0,0 +1,64 @@ +/* + * 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.toolkit.oasv.compatibility.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.servicecomb.toolkit.oasv.diffvalidation.api.EncodingDiffValidator; +import org.apache.servicecomb.toolkit.oasv.diffvalidation.api.HeaderDiffValidator; +import org.apache.servicecomb.toolkit.oasv.diffvalidation.api.MediaTypeDiffValidator; +import org.apache.servicecomb.toolkit.oasv.diffvalidation.api.OperationDiffValidator; +import org.apache.servicecomb.toolkit.oasv.diffvalidation.api.ParameterDiffValidator; +import org.apache.servicecomb.toolkit.oasv.diffvalidation.api.PathItemDiffValidator; +import org.apache.servicecomb.toolkit.oasv.diffvalidation.api.RequestBodyDiffValidator; +import org.apache.servicecomb.toolkit.oasv.diffvalidation.api.ResponseDiffValidator; +import org.apache.servicecomb.toolkit.oasv.diffvalidation.api.SchemaDiffValidator; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.BeansException; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@SpringBootApplication +public class ValidatorConfigurationsTest implements ApplicationContextAware { + + private ApplicationContext applicationContext; + + @Test + public void testConfigurations() { + assertThat(applicationContext.getBeansOfType(EncodingDiffValidator.class)).hasSize(7); + assertThat(applicationContext.getBeansOfType(HeaderDiffValidator.class)).hasSize(3); + assertThat(applicationContext.getBeansOfType(MediaTypeDiffValidator.class)).hasSize(6); + assertThat(applicationContext.getBeansOfType(OperationDiffValidator.class)).hasSize(5); + assertThat(applicationContext.getBeansOfType(ParameterDiffValidator.class)).hasSize(8); + assertThat(applicationContext.getBeansOfType(PathItemDiffValidator.class)).hasSize(3); + assertThat(applicationContext.getBeansOfType(RequestBodyDiffValidator.class)).hasSize(2); + assertThat(applicationContext.getBeansOfType(ResponseDiffValidator.class)).hasSize(3); + assertThat(applicationContext.getBeansOfType(SchemaDiffValidator.class)).hasSize(1); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } +} diff --git a/oas-validator/oas-validator-compatibility-spring/src/test/resources/logback-test.xml b/oas-validator/oas-validator-compatibility-spring/src/test/resources/logback-test.xml new file mode 100644 index 0000000..a1ba69a --- /dev/null +++ b/oas-validator/oas-validator-compatibility-spring/src/test/resources/logback-test.xml @@ -0,0 +1,22 @@ +<?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. + --> + +<configuration> + <include resource="org/springframework/boot/logging/logback/base.xml" /> + <logger name="org.springframework" level="OFF"/> +</configuration> diff --git a/oas-validator/oas-validator-compliance-spring/pom.xml b/oas-validator/oas-validator-compliance-spring/pom.xml index 5e4b0f9..f143d9e 100644 --- a/oas-validator/oas-validator-compliance-spring/pom.xml +++ b/oas-validator/oas-validator-compliance-spring/pom.xml @@ -47,6 +47,12 @@ <artifactId>spring-boot-starter</artifactId> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> <build> diff --git a/oas-validator/oas-validator-compliance-spring/src/test/java/org/apache/servicecomb/toolkit/oasv/compliance/config/ValidatorConfigurationsTest.java b/oas-validator/oas-validator-compliance-spring/src/test/java/org/apache/servicecomb/toolkit/oasv/compliance/config/ValidatorConfigurationsTest.java new file mode 100644 index 0000000..dda31f8 --- /dev/null +++ b/oas-validator/oas-validator-compliance-spring/src/test/java/org/apache/servicecomb/toolkit/oasv/compliance/config/ValidatorConfigurationsTest.java @@ -0,0 +1,68 @@ +/* + * 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.toolkit.oasv.compliance.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.servicecomb.toolkit.oasv.validation.api.ComponentsValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.EncodingValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.HeaderValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.InfoValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.OpenApiValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.OperationValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.ParameterValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.PathsValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.RequestBodyValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.SchemaValidator; +import org.apache.servicecomb.toolkit.oasv.validation.api.TagValidator; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.BeansException; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@SpringBootApplication +public class ValidatorConfigurationsTest implements ApplicationContextAware { + + private ApplicationContext applicationContext; + + @Test + public void testConfigurations() { + assertThat(applicationContext.getBeansOfType(ComponentsValidator.class)).hasSize(14); + assertThat(applicationContext.getBeansOfType(EncodingValidator.class)).hasSize(2); + assertThat(applicationContext.getBeansOfType(HeaderValidator.class)).hasSize(2); + assertThat(applicationContext.getBeansOfType(InfoValidator.class)).hasSize(1); + assertThat(applicationContext.getBeansOfType(OpenApiValidator.class)).hasSize(8); + assertThat(applicationContext.getBeansOfType(OperationValidator.class)).hasSize(8); + assertThat(applicationContext.getBeansOfType(ParameterValidator.class)).hasSize(7); + assertThat(applicationContext.getBeansOfType(PathsValidator.class)).hasSize(2); + assertThat(applicationContext.getBeansOfType(RequestBodyValidator.class)).hasSize(2); + assertThat(applicationContext.getBeansOfType(SchemaValidator.class)).hasSize(2); + assertThat(applicationContext.getBeansOfType(TagValidator.class)).hasSize(3); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } +} diff --git a/oas-validator/oas-validator-compliance-spring/src/test/resources/logback-test.xml b/oas-validator/oas-validator-compliance-spring/src/test/resources/logback-test.xml new file mode 100644 index 0000000..a1ba69a --- /dev/null +++ b/oas-validator/oas-validator-compliance-spring/src/test/resources/logback-test.xml @@ -0,0 +1,22 @@ +<?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. + --> + +<configuration> + <include resource="org/springframework/boot/logging/logback/base.xml" /> + <logger name="org.springframework" level="OFF"/> +</configuration>