This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git


The following commit(s) were added to refs/heads/master by this push:
     new 2dd373d  Include a test collecting all *.camelk.yaml files in the 
repository and validating it against the yaml schema #387
2dd373d is described below

commit 2dd373d177043d95b143fc0bdc69874261f69177
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Thu Jul 16 16:46:36 2020 +0200

    Include a test collecting all *.camelk.yaml files in the repository and 
validating it against the yaml schema #387
---
 camel-k-loader-yaml/camel-k-loader-yaml/pom.xml    |  6 +++
 .../k/loader/yaml/RoutesValidationTest.groovy      | 53 ++++++++++++++++++++++
 .../resources/routes/RoutesTest_aggregator.yaml    |  2 +-
 pom.xml                                            |  1 +
 4 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml 
b/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml
index 63f07ab..d839228 100644
--- a/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml
+++ b/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml
@@ -100,6 +100,12 @@
             <artifactId>camel-bean</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.github.java-json-tools</groupId>
+            <artifactId>json-schema-validator</artifactId>
+            <version>${json-schema-validator}</version>
+            <scope>test</scope>
+        </dependency>
 
         <dependency>
             <groupId>org.spockframework</groupId>
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesValidationTest.groovy
 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesValidationTest.groovy
new file mode 100644
index 0000000..2d39b09
--- /dev/null
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesValidationTest.groovy
@@ -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.camel.k.loader.yaml
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
+import com.github.fge.jackson.JsonLoader
+import com.github.fge.jsonschema.main.JsonSchemaFactory
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import java.nio.file.Files
+import java.nio.file.Path
+import java.nio.file.Paths
+
+class RoutesValidationTest extends Specification {
+    static def MAPPER = new ObjectMapper(new YAMLFactory())
+    static def SCHEMA_RES = JsonLoader.fromResource('/camel-yaml-dsl.json')
+    static def SCHEMA = JsonSchemaFactory.byDefault().getJsonSchema(SCHEMA_RES)
+
+    @Unroll
+    def 'validate'(Path source) {
+        given:
+            def target = MAPPER.readTree(source.toFile())
+        when:
+            def report = SCHEMA.validate(target)
+        then:
+            report.isSuccess()
+        where:
+            source << routes()
+    }
+
+    def routes() {
+        def routes = getClass().getResource("/routes").toURI()
+        def paths = Paths.get(routes)
+
+        return Files.list(paths)
+    }
+}
diff --git 
a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesTest_aggregator.yaml
 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesTest_aggregator.yaml
index 1634826..9b6e9d9 100644
--- 
a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesTest_aggregator.yaml
+++ 
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesTest_aggregator.yaml
@@ -19,7 +19,7 @@
     steps:
       - aggregate:
           strategy-ref: "aggregatorStrategy"
-          completion-size: 2
+          completion-size: "2"
           correlation-expression:
             simple: "${header.StockSymbol}"
       - to: "mock:route"
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 0f38955..732058c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,7 @@
         <rest-assured.version>4.3.1</rest-assured.version>
         <hamcrest.version>2.2</hamcrest.version>
         <jaeger.version>1.2.0</jaeger.version>
+        <json-schema-validator>2.2.14</json-schema-validator>
 
         <gmavenplus-plugin.version>1.9.0</gmavenplus-plugin.version>
         <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>

Reply via email to