-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
183 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: java | ||
jdk: | ||
- oraclejdk8 | ||
notifications: | ||
slack: | ||
secure: UjSpOIXxnH3JLZc109j+EzVwzVVvlNPsFoTRUf9uSfkwSCcAU/UQGOennJANOgloFychYl+YytWF9+Qi9AfF5OyFsXWqs4cx8CylQlN9YbEzUkCtGt4CX1AZqUCiH9oAzSExIS8FTpn/Viu8YtF91djaMdX5s+Nfj9IcVwWbrUE= |
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
142 changes: 142 additions & 0 deletions
142
...ta-validator/src/test/java/org/openmhealth/schema/TestDataValidationIntegrationTests.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,142 @@ | ||
/* | ||
* Copyright 2015 Open mHealth | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.openmhealth.schema; | ||
|
||
|
||
import com.github.fge.jackson.JacksonUtils; | ||
import com.github.fge.jsonschema.core.report.ProcessingMessage; | ||
import com.github.fge.jsonschema.core.report.ProcessingReport; | ||
import org.openmhealth.schema.configuration.Application; | ||
import org.openmhealth.schema.domain.DataFile; | ||
import org.openmhealth.schema.domain.DataFileValidationResult; | ||
import org.openmhealth.schema.domain.SchemaFile; | ||
import org.openmhealth.schema.domain.omh.SchemaVersion; | ||
import org.openmhealth.schema.service.DataFileService; | ||
import org.openmhealth.schema.service.SchemaFileService; | ||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.IntegrationTest; | ||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.openmhealth.schema.domain.DataFileValidationResult.FAIL; | ||
import static org.openmhealth.schema.domain.DataFileValidationResult.PASS; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
|
||
/** | ||
* A test suite that dynamically creates a test for each combination of schema and applicable test data file. | ||
* | ||
* @author Emerson Farrugia | ||
*/ | ||
@SpringApplicationConfiguration(classes = Application.class) | ||
@IntegrationTest | ||
public class TestDataValidationIntegrationTests extends AbstractTestNGSpringContextTests { | ||
|
||
private static final Logger logger = getLogger(TestDataValidationIntegrationTests.class); | ||
|
||
@Autowired | ||
private SchemaFileService schemaFileService; | ||
|
||
@Autowired | ||
private DataFileService dataFileService; | ||
|
||
@Value("${schemaFiles.baseDirectory}") | ||
private String schemaFileBaseDirectory; | ||
|
||
@Value("${testDataFiles.baseDirectory}") | ||
private String testDataFileBaseDirectory; | ||
|
||
|
||
@Test(dataProvider = "validationPairProvider") | ||
public void validateTestData(SchemaFile schemaFile, DataFile dataFile) throws Exception { | ||
|
||
ProcessingReport report = schemaFile.getJsonSchema().validate(dataFile.getData()); | ||
DataFileValidationResult validationResult = report.isSuccess() ? PASS : FAIL; | ||
|
||
if (validationResult != dataFile.getExpectedValidationResult()) { | ||
for (ProcessingMessage processingMessage : report) { | ||
logger.error(JacksonUtils.prettyPrint(processingMessage.asJson())); | ||
} | ||
} | ||
|
||
assertThat(dataFile.getExpectedValidationResult(), equalTo(validationResult)); | ||
} | ||
|
||
/** | ||
* @return an iterator over all pairs of schema files and applicable test data files | ||
*/ | ||
@DataProvider(name = "validationPairProvider") | ||
public Iterator<Object[]> newValidationPairProvider() { | ||
|
||
List<SchemaFile> schemaFiles = schemaFileService.getSchemaFiles(asUri(schemaFileBaseDirectory)); | ||
|
||
if (schemaFiles.size() == 0) { | ||
return Collections.emptyIterator(); | ||
} | ||
|
||
List<DataFile> dataFiles = dataFileService.getDataFiles(asUri(testDataFileBaseDirectory)); | ||
|
||
if (dataFiles.size() == 0) { | ||
return Collections.emptyIterator(); | ||
} | ||
|
||
List<Object[]> validationPairs = new ArrayList<>(); | ||
|
||
for (SchemaFile schemaFile : schemaFiles) { | ||
|
||
for (DataFile dataFile : dataFiles) { | ||
|
||
if (!dataFile.getSchemaId().getName().equals(schemaFile.getSchemaId().getName())) { | ||
continue; | ||
} | ||
|
||
SchemaVersion dataFileVersion = dataFile.getSchemaId().getVersion(); | ||
SchemaVersion schemaFileVersion = schemaFile.getSchemaId().getVersion(); | ||
|
||
if (dataFileVersion.getMajor() != schemaFileVersion.getMajor()) { | ||
continue; | ||
} | ||
|
||
// a data point conforms to the schema listed in its header and newer minor versions of that schema | ||
if (dataFileVersion.getMinor() > schemaFileVersion.getMinor()) { | ||
continue; | ||
} | ||
|
||
validationPairs.add(new Object[]{schemaFile, dataFile}); | ||
} | ||
} | ||
|
||
return validationPairs.iterator(); | ||
} | ||
|
||
private URI asUri(String filename) { | ||
return new File(filename).toURI(); | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
test-data/omh/descriptive-statistic/1.1/shouldFail/empty-string.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
test-data/omh/descriptive-statistic/1.1/shouldFail/invalid-statistic.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
test-data/omh/descriptive-statistic/1.1/shouldPass/valid-statistic.json
This file was deleted.
Oops, something went wrong.