Skip to content

Commit

Permalink
Merge branch 'release/v1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
emersonf committed Jul 3, 2015
2 parents 4be10be + ea3284a commit 7717e03
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
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=
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Open mHealth Schema Repository

A repository of Open mHealth [schemas](http://www.openmhealth.org/developers/schemas/). This repository also includes sample test data, a validator for that data, and a Java schema SDK.

[![Build Status](https://travis-ci.org/openmhealth/schemas.svg?branch=develop)](https://travis-ci.org/openmhealth/schemas)

## Schemas
The schemas are located in the [schema](schema) directory.

## Validator and test data
The [validator](test-data-validator) is a simple application that validates test data against schemas. The test data
that it uses is located in the [test-data](test-data) directory.

## Java SDK
## Java SDK
The [Java SDK](java-schema-sdk) helps you produce and consume Open mHealth compliant data in your Java, Groovy, and Scala applications.

## Tooling
Expand Down
2 changes: 1 addition & 1 deletion java-schema-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray' // see https://github.com/bintray/gradle-bintray-plugin for details

archivesBaseName = 'omh-schema-sdk'
version = '1.0.1'
version = '1.0.2'

ext {
jacksonVersion = '2.5.3'
Expand Down
7 changes: 6 additions & 1 deletion schema/omh/minutes-moderate-activity-1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"description": "This schema represents a single measurement of minutes of moderate-intensity activity performed. The ability to represent descriptive statistics (e.g., mean, median) will be added shortly.",

"references": [
{
"description": "The SNOMED code represents Physical activity target moderate exercise (finding)",
"url": "http://purl.bioontology.org/ontology/SNOMEDCT/408581006"
}
],
"definitions": {
"duration_unit_value": {
"$ref": "duration-unit-value-1.x.json"
Expand Down
7 changes: 6 additions & 1 deletion test-data-validator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ buildscript {
}

ext {
springBootVersion = '1.2.4.RELEASE'
springBootVersion = '1.2.5.RELEASE'
}

dependencies {
Expand Down Expand Up @@ -81,4 +81,9 @@ dependencies {
testCompile 'junit:junit'
testCompile 'org.mockito:mockito-core'
testCompile 'org.springframework:spring-test'
testCompile 'org.testng:testng:6.8.21'
}

test {
useTestNG()
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class Application {
@Autowired
private ValidationService validationService;


public static void main(String[] args) throws IOException, ProcessingException {

ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class DataFile {

private String name;
private URI location;
private String path;
private SchemaId schemaId;
private DataFileValidationResult expectedValidationResult;
private JsonNode data;
Expand All @@ -55,6 +56,7 @@ public DataFile(URI location, JsonNode data) {

this.name = matcher.group(5);
this.location = location;
this.path = matcher.group(0);
this.schemaId = new SchemaId(matcher.group(1), matcher.group(2), new SchemaVersion(matcher.group(3)));
this.expectedValidationResult = matcher.group(4).equals("shouldPass") ? PASS : FAIL;
this.data = data;
Expand All @@ -68,6 +70,10 @@ public URI getLocation() {
return location;
}

public String getPath() {
return path;
}

public SchemaId getSchemaId() {
return schemaId;
}
Expand All @@ -79,4 +85,9 @@ public DataFileValidationResult getExpectedValidationResult() {
public JsonNode getData() {
return data;
}

@Override
public String toString() {
return getPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ public URI getLocation() {
public JsonSchema getJsonSchema() {
return jsonSchema;
}


@Override
public String toString() {
return getSchemaId().toString();
}
}
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();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 7717e03

Please sign in to comment.