This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example context modules for testing
- Loading branch information
Showing
18 changed files
with
344 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
catalog-core/src/main/java/uk/gov/justice/schema/catalog/util/UriResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package uk.gov.justice.schema.catalog.util; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
public class UriResolver { | ||
|
||
public URI resolve(final URI baseUri, final URI otherUri) throws URISyntaxException { | ||
|
||
if (baseUri.isOpaque()) { | ||
|
||
final String scheme = baseUri.getScheme(); | ||
final String schemeSpecificPart = baseUri.getSchemeSpecificPart(); | ||
final String fragment = baseUri.getFragment(); | ||
final URI resolvedUri = new URI(schemeSpecificPart).resolve(otherUri); | ||
|
||
return new URI(scheme, resolvedUri.toString(), fragment); | ||
} | ||
|
||
return baseUri.resolve(otherUri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
catalog-core/src/test/java/uk/gov/justice/schema/catalog/util/UriResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package uk.gov.justice.schema.catalog.util; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.net.URI; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class UriResolverTest { | ||
|
||
@InjectMocks | ||
private UriResolver uriResolver; | ||
|
||
@Test | ||
public void shouldResolveANonOpaqueUri() throws Exception { | ||
final URI baseUri = new URI("file:/src/target/example-standards-1.0.0-SNAPSHOT.jar!/json/schema/schema_catalog.json"); | ||
final URI otherUri = new URI("ingredient.json"); | ||
|
||
assertThat(uriResolver.resolve(baseUri, otherUri).toString(), is("file:/src/target/example-standards-1.0.0-SNAPSHOT.jar!/json/schema/ingredient.json")); | ||
} | ||
|
||
@Test | ||
public void shouldResolveAnOpaqueUri() throws Exception { | ||
|
||
final URI baseUri = new URI("jar:file:/src/target/example-standards-1.0.0-SNAPSHOT.jar!/json/schema/schema_catalog.json"); | ||
final URI otherUri = new URI("ingredient.json"); | ||
|
||
assertThat(uriResolver.resolve(baseUri, otherUri).toString(), is("jar:file:/src/target/example-standards-1.0.0-SNAPSHOT.jar!/json/schema/ingredient.json")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?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>example-context</artifactId> | ||
<groupId>uk.gov.justice.schema</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>example-command-api</artifactId> | ||
|
||
</project> |
18 changes: 18 additions & 0 deletions
18
example-context/example-command-api/src/main/resources/json/add-recipe.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "Eton Mess", | ||
"glutenFree": false, | ||
"ingredients": [ | ||
{ | ||
"name": "custard", | ||
"quantity": 2 | ||
}, | ||
{ | ||
"name": "egg", | ||
"quantity": 6 | ||
}, | ||
{ | ||
"name": "sugar", | ||
"quantity": 500 | ||
} | ||
] | ||
} |
31 changes: 31 additions & 0 deletions
31
example-context/example-command-api/src/main/resources/json/schema/example.add-recipe.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"id": "http://justice.gov.uk/example/cakeshop/example.add-recipe.json", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Uniquely identifies the cake to be produced from the recipe", | ||
"name": "Name of Cake", | ||
"title": "Name of Cake" | ||
}, | ||
"glutenFree": { | ||
"type": "boolean" | ||
}, | ||
"ingredients": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"id": "http://justice.gov.uk/example/standard/ingredient.json" | ||
} | ||
], | ||
"minItems": 1, | ||
"description": "List ingredients and quantities for recipe" | ||
} | ||
}, | ||
"required": [ | ||
"name", | ||
"ingredients", | ||
"glutenFree" | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
example-context/example-command-api/src/main/resources/json/schema/schema_catalog.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"catalog": { | ||
"name": "example", | ||
"group": [ | ||
{ | ||
"name": "", | ||
"baseLocation": "", | ||
"schema": [ | ||
{ | ||
"id": "http://justice.gov.uk/example/cakeshop/example.add-recipe.json", | ||
"location": "example.add-recipe.json" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?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>example-context</artifactId> | ||
<groupId>uk.gov.justice.schema</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>example-integration-test</artifactId> | ||
|
||
<dependencies> | ||
<!-- Test Dependencies --> | ||
<dependency> | ||
<groupId>uk.gov.justice.schema</groupId> | ||
<artifactId>example-command-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.schema</groupId> | ||
<artifactId>example-standards</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.schema</groupId> | ||
<artifactId>catalog-core</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.utils</groupId> | ||
<artifactId>utilities-core</artifactId> | ||
<version>${utilities.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.jayway.jsonpath</groupId> | ||
<artifactId>json-path-assert</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
52 changes: 52 additions & 0 deletions
52
...example-integration-test/src/test/java/uk/gov/justice/schema/catalog/CatalogLoaderIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package uk.gov.justice.schema.catalog; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import uk.gov.justice.schema.catalog.util.ClasspathResourceLoader; | ||
import uk.gov.justice.schema.catalog.util.UriResolver; | ||
import uk.gov.justice.schema.catalog.util.UrlConverter; | ||
import uk.gov.justice.schema.client.SchemaClientFactory; | ||
import uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer; | ||
|
||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.everit.json.schema.Schema; | ||
import org.junit.Test; | ||
|
||
public class CatalogLoaderIT { | ||
|
||
private final FileContentsAsStringLoader fileContentsAsStringLoader = new FileContentsAsStringLoader(); | ||
private final JsonStringToSchemaConverter jsonStringToSchemaConverter = new JsonStringToSchemaConverter(); | ||
private final SchemaResolverAndLoader schemaResolverAndLoader = new SchemaResolverAndLoader(jsonStringToSchemaConverter); | ||
private final ObjectMapper objectMapper = new ObjectMapperProducer().objectMapper(); | ||
private final UrlConverter urlConverter = new UrlConverter(); | ||
private final UriResolver uriResolver = new UriResolver(); | ||
private final ClasspathResourceLoader classpathResourceLoader = new ClasspathResourceLoader(); | ||
private final ClasspathCatalogLoader classpathCatalogLoader = new ClasspathCatalogLoader(objectMapper, classpathResourceLoader, urlConverter); | ||
private final SchemaResolver schemaResolver = new SchemaResolver(urlConverter, uriResolver); | ||
private final CatalogToSchemaResolver catalogToSchemaResolver = new CatalogToSchemaResolver(classpathCatalogLoader, schemaResolver); | ||
private final JsonSchemaLoader jsonSchemaLoader = new JsonSchemaLoader(fileContentsAsStringLoader); | ||
private final SchemaClientFactory schemaClientFactory = new SchemaClientFactory(); | ||
|
||
private final CatalogLoader catalogLoader = new CatalogLoader( | ||
schemaResolverAndLoader, | ||
catalogToSchemaResolver, | ||
jsonSchemaLoader, | ||
schemaClientFactory); | ||
|
||
@Test | ||
public void shouldMapSchemasOnClasspathToTheirIds() throws Exception { | ||
|
||
final Map<String, Schema> idsToSchemaMap = catalogLoader.loadCatalogsFromClasspath(); | ||
|
||
assertThat(idsToSchemaMap.size(), is(2)); | ||
|
||
final String id_1 = "http://justice.gov.uk/example/standard/ingredient.json"; | ||
final String json_1 = idsToSchemaMap.get(id_1).toString(); | ||
|
||
final String id_2 = "http://justice.gov.uk/example/cakeshop/example.add-recipe.json"; | ||
final String json_2 = idsToSchemaMap.get(id_2).toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?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>example-context</artifactId> | ||
<groupId>uk.gov.justice.schema</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>example-standards</artifactId> | ||
|
||
|
||
</project> |
17 changes: 17 additions & 0 deletions
17
example-context/example-standards/src/main/resources/json/schema/schema_catalog.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"catalog": { | ||
"name": "standards", | ||
"group": [ | ||
{ | ||
"name": "cakeshop", | ||
"baseLocation": "standards/", | ||
"schema": [ | ||
{ | ||
"id": "http://justice.gov.uk/example/standard/ingredient.json", | ||
"location": "ingredient.json" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
example-context/example-standards/src/main/resources/json/schema/standards/ingredient.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"id": "http://justice.gov.uk/example/standard/ingredient.json", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"quantity": { | ||
"type": "integer" | ||
} | ||
} | ||
} |
Oops, something went wrong.