-
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
7 changed files
with
290 additions
and
16 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
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
java-schema-sdk/src/main/java/org/openmhealth/schema/domain/omh/FreeFormMeasure.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 @@ | ||
/* | ||
* Copyright 2016 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.domain.omh; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import org.openmhealth.schema.serializer.SerializationConstructor; | ||
|
||
|
||
/** | ||
* A measure whose only declared property is a schema identifier, requiring JSON Schema additional properties for any | ||
* remaining properties. | ||
* | ||
* @author Emerson Farrugia | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class) | ||
public class FreeFormMeasure extends Measure { | ||
|
||
private SchemaId schemaId; | ||
|
||
@SerializationConstructor | ||
protected FreeFormMeasure() { | ||
} | ||
|
||
public static class Builder extends Measure.Builder<FreeFormMeasure, FreeFormMeasure.Builder> { | ||
|
||
private SchemaId schemaId; | ||
|
||
public Builder(String schemaNamespace, String schemaName, String schemaVersion) { | ||
this.schemaId = new SchemaId(schemaNamespace, schemaName, schemaVersion); | ||
} | ||
|
||
@Override | ||
public FreeFormMeasure build() { | ||
return new FreeFormMeasure(this); | ||
} | ||
} | ||
|
||
private FreeFormMeasure(FreeFormMeasure.Builder builder) { | ||
super(builder); | ||
|
||
schemaId = builder.schemaId; | ||
} | ||
|
||
@Override | ||
public SchemaId getSchemaId() { | ||
return this.schemaId; | ||
} | ||
} |
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
112 changes: 112 additions & 0 deletions
112
...-schema-sdk/src/test/java/org/openmhealth/schema/domain/omh/FreeFormMeasureUnitTests.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,112 @@ | ||
/* | ||
* Copyright 2016 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.domain.omh; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
|
||
/** | ||
* @author Emerson Farrugia | ||
*/ | ||
public class FreeFormMeasureUnitTests extends SerializationUnitTests { | ||
|
||
@Test(expectedExceptions = NullPointerException.class) | ||
public void constructorShouldThrowExceptionOnUndefinedSchemaNamespace() { | ||
|
||
new FreeFormMeasure.Builder(null, "body-weight", "1.0"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void constructorShouldThrowExceptionOnInvalidSchemaNamespace() { | ||
|
||
new FreeFormMeasure.Builder("%", "body-weight", "1.0"); | ||
} | ||
|
||
@Test(expectedExceptions = NullPointerException.class) | ||
public void constructorShouldThrowExceptionOnUndefinedSchemaName() { | ||
|
||
new FreeFormMeasure.Builder("omh", null, "1.0"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void constructorShouldThrowExceptionOnInvalidSchemaName() { | ||
|
||
new FreeFormMeasure.Builder("omh", "%", "1.0"); | ||
} | ||
|
||
@Test(expectedExceptions = NullPointerException.class) | ||
public void constructorShouldThrowExceptionOnUndefinedSchemaVersion() { | ||
|
||
new FreeFormMeasure.Builder("omh", "body-weight", null); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void constructorShouldThrowExceptionOnInvalidSchemaVersion() { | ||
|
||
new FreeFormMeasure.Builder("omh", "body-weight", "%"); | ||
} | ||
|
||
@Test | ||
public void buildShouldConstructMeasureUsingOnlyRequiredProperties() { | ||
|
||
FreeFormMeasure measure = new FreeFormMeasure.Builder("omh", "body-weight", "1.0").build(); | ||
|
||
assertThat(measure, notNullValue()); | ||
assertThat(measure.getSchemaId(), equalTo(BodyWeight.SCHEMA_ID)); | ||
assertThat(measure.getEffectiveTimeFrame(), nullValue()); | ||
assertThat(measure.getDescriptiveStatistic(), nullValue()); | ||
assertThat(measure.getUserNotes(), nullValue()); | ||
} | ||
|
||
@Override | ||
protected String getSchemaFilename() { | ||
|
||
// the serialization tests will work with the body weight schema as a use case | ||
return BodyWeightUnitTests.SCHEMA_FILENAME; | ||
} | ||
|
||
@Test | ||
public void measureShouldSerializeCorrectly() throws Exception { | ||
|
||
FreeFormMeasure measure = new FreeFormMeasure.Builder("omh", "body-weight", "1.0").build(); | ||
|
||
measure.setAdditionalProperty("body_weight.value", 50L); | ||
measure.setAdditionalProperty("body_weight.unit", "kg"); | ||
measure.setAdditionalProperty("effective_time_frame.time_interval.start_date_time", "2015-10-01T00:00:00Z"); | ||
measure.setAdditionalProperty("effective_time_frame.time_interval.end_date_time", "2015-11-01T00:00:00Z"); | ||
measure.setAdditionalProperty("descriptive_statistic", "minimum"); | ||
|
||
String document = "{\n" + | ||
" \"body_weight\": {\n" + | ||
" \"value\": 50,\n" + | ||
" \"unit\": \"kg\"\n" + | ||
" },\n" + | ||
" \"effective_time_frame\": {\n" + | ||
" \"time_interval\": {\n" + | ||
" \"start_date_time\": \"2015-10-01T00:00:00Z\",\n" + | ||
" \"end_date_time\": \"2015-11-01T00:00:00Z\"\n" + | ||
" }\n" + | ||
" },\n" + | ||
" \"descriptive_statistic\": \"minimum\"\n" + | ||
"}"; | ||
|
||
serializationShouldCreateValidDocument(measure, document); | ||
} | ||
} |