Skip to content

Commit

Permalink
Include a test collecting all *.camelk.yaml files in the repository a…
Browse files Browse the repository at this point in the history
…nd validating it against the yaml schema #387
  • Loading branch information
lburgazzoli committed Jul 16, 2020
1 parent d9468dd commit f925cb4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions camel-k-loader-yaml/camel-k-loader-yaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
steps:
- aggregate:
strategy-ref: "aggregatorStrategy"
completion-size: 2
completion-size: "2"
correlation-expression:
simple: "${header.StockSymbol}"
- to: "mock:route"
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit f925cb4

Please sign in to comment.