Skip to content

Commit

Permalink
#35 added testing data , fixed from ocds example, added validation fo…
Browse files Browse the repository at this point in the history
…r embedded versioned releases and compiled releases
  • Loading branch information
mpostelnicu committed Oct 4, 2018
1 parent 80325f1 commit 9a71c9c
Show file tree
Hide file tree
Showing 12 changed files with 3,710 additions and 22 deletions.
16 changes: 16 additions & 0 deletions jocds-cli/src/test/java/test/TestOcdsValidatorRelease.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ public void testReleasePackageValidation() {

}

@Test
public void testRecordPackageValidation() {

OcdsValidatorStringRequest request = new OcdsValidatorStringRequest(null, new TreeSet<>(),
OcdsValidatorConstants.Schemas.RECORD_PACKAGE);

request.setJson(getJsonFromResource("/record-package.json"));

ProcessingReport processingReport = ocdsValidatorService.validate(request);
if (!processingReport.isSuccess()) {
System.out.println(processingReport);
}

Assert.assertTrue(processingReport.isSuccess());
}

@Test
public void testReleasePackageValidationWithVersionAutodetect() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public static final class Extensions {

public static final String EXTENSIONS_PROPERTY = "extensions";
public static final String RELEASES_PROPERTY = "releases";
public static final String RECORDS_PROPERTY = "records";
public static final String COMPILED_RELEASE_PROPERTY = "compiledRelease";
public static final String VERSIONED_RELEASE_PROPERTY = "versionedRelease";
public static final String OCID_PROPERTY = "ocid";
public static final String VERSION_PROPERTY = "version";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ private JsonNode getExtensionMeta(boolean trustSelfSignedCerts, String id) {
}

//attempt load via URL
JsonNode jsonNode = readExtensionMetaURL(trustSelfSignedCerts, id);
extensionMeta.put(id, jsonNode);
return jsonNode;
JsonNode jsonNode = readExtensionMetaURL(trustSelfSignedCerts, id);
extensionMeta.put(id, jsonNode);
return jsonNode;
}

private boolean compatibleExtension(JsonNode extensionNodeMeta, String fullVersion) {
Expand Down Expand Up @@ -233,13 +233,13 @@ private JsonMergePatch getExtensionReleaseJson(boolean trustSelfSignedCerts, Str
}

//attempt load via URL
String releaseUrl = id.replace(
OcdsValidatorConstants.REMOTE_EXTENSION_META_POSTFIX,
OcdsValidatorConstants.EXTENSION_RELEASE_JSON
);
JsonMergePatch patch = readExtensionReleaseJsonURL(trustSelfSignedCerts, releaseUrl);
extensionReleaseJson.put(id, patch);
return patch;
String releaseUrl = id.replace(
OcdsValidatorConstants.REMOTE_EXTENSION_META_POSTFIX,
OcdsValidatorConstants.EXTENSION_RELEASE_JSON
);
JsonMergePatch patch = readExtensionReleaseJsonURL(trustSelfSignedCerts, releaseUrl);
extensionReleaseJson.put(id, patch);
return patch;
}

private JsonNode readExtensionMeta(String extensionName) {
Expand All @@ -254,8 +254,8 @@ private JsonNode readExtensionMeta(String extensionName) {
}

private JsonNode readExtensionMetaURL(boolean trustSelfSignedCerts, String url) {
logger.debug("Reading extension metadata from URL " + url);
return getJsonNodeFromUrl(trustSelfSignedCerts, url);
logger.debug("Reading extension metadata from URL " + url);
return getJsonNodeFromUrl(trustSelfSignedCerts, url);
}

private JsonMergePatch readExtensionReleaseJsonURL(boolean trustSelfSignedCerts, String url) {
Expand Down Expand Up @@ -488,7 +488,7 @@ public ProcessingReport validate(OcdsValidatorNodeRequest nodeRequest) {

if (nodeRequest.getSchemaType().equals(OcdsValidatorConstants.Schemas.RELEASE)
|| nodeRequest.getSchemaType().equals(
OcdsValidatorConstants.Schemas.VERSIONED_RELEASE_VALIDATION)) {
OcdsValidatorConstants.Schemas.VERSIONED_RELEASE_VALIDATION)) {

if (nodeRequest.getVersion() == null) {
throw new RuntimeException("Not allowed null version info for release validation!");
Expand Down Expand Up @@ -588,7 +588,8 @@ private ProcessingReport validateEmbeddedReleases(OcdsValidatorNodeRequest nodeR
ProcessingReport returnedReport = new ListProcessingReport();
for (JsonNode release : releasesNode) {
returnedReport.mergeWith(validateEmbeddedRelease(nodeRequest,
release, releaseType));
release, releaseType
));
}
return returnedReport;
}
Expand Down Expand Up @@ -672,9 +673,11 @@ private ProcessingReport validateReleasePackage(OcdsValidatorNodeRequest nodeReq
applyExtensions(nodeRequest);

if (nodeRequest.getNode().hasNonNull(OcdsValidatorConstants.RELEASES_PROPERTY)) {
releasePackageReport.mergeWith(validateEmbeddedReleases(nodeRequest,
releasePackageReport.mergeWith(validateEmbeddedReleases(
nodeRequest,
nodeRequest.getNode().get(OcdsValidatorConstants.RELEASES_PROPERTY),
OcdsValidatorConstants.Schemas.RELEASE));
OcdsValidatorConstants.Schemas.RELEASE
));
} else {
throw new RuntimeException("No releases were found during release package validation!");
}
Expand All @@ -699,19 +702,38 @@ private ProcessingReport validateRecordPackage(OcdsValidatorNodeRequest nodeRequ

JsonSchema schema = getSchema(nodeRequest);
try {

//do a general non extension validation of entire json
ProcessingReport recordPackageReport = schema.validate(nodeRequest.getNode());
if (!recordPackageReport.isSuccess()) {
return recordPackageReport;
}

//validate each release separately, after applying extensions
applyExtensions(nodeRequest);

if (nodeRequest.getNode().hasNonNull(OcdsValidatorConstants.RELEASES_PROPERTY)) {
recordPackageReport.mergeWith(validateEmbeddedReleases(nodeRequest,
nodeRequest.getNode().get(OcdsValidatorConstants.RELEASES_PROPERTY),
OcdsValidatorConstants.Schemas.RELEASE));
} else {
throw new RuntimeException("No releases were found during release package validation!");
//get all records
if (nodeRequest.getNode().hasNonNull(OcdsValidatorConstants.RECORDS_PROPERTY)) {
for (JsonNode record : nodeRequest.getNode().get(OcdsValidatorConstants.RECORDS_PROPERTY)) {

//validate compiled release
if (record.hasNonNull(OcdsValidatorConstants.COMPILED_RELEASE_PROPERTY)) {
recordPackageReport.mergeWith(validateEmbeddedRelease(
nodeRequest,
record.get(OcdsValidatorConstants.COMPILED_RELEASE_PROPERTY),
OcdsValidatorConstants.Schemas.RELEASE
));
}

//validate versioned release
if (record.hasNonNull(OcdsValidatorConstants.VERSIONED_RELEASE_PROPERTY)) {
recordPackageReport.mergeWith(validateEmbeddedRelease(
nodeRequest,
record.get(OcdsValidatorConstants.VERSIONED_RELEASE_PROPERTY),
OcdsValidatorConstants.Schemas.VERSIONED_RELEASE_VALIDATION
));
}
}
}

return recordPackageReport;
Expand Down
Loading

0 comments on commit 9a71c9c

Please sign in to comment.