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 support to generate referenced schema
- Loading branch information
Benster Nzewi
committed
Jun 29, 2018
1 parent
79a5a66
commit 90e7bed
Showing
7 changed files
with
167 additions
and
22 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
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
65 changes: 65 additions & 0 deletions
65
catalog-core/src/test/java/uk/gov/justice/schema/catalog/util/CatalogUpdaterTest.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,65 @@ | ||
package uk.gov.justice.schema.catalog.util; | ||
|
||
|
||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import uk.gov.justice.schema.catalog.CatalogUpdater; | ||
import uk.gov.justice.schema.catalog.JsonSchemaFileLoader; | ||
import uk.gov.justice.schema.catalog.RawCatalog; | ||
|
||
import java.io.File; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.slf4j.Logger; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class CatalogUpdaterTest { | ||
|
||
@Mock Logger logger; | ||
@Mock | ||
private JsonSchemaFileLoader jsonSchemaFileLoader; | ||
|
||
@InjectMocks | ||
private RawCatalog rawCatalog; | ||
|
||
@InjectMocks private CatalogUpdater catalogUpdater; | ||
|
||
@Test | ||
public void shouldCacheFileWithReferenceToAnotherSchema(){ | ||
|
||
final Map<String, String> schemaIdsToRawJsonSchemaCache = new HashMap<>(); | ||
final Path basePath = Paths.get(("")); | ||
|
||
schemaIdsToRawJsonSchemaCache.put("http://justice.gov.uk/standards/address.json", "json schema" ); | ||
|
||
rawCatalog.initialize(); | ||
Collection<Path> paths = new ArrayList<>(); | ||
|
||
try { | ||
final File aliasJson = new File(this.getClass().getClassLoader().getResource("json/schema/standards/example.events.alias.json").toURI()); | ||
final File personJson = new File(this.getClass().getClassLoader().getResource("json/schema/standards/example.events.person-updated.json").toURI()); | ||
paths.add(Paths.get(aliasJson.toURI())); | ||
paths.add(Paths.get(personJson.toURI())); | ||
catalogUpdater.updtateRawCatalog(schemaIdsToRawJsonSchemaCache, basePath, paths); | ||
assertThat(schemaIdsToRawJsonSchemaCache.size(), greaterThan(1)); | ||
|
||
} catch (URISyntaxException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
|
||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
catalog-core/src/test/resources/json/schema/standards/defendant.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
25 changes: 25 additions & 0 deletions
25
catalog-core/src/test/resources/json/schema/standards/example.events.alias.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,25 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"id": "http://justice.gov.uk/standards/alias.json", | ||
"properties": { | ||
"aliasForenames": { | ||
"type": "string", | ||
"maxLength": 20 | ||
}, | ||
"aliasInitials": { | ||
"type": "string", | ||
"maxLength": 2 | ||
}, | ||
"aliasSurname": { | ||
"type": "string", | ||
"maxLength": 30 | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
"aliasForenames", | ||
"aliasInitials", | ||
"aliasSurname" | ||
] | ||
} |
56 changes: 56 additions & 0 deletions
56
catalog-core/src/test/resources/json/schema/standards/example.events.person-updated.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 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"id": "http://justice.gov.uk/standards/example.events.person-updated.json", | ||
"properties": { | ||
"personId": { | ||
"$ref": "http://justice.gov.uk/standards/example.standard.uuid.json" | ||
}, | ||
"title": { | ||
"type": "string", | ||
"enum": [ | ||
"", | ||
"Mr", | ||
"Mrs", | ||
"Ms" | ||
] | ||
}, | ||
"firstName": { | ||
"type": "string" | ||
}, | ||
"lastName": { | ||
"type": "string" | ||
}, | ||
"required": { | ||
"type": "boolean" | ||
}, | ||
"signedInCount": { | ||
"type": "integer" | ||
}, | ||
"ratio": { | ||
"type": "number" | ||
}, | ||
"startDate": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"aliases": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "http://justice.gov.uk/standards/alias.json" | ||
} | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
"personId", | ||
"title", | ||
"firstName", | ||
"lastName", | ||
"required", | ||
"signedInCount", | ||
"ratio", | ||
"startDate", | ||
"alias" | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
catalog-core/src/test/resources/json/schema/standards/example.standard.uuid.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,11 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"id": "http://justice.gov.uk/standards/example.standard.uuid.json", | ||
"$ref": "#/definitions/uuid", | ||
"definitions": { | ||
"uuid": { | ||
"type": "string", | ||
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" | ||
} | ||
} | ||
} |