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.
rename groups and schemas to their plurals in catalogs and domain obj…
…ects
- Loading branch information
amckenzie
committed
Nov 30, 2017
1 parent
4a14207
commit 5f244c5
Showing
15 changed files
with
152 additions
and
77 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
20 changes: 14 additions & 6 deletions
20
catalog-core/src/main/java/uk/gov/justice/schema/catalog/JsonStringToSchemaConverter.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 |
---|---|---|
@@ -1,19 +1,27 @@ | ||
package uk.gov.justice.schema.catalog; | ||
|
||
import static java.lang.String.format; | ||
|
||
import org.everit.json.schema.Schema; | ||
import org.everit.json.schema.loader.SchemaClient; | ||
import org.everit.json.schema.loader.SchemaLoader; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.json.JSONTokener; | ||
|
||
public class JsonStringToSchemaConverter { | ||
|
||
// TODO: test me!!! | ||
public Schema convert(final String schemaJson, final SchemaClient schemaClient) { | ||
return SchemaLoader.builder() | ||
.schemaJson(new JSONObject(new JSONTokener(schemaJson))) | ||
.httpClient(schemaClient) | ||
.build() | ||
.load() | ||
.build(); | ||
try { | ||
return SchemaLoader.builder() | ||
.schemaJson(new JSONObject(new JSONTokener(schemaJson))) | ||
.httpClient(schemaClient) | ||
.build() | ||
.load() | ||
.build(); | ||
} catch (final JSONException e) { | ||
throw new SchemaCatalogException(format("Failed to convert schema json to Schema Object. Schema json:%n%s", schemaJson), e); | ||
} | ||
} | ||
} |
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
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
45 changes: 45 additions & 0 deletions
45
...log-core/src/test/java/uk/gov/justice/schema/catalog/JsonStringToSchemaConverterTest.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,45 @@ | ||
package uk.gov.justice.schema.catalog; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.CoreMatchers.startsWith; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.net.URL; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.everit.json.schema.loader.SchemaClient; | ||
import org.json.JSONException; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class JsonStringToSchemaConverterTest { | ||
|
||
@InjectMocks | ||
private JsonStringToSchemaConverter jsonStringToSchemaConverter; | ||
|
||
@Test | ||
public void shouldFailWithErrorMessageIfParsingTheJsonStringFails() throws Exception { | ||
|
||
final URL url = getClass().getClassLoader().getResource("json/dodgy-schemas/schema-with-two-ids.json"); | ||
|
||
assertThat(url, is(notNullValue())); | ||
|
||
final String schemaJson = IOUtils.toString(url); | ||
|
||
try { | ||
jsonStringToSchemaConverter.convert(schemaJson, mock(SchemaClient.class)); | ||
fail(); | ||
} catch (final SchemaCatalogException expected) { | ||
assertThat(expected.getCause(), is(instanceOf(JSONException.class))); | ||
assertThat(expected.getMessage(), startsWith("Failed to convert schema json to Schema Object. Schema json:")); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
catalog-core/src/test/resources/json/dodgy-schemas/schema-with-two-ids.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,22 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"id": "http://justice.gov.uk/context/person.json", | ||
"type": "object", | ||
"id": "http://justice.gov.uk/context/person.json", | ||
"properties": { | ||
"nino": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"correspondence_address": | ||
{"$ref" : "http://justice.gov.uk/standards/complex_address.json#/definitions/complex_address2"} | ||
|
||
}, | ||
"required": [ | ||
"nino", | ||
"name", | ||
"correspondence_address" | ||
] | ||
} |
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
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
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
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