Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Created groovy validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondrej Pontes authored and Jakub Cechacek committed Jun 17, 2016
1 parent b59a1c6 commit 001410c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
32 changes: 32 additions & 0 deletions apiman-it-validator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apiman-integration-tests</artifactId>
<groupId>io.apiman.test</groupId>
<version>1.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>apiman-it-validator</artifactId>

<properties>
<version.groovy>2.4.6</version.groovy>
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${version.groovy}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
<version>${version.groovy}</version>
</dependency>
</dependencies>

</project>
62 changes: 62 additions & 0 deletions apiman-it-validator/src/main/groovy/ConfigValidator.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import groovy.json.JsonSlurper

/**
* @author opontes
*/

def assertValidMetadata = { json ->
json?.Metadata?.apimanVersion == version
}

def assertValidVersion = { json ->
json?.version == version
}

def assertValidPlugins = { json ->
json?.plugins?.every { it?.version == version }
}

def assertValidRepository = { json ->
json?.repository?.url == repository
}

def setUpCliBuilder() {
def cli = new CliBuilder(usage: 'ConfigValidator -d <amg_dir> -r <repository_url>')
cli.with {
d(longOpt: 'amg_dir', 'AMG directory', args: 1, required: true)
r(longOpt: 'repository_url', 'Maven repository url', args: 1, required: true)
v(longOpt: 'version', 'Apiman version', args: 1, required: false)
}
return cli.parse(args)
}

def MAPPER = [
"/apiman/data/basic-settings.apiman.json" : [
assertValidMetadata
],
"/standalone/data/bootstrap/amg-config.json" : [
assertValidMetadata
],
"/apiman/bootstrap/apiman-default-config.json" : [
assertValidMetadata
],
"/standalone/configuration/amg-plugin-registry.json" : [
assertValidVersion,
assertValidPlugins,
assertValidRepository
]
]

def messages = []
def o = setUpCliBuilder()
if (!o) return
def amg_home = o.d
version = o.v
repository = o.r

MAPPER.each { path, asserts ->
def json = new JsonSlurper().parse(new File(amg_home + path))
def isValid = asserts.every { validator -> validator(json) }
if (!isValid) messages.add("Possible error is in file: ${path}")
}
(messages.empty) ? println("Files are OK.") : println(messages)
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<modules>
<module>apiman-it-commons</module>
<module>apiman-it-deployments</module>
<module>apiman-it-coverage</module>
</modules>

<properties>
Expand Down

0 comments on commit 001410c

Please sign in to comment.