From 71a4ad367f5e13945d2a6435769e637df2ecf0c5 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Wed, 16 Dec 2015 16:27:37 -0700 Subject: [PATCH 01/18] Simplify Google Fit mapper tests --- ...adayStepCountDataPointMapperUnitTests.java | 3 +- .../common/GoogleFitTestProperties.java | 107 +++++++++++++ ...FitBodyHeightDataPointMapperUnitTests.java | 54 +++---- ...FitBodyWeightDataPointMapperUnitTests.java | 60 ++++---- ...aloriesBurnedDataPointMapperUnitTests.java | 54 +++---- .../GoogleFitDataPointMapperUnitTests.java | 141 +++++++++--------- ...eFitHeartRateDataPointMapperUnitTests.java | 38 ++--- ...sicalActivityDataPointMapperUnitTests.java | 68 ++++----- ...eFitStepCountDataPointMapperUnitTests.java | 45 +++--- 9 files changed, 333 insertions(+), 237 deletions(-) create mode 100644 shim-server/src/test/java/org/openmhealth/shim/googlefit/common/GoogleFitTestProperties.java diff --git a/shim-server/src/test/java/org/openmhealth/shim/fitbit/mapper/FitbitIntradayStepCountDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/fitbit/mapper/FitbitIntradayStepCountDataPointMapperUnitTests.java index 66adfc9f..1a56b3e0 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/fitbit/mapper/FitbitIntradayStepCountDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/fitbit/mapper/FitbitIntradayStepCountDataPointMapperUnitTests.java @@ -55,8 +55,7 @@ public void initializeResponseNode() throws IOException { @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(2)); + assertThat(mapper.asDataPoints(singletonList(responseNode)).size(), equalTo(2)); } @Test diff --git a/shim-server/src/test/java/org/openmhealth/shim/googlefit/common/GoogleFitTestProperties.java b/shim-server/src/test/java/org/openmhealth/shim/googlefit/common/GoogleFitTestProperties.java new file mode 100644 index 00000000..739ba8a8 --- /dev/null +++ b/shim-server/src/test/java/org/openmhealth/shim/googlefit/common/GoogleFitTestProperties.java @@ -0,0 +1,107 @@ +/* + * 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.shim.googlefit.common; + +import org.openmhealth.schema.domain.omh.DataPointModality; +import org.openmhealth.schema.domain.omh.SchemaId; + +import java.util.Optional; + + +/** + * @author Chris Schaefbauer + */ +public class GoogleFitTestProperties { + + private String startDateTime; + private String endDateTime; + private String sourceOriginId; + private double fpValue; + private DataPointModality modality; + private String stringValue; + private long intValue; + private SchemaId bodySchemaId; + + public void addFloatingPointProperty(double fpVal) { + + fpValue = fpVal; + } + + public String getSourceOriginId() { + + return sourceOriginId; + } + + public Optional getModality() { + + return Optional.ofNullable(modality); + } + + public void setModality(DataPointModality modality) { + this.modality = modality; + } + + public double getFpValue() { + return fpValue; + } + + public Optional getEndDateTime() { + + return Optional.ofNullable(endDateTime); + } + + public Optional getStartDateTime() { + + return Optional.ofNullable(startDateTime); + } + + public String getStringValue() { + return stringValue; + } + + public void setStringValue(String stringValue) { + this.stringValue = stringValue; + } + + public void setStartDateTime(String startDateTime) { + this.startDateTime = startDateTime; + } + + public void setEndDateTime(String endDateTime) { + this.endDateTime = endDateTime; + } + + public void setSourceOriginId(String sourceOriginId) { + this.sourceOriginId = sourceOriginId; + } + + public void setIntValue(long integerValue) { + this.intValue = integerValue; + } + + public long getIntValue() { + return intValue; + } + + public SchemaId getBodySchemaId() { + return bodySchemaId; + } + + public void setBodySchemaId(SchemaId bodySchemaId) { + this.bodySchemaId = bodySchemaId; + } +} diff --git a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitBodyHeightDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitBodyHeightDataPointMapperUnitTests.java index 2741e20e..4263cf1b 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitBodyHeightDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitBodyHeightDataPointMapperUnitTests.java @@ -3,18 +3,16 @@ import org.openmhealth.schema.domain.omh.BodyHeight; import org.openmhealth.schema.domain.omh.DataPoint; import org.openmhealth.schema.domain.omh.LengthUnitValue; -import org.openmhealth.schema.domain.omh.TimeInterval; -import org.testng.annotations.BeforeTest; +import org.openmhealth.shim.googlefit.common.GoogleFitTestProperties; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.IOException; -import java.time.OffsetDateTime; import java.util.List; -import java.util.Map; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +import static org.openmhealth.schema.domain.omh.BodyHeight.*; import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; import static org.openmhealth.schema.domain.omh.LengthUnit.METER; @@ -24,10 +22,10 @@ */ public class GoogleFitBodyHeightDataPointMapperUnitTests extends GoogleFitDataPointMapperUnitTests { - private GoogleFitBodyHeightDataPointMapper mapper = new GoogleFitBodyHeightDataPointMapper(); + private final GoogleFitBodyHeightDataPointMapper mapper = new GoogleFitBodyHeightDataPointMapper(); - @BeforeTest + @BeforeClass @Override public void initializeResponseNode() throws IOException { @@ -37,54 +35,46 @@ public void initializeResponseNode() throws IOException { @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(2)); + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(2)); } @Test public void asDataPointsShouldReturnCorrectDataPointForSingleTimePoint() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - testGoogleFitDataPoint(dataPoints.get(0), + List> dataPoints = mapper.asDataPoints(responseNode); + + assertThatDataPointMatches(dataPoints.get(0), createFloatingPointTestProperties(1.8287990093231201, "2015-07-08T03:17:06.030Z", null, - "raw:com.google.height:com.google.android.apps.fitness:user_input")); + "raw:com.google.height:com.google.android.apps.fitness:user_input", SCHEMA_ID)); } @Test public void asDataPointsShouldReturnCorrectDataPointForTimeRange() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - testGoogleFitDataPoint(dataPoints.get(1), + List> dataPoints = mapper.asDataPoints(responseNode); + + assertThatDataPointMatches(dataPoints.get(1), createFloatingPointTestProperties(1.828800082206726, "2015-07-08T14:43:57.544Z", "2015-07-08T14:43:58.545Z", - "raw:com.google.height:com.google.android.apps.fitness:user_input")); + "raw:com.google.height:com.google.android.apps.fitness:user_input", SCHEMA_ID)); } @Test public void asDataPointsShouldReturnSelfReportedAsModalityWhenDataSourceContainsUserInput() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + DataPoint selfReportedDataPoint = mapper.asDataPoints(responseNode).get(1); - assertThat(dataPoints.get(1).getHeader().getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED)); + assertThat(selfReportedDataPoint.getHeader().getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED)); } - /* Helper methods */ - // TODO clean up @Override - public void testGoogleFitMeasureFromDataPoint(BodyHeight testMeasure, Map properties) { + public void assertThatMeasureMatches(BodyHeight testMeasure, GoogleFitTestProperties testProperties) { BodyHeight.Builder bodyHeightBuilder = - new BodyHeight.Builder(new LengthUnitValue(METER, (double) properties.get("fpValue"))); - if (properties.containsKey("endDateTimeString")) { - bodyHeightBuilder.setEffectiveTimeFrame(TimeInterval.ofStartDateTimeAndEndDateTime( - OffsetDateTime.parse((String) properties.get("startDateTimeString")), - OffsetDateTime.parse((String) properties.get("endDateTimeString")))); - } - else { - bodyHeightBuilder - .setEffectiveTimeFrame(OffsetDateTime.parse((String) properties.get("startDateTimeString"))); - } - BodyHeight expectedBodyHeight = bodyHeightBuilder.build(); - assertThat(testMeasure, equalTo(expectedBodyHeight)); + new BodyHeight.Builder(new LengthUnitValue(METER, testProperties.getFpValue())); + + setExpectedEffectiveTimeFrame(bodyHeightBuilder, testProperties); + + assertThat(testMeasure, equalTo(bodyHeightBuilder.build())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitBodyWeightDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitBodyWeightDataPointMapperUnitTests.java index 93512e86..0ad12709 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitBodyWeightDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitBodyWeightDataPointMapperUnitTests.java @@ -2,20 +2,20 @@ import org.openmhealth.schema.domain.omh.BodyWeight; import org.openmhealth.schema.domain.omh.DataPoint; -import org.openmhealth.schema.domain.omh.MassUnit; import org.openmhealth.schema.domain.omh.MassUnitValue; -import org.testng.annotations.BeforeTest; +import org.openmhealth.shim.googlefit.common.GoogleFitTestProperties; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.IOException; import java.util.List; -import java.util.Map; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; +import static org.openmhealth.schema.domain.omh.BodyWeight.*; import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; +import static org.openmhealth.schema.domain.omh.MassUnit.KILOGRAM; /** @@ -23,10 +23,9 @@ */ public class GoogleFitBodyWeightDataPointMapperUnitTests extends GoogleFitDataPointMapperUnitTests { - private GoogleFitBodyWeightDataPointMapper mapper = new GoogleFitBodyWeightDataPointMapper(); + private final GoogleFitBodyWeightDataPointMapper mapper = new GoogleFitBodyWeightDataPointMapper(); - - @BeforeTest + @BeforeClass @Override public void initializeResponseNode() throws IOException { @@ -35,51 +34,54 @@ public void initializeResponseNode() throws IOException { @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(3)); + + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(3)); } @Test public void asDataPointsShouldReturnCorrectDataPointsForSingleTimePoint() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - testGoogleFitDataPoint(dataPoints.get(0), + List> dataPoints = mapper.asDataPoints(responseNode); + + assertThatDataPointMatches(dataPoints.get(0), createFloatingPointTestProperties(72.0999984741211, "2015-02-13T00:00:00Z", null, - "raw:com.google.weight:com.fatsecret.android:")); - testGoogleFitDataPoint(dataPoints.get(1), + "raw:com.google.weight:com.fatsecret.android:", SCHEMA_ID)); + + assertThatDataPointMatches(dataPoints.get(1), createFloatingPointTestProperties(72, "2015-02-17T16:57:13.313Z", null, - "raw:com.google.weight:com.wsl.noom:")); + "raw:com.google.weight:com.wsl.noom:", SCHEMA_ID)); } @Test public void asDataPointsShouldReturnCorrectDataPointsWithTimeRange() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - - testGoogleFitDataPoint(dataPoints.get(2), + assertThatDataPointMatches(mapper.asDataPoints(responseNode).get(2), createFloatingPointTestProperties(75.75070190429688, "2015-07-08T03:17:00Z", "2015-07-08T03:17:10.020Z", - "raw:com.google.weight:com.google.android.apps.fitness:user_input")); + "raw:com.google.weight:com.google.android.apps.fitness:user_input", SCHEMA_ID)); } @Test public void asDataPointsShouldReturnSelfReportedAsModalityWhenDataSourceContainsUserInput() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + assertThat(mapper.asDataPoints(responseNode).get(2).getHeader().getAcquisitionProvenance().getModality(), + equalTo(SELF_REPORTED)); + } - // TODO split - assertThat(dataPoints.get(2).getHeader().getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED)); - assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getModality(), nullValue()); + @Test + public void asDataPointsShouldReturnNoModalityWhenDataSourceDoesNotContainUserInput() { + assertThat(mapper.asDataPoints(responseNode).get(0).getHeader().getAcquisitionProvenance().getModality(), + nullValue()); } - /* Helper methods */ - // TODO clean up @Override - public void testGoogleFitMeasureFromDataPoint(BodyWeight testMeasure, Map properties) { + public void assertThatMeasureMatches(BodyWeight testMeasure, GoogleFitTestProperties testProperties) { + BodyWeight.Builder expectedBodyWeightBuilder = - new BodyWeight.Builder(new MassUnitValue(MassUnit.KILOGRAM, (Double) properties.get("fpValue"))); - setExpectedEffectiveTimeFrame(expectedBodyWeightBuilder, properties); - BodyWeight expectedBodyWeight = expectedBodyWeightBuilder.build(); - assertThat(testMeasure, equalTo(expectedBodyWeight)); + new BodyWeight.Builder(new MassUnitValue(KILOGRAM, testProperties.getFpValue())); + + setExpectedEffectiveTimeFrame(expectedBodyWeightBuilder, testProperties); + + assertThat(testMeasure, equalTo(expectedBodyWeightBuilder.build())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitCaloriesBurnedDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitCaloriesBurnedDataPointMapperUnitTests.java index 60a24b8b..7ba74e92 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitCaloriesBurnedDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitCaloriesBurnedDataPointMapperUnitTests.java @@ -1,17 +1,21 @@ package org.openmhealth.shim.googlefit.mapper; -import org.openmhealth.schema.domain.omh.*; -import org.testng.annotations.BeforeTest; +import org.openmhealth.schema.domain.omh.CaloriesBurned; +import org.openmhealth.schema.domain.omh.DataPoint; +import org.openmhealth.schema.domain.omh.KcalUnitValue; +import org.openmhealth.shim.googlefit.common.GoogleFitTestProperties; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.IOException; import java.util.List; -import java.util.Map; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; +import static org.openmhealth.schema.domain.omh.CaloriesBurned.*; +import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; /** @@ -19,9 +23,9 @@ */ public class GoogleFitCaloriesBurnedDataPointMapperUnitTests extends GoogleFitDataPointMapperUnitTests { - private GoogleFitCaloriesBurnedDataPointMapper mapper = new GoogleFitCaloriesBurnedDataPointMapper(); + private final GoogleFitCaloriesBurnedDataPointMapper mapper = new GoogleFitCaloriesBurnedDataPointMapper(); - @BeforeTest + @BeforeClass @Override public void initializeResponseNode() throws IOException { @@ -31,49 +35,49 @@ public void initializeResponseNode() throws IOException { @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - - assertThat(dataPoints.size(), equalTo(2)); + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(2)); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); - testGoogleFitDataPoint(dataPoints.get(0), + assertThatDataPointMatches(dataPoints.get(0), createFloatingPointTestProperties(200.0, "2015-07-07T13:30:00Z", "2015-07-07T14:00:00Z", - "raw:com.google.calories.expended:com.google.android.apps.fitness:user_input")); - testGoogleFitDataPoint(dataPoints.get(1), + "raw:com.google.calories.expended:com.google.android.apps.fitness:user_input", SCHEMA_ID)); + + assertThatDataPointMatches(dataPoints.get(1), createFloatingPointTestProperties(4.221510410308838, "2015-07-08T14:43:49.730Z", "2015-07-08T14:47:27.809Z", - "derived:com.google.calories.expended:com.google.android.gms:from_activities")); + "derived:com.google.calories.expended:com.google.android.gms:from_activities", SCHEMA_ID)); } @Test public void asDataPointsShouldReturnSelfReportedAsModalityWhenDataSourceContainsUserInput() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - - assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getModality(), - equalTo(DataPointModality.SELF_REPORTED)); + assertThat(mapper.asDataPoints(responseNode).get(0).getHeader().getAcquisitionProvenance().getModality(), + equalTo(SELF_REPORTED)); + } - assertThat(dataPoints.get(1).getHeader().getAcquisitionProvenance().getModality(), nullValue()); + @Test + public void asDataPointsShouldReturnNoModalityWhenDataSourceDoesNotContainUserInput() { + assertThat(mapper.asDataPoints(responseNode).get(1).getHeader().getAcquisitionProvenance().getModality(), + nullValue()); } - /* Helper methods */ @Override - public void testGoogleFitMeasureFromDataPoint(CaloriesBurned testMeasure, Map properties) { + public void assertThatMeasureMatches(CaloriesBurned testMeasure, GoogleFitTestProperties testProperties) { CaloriesBurned.Builder expectedCaloriesBurnedBuilder = - new CaloriesBurned.Builder(new KcalUnitValue(KcalUnit.KILOCALORIE, (double) properties.get("fpValue"))); - setExpectedEffectiveTimeFrame(expectedCaloriesBurnedBuilder, properties); + new CaloriesBurned.Builder( + new KcalUnitValue(KILOCALORIE, testProperties.getFpValue())); - CaloriesBurned expectedCaloriesBurned = expectedCaloriesBurnedBuilder.build(); + setExpectedEffectiveTimeFrame(expectedCaloriesBurnedBuilder, testProperties); - assertThat(testMeasure, equalTo(expectedCaloriesBurned)); + assertThat(testMeasure, equalTo(expectedCaloriesBurnedBuilder.build())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitDataPointMapperUnitTests.java index ffa13f2d..366e613f 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitDataPointMapperUnitTests.java @@ -1,18 +1,17 @@ package org.openmhealth.shim.googlefit.mapper; import com.fasterxml.jackson.databind.JsonNode; -import com.google.common.collect.Maps; import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; +import org.openmhealth.shim.googlefit.common.GoogleFitTestProperties; import java.io.IOException; import java.time.OffsetDateTime; -import java.util.HashMap; -import java.util.Map; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; +import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; import static org.openmhealth.shim.googlefit.mapper.GoogleFitDataPointMapper.RESOURCE_API_SOURCE_NAME; @@ -32,122 +31,124 @@ public abstract class GoogleFitDataPointMapperUnitTests exten * Implemented by measure specific test classes in order to test the {@link Measure} contained within the mapper * created {@link DataPoint}. Should contain the assertions needed to test the individual values in the measure. */ - public abstract void testGoogleFitMeasureFromDataPoint(T testMeasure, Map properties); + public abstract void assertThatMeasureMatches(T testMeasure, GoogleFitTestProperties testProperties); /** - * Used to test data points created through {@link Measure} specific Google Fit mappers. + * Used to test data points created through measure specific Google Fit mappers. * - * @param dataPoint datapoint created by the mapper - * @param properties a map containing different properties to test against the mapper generated datapoint, should - * contain keys that are used in this generic data point test as well as the mapper specific test + * @param dataPoint data point created by the mapper + * @param testProperties properties to test against the mapper generated data point */ - public void testGoogleFitDataPoint(DataPoint dataPoint, Map properties) { + public void assertThatDataPointMatches(DataPoint dataPoint, GoogleFitTestProperties testProperties) { - testGoogleFitMeasureFromDataPoint(dataPoint.getBody(), properties); + assertThatMeasureMatches(dataPoint.getBody(), testProperties); DataPointHeader dataPointHeader = dataPoint.getHeader(); assertThat(dataPointHeader.getAcquisitionProvenance().getSourceName(), equalTo(RESOURCE_API_SOURCE_NAME)); assertThat(dataPointHeader.getAcquisitionProvenance().getAdditionalProperties().get( - "source_origin_id"), equalTo(properties.get("sourceOriginId"))); + "source_origin_id"), equalTo(testProperties.getSourceOriginId())); - if (properties.containsKey("modality")) { - assertThat(dataPointHeader.getAcquisitionProvenance().getModality(), equalTo(properties.get("modality"))); + assertThat(dataPointHeader.getBodySchemaId(), equalTo(testProperties.getBodySchemaId())); + + if (testProperties.getModality().isPresent()) { + + assertThat(dataPointHeader.getAcquisitionProvenance().getModality(), + equalTo(testProperties.getModality().get())); } + else { - if (!properties.containsKey("modality")) { assertThat(dataPointHeader.getAcquisitionProvenance().getModality(), nullValue()); } - } /** - * Creates the properties map used for generating an expected values datapoint to test google fit data points - * against. - * - * @param fpValue a floating point value from a Google fit JSON test datapoint - * @param startDateTime a string containing the start timestamp in unix epoch nanoseconds - * @param endDateTime a string containing the end timestamp in unix epoch nanoseconds - * @param sourceOriginId a string containing the origin source id from the datapoint from the JSON test data - * @return a map with the properties needed to generate an expected datapoint to test a google fit datapoint + * Creates a test properties object used to generate an expected value data point to test google fit data points + * that use floating point values in their response. */ - public Map createFloatingPointTestProperties(double fpValue, String startDateTime, - String endDateTime, String sourceOriginId) { - Map properties = createTestProperties(startDateTime, endDateTime, sourceOriginId); - properties.put("fpValue", fpValue); - return properties; + public GoogleFitTestProperties createFloatingPointTestProperties(double fpValue, String startDateTime, + String endDateTime, String sourceOriginId, SchemaId schemaId) { + + GoogleFitTestProperties testProperties = + createTestProperties(startDateTime, endDateTime, sourceOriginId, schemaId); + + testProperties.addFloatingPointProperty(fpValue); + + return testProperties; } /** - * Creates the properties map used for generating an expected values datapoint to test google fit data points - * against. - * - * @param intValue an integer value from a Google fit JSON test datapoint - * @param startDateTime a string containing the start timestamp in unix epoch nanoseconds - * @param endDateTime a string containing the end timestamp in unix epoch nanoseconds - * @param sourceOriginId a string containing the origin source id from the datapoint from the JSON test data - * @return a map with the properties needed to generate an expected datapoint to test a google fit datapoint + * Creates a test properties object used to generate an expected value data point to test google fit data points + * that use integer values in their response. */ - public Map createIntegerTestProperties(long intValue, String startDateTime, String endDateTime, - String sourceOriginId) { + public GoogleFitTestProperties createIntegerTestProperties(long intValue, String startDateTime, String endDateTime, + String sourceOriginId, SchemaId schemaId) { + + GoogleFitTestProperties testProperties = + createTestProperties(startDateTime, endDateTime, sourceOriginId, schemaId); + + testProperties.setIntValue(intValue); - Map properties = createTestProperties(startDateTime, endDateTime, sourceOriginId); - properties.put("intValue", intValue); - return properties; + return testProperties; } /** - * Creates the properties map used for generating an expected values datapoint to test google fit data points - * against, used specifically for testing physical activity because it generates a string value as the activity - * type. - * - * @param stringValue an string value from a Google fit JSON test datapoint - * @param startDateTime a string containing the start timestamp in unix epoch nanoseconds - * @param endDateTime a string containing the end timestamp in unix epoch nanoseconds - * @param sourceOriginId a string containing the origin source id from the datapoint from the JSON test data - * @return a map with the properties needed to generate an expected datapoint to test a google fit datapoint + * Creates a test properties object used to generate an expected value data point to test google fit data points + * that use strings to represent values. */ - public Map createStringTestProperties(String stringValue, String startDateTime, String endDateTime, - String sourceOriginId) { + public GoogleFitTestProperties createStringTestProperties(String stringValue, String startDateTime, + String endDateTime, + String sourceOriginId, + SchemaId schemaId) { + + GoogleFitTestProperties testProperties = + createTestProperties(startDateTime, endDateTime, sourceOriginId, schemaId); + + testProperties.setStringValue(stringValue); - Map properties = createTestProperties(startDateTime, endDateTime, sourceOriginId); - properties.put("stringValue", stringValue); - return properties; + return testProperties; } - private Map createTestProperties(String startDateTimeString, String endDateTimeString, - String sourceOriginId) { + private GoogleFitTestProperties createTestProperties(String startDateTimeString, String endDateTimeString, + String sourceOriginId, SchemaId schemaId) { + + GoogleFitTestProperties testProperties = new GoogleFitTestProperties(); - HashMap properties = Maps.newHashMap(); if (startDateTimeString != null) { - properties.put("startDateTimeString", startDateTimeString); + testProperties.setStartDateTime(startDateTimeString); } + if (endDateTimeString != null) { - properties.put("endDateTimeString", endDateTimeString); + testProperties.setEndDateTime(endDateTimeString); } + if (sourceOriginId != null) { - properties.put("sourceOriginId", sourceOriginId); + + testProperties.setSourceOriginId(sourceOriginId); + if (sourceOriginId.endsWith("user_input")) { - properties.put("modality", DataPointModality.SELF_REPORTED); + testProperties.setModality(SELF_REPORTED); } } - return properties; + testProperties.setBodySchemaId(schemaId); + + return testProperties; } /** - * Sets the effective time frame for a datapoint builder given a map of properties that contains the key - * "startDateTimeString" and optionally, "endDateTimeString". + * Sets the effective time frame for a data point builder given a {@link GoogleFitTestProperties} object. */ - public void setExpectedEffectiveTimeFrame(T.Builder builder, Map properties) { + public void setExpectedEffectiveTimeFrame(T.Builder builder, GoogleFitTestProperties testProperties) { + + if (testProperties.getEndDateTime().isPresent()) { - if (properties.containsKey("endDateTimeString")) { builder.setEffectiveTimeFrame(TimeInterval.ofStartDateTimeAndEndDateTime( - OffsetDateTime.parse((String) properties.get("startDateTimeString")), - OffsetDateTime.parse((String) properties.get("endDateTimeString")))); + OffsetDateTime.parse(testProperties.getStartDateTime().get()), + OffsetDateTime.parse(testProperties.getEndDateTime().get()))); } else { - builder.setEffectiveTimeFrame(OffsetDateTime.parse((String) properties.get("startDateTimeString"))); + builder.setEffectiveTimeFrame(OffsetDateTime.parse(testProperties.getStartDateTime().get())); } } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitHeartRateDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitHeartRateDataPointMapperUnitTests.java index 0f009fb9..51092513 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitHeartRateDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitHeartRateDataPointMapperUnitTests.java @@ -1,17 +1,15 @@ package org.openmhealth.shim.googlefit.mapper; -import org.openmhealth.schema.domain.omh.DataPoint; import org.openmhealth.schema.domain.omh.HeartRate; -import org.testng.annotations.BeforeTest; +import org.openmhealth.shim.googlefit.common.GoogleFitTestProperties; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.IOException; -import java.util.List; -import java.util.Map; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +import static org.openmhealth.schema.domain.omh.HeartRate.SCHEMA_ID; /** @@ -19,10 +17,9 @@ */ public class GoogleFitHeartRateDataPointMapperUnitTests extends GoogleFitDataPointMapperUnitTests { - private GoogleFitHeartRateDataPointMapper mapper = new GoogleFitHeartRateDataPointMapper(); + private final GoogleFitHeartRateDataPointMapper mapper = new GoogleFitHeartRateDataPointMapper(); - - @BeforeTest + @BeforeClass @Override public void initializeResponseNode() throws IOException { @@ -32,37 +29,32 @@ public void initializeResponseNode() throws IOException { @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(2)); + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(2)); } @Test public void asDataPointsShouldReturnCorrectDataPointsForSingleTimePoint() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - testGoogleFitDataPoint(dataPoints.get(0), + assertThatDataPointMatches(mapper.asDataPoints(responseNode).get(0), createFloatingPointTestProperties(54, "2015-01-30T15:37:48.186Z", null, - "raw:com.google.heart_rate.bpm:com.azumio.instantheartrate.full:")); + "raw:com.google.heart_rate.bpm:com.azumio.instantheartrate.full:", SCHEMA_ID)); } @Test public void asDataPointsShouldReturnCorrectDataPointsForTimeRange() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - testGoogleFitDataPoint(dataPoints.get(1), + assertThatDataPointMatches(mapper.asDataPoints(responseNode).get(1), createFloatingPointTestProperties(58.0, "2015-07-10T14:34:32.914Z", "2015-07-10T14:34:33.915Z", - "raw:com.google.heart_rate.bpm:si.modula.android.instantheartrate:")); + "raw:com.google.heart_rate.bpm:si.modula.android.instantheartrate:", SCHEMA_ID)); } - /* Helper methods */ - // TODO clean up @Override - public void testGoogleFitMeasureFromDataPoint(HeartRate testMeasure, Map properties) { + public void assertThatMeasureMatches(HeartRate testMeasure, GoogleFitTestProperties testProperties) { + + HeartRate.Builder expectedHeartRateBuilder = new HeartRate.Builder(testProperties.getFpValue()); - HeartRate.Builder expectedHeartRateBuilder = new HeartRate.Builder((double) properties.get("fpValue")); - setExpectedEffectiveTimeFrame(expectedHeartRateBuilder, properties); - HeartRate expectedHeartRate = expectedHeartRateBuilder.build(); + setExpectedEffectiveTimeFrame(expectedHeartRateBuilder, testProperties); - assertThat(testMeasure, equalTo(expectedHeartRate)); + assertThat(testMeasure, equalTo(expectedHeartRateBuilder.build())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitPhysicalActivityDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitPhysicalActivityDataPointMapperUnitTests.java index 42732a2f..9837ac35 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitPhysicalActivityDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitPhysicalActivityDataPointMapperUnitTests.java @@ -2,19 +2,18 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.DataPoint; -import org.openmhealth.schema.domain.omh.DataPointModality; import org.openmhealth.schema.domain.omh.PhysicalActivity; -import org.testng.annotations.BeforeTest; +import org.openmhealth.shim.googlefit.common.GoogleFitTestProperties; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.IOException; import java.util.List; -import java.util.Map; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.*; +import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; +import static org.openmhealth.schema.domain.omh.PhysicalActivity.SCHEMA_ID; /** @@ -23,55 +22,57 @@ public class GoogleFitPhysicalActivityDataPointMapperUnitTests extends GoogleFitDataPointMapperUnitTests { - private GoogleFitPhysicalActivityDataPointMapper mapper = new GoogleFitPhysicalActivityDataPointMapper(); - protected JsonNode sleepActivityNode; + private final GoogleFitPhysicalActivityDataPointMapper mapper = new GoogleFitPhysicalActivityDataPointMapper(); - @BeforeTest + @BeforeClass @Override public void initializeResponseNode() throws IOException { responseNode = asJsonNode("org/openmhealth/shim/googlefit/mapper/googlefit-merge-activity-segments.json"); - sleepActivityNode = - asJsonNode("org/openmhealth/shim/googlefit/mapper/googlefit-merge-activity-segments-only-sleep.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(3)); + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(3)); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - testGoogleFitDataPoint(dataPoints.get(0), + List> dataPoints = mapper.asDataPoints(responseNode); + + assertThatDataPointMatches(dataPoints.get(0), createStringTestProperties("Walking", "2015-01-01T22:21:57Z", "2015-01-01T23:29:49Z", - "derived:com.google.activity.segment:com.strava:session_activity_segment")); - testGoogleFitDataPoint(dataPoints.get(1), - createStringTestProperties("Aerobics", "2015-01-05T00:27:29.151Z", "2015-01-05T00:30:41.151Z", - "derived:com.google.activity.segment:com.mapmyrun.android2:session_activity_segment")); + "derived:com.google.activity.segment:com.strava:session_activity_segment", SCHEMA_ID)); + assertThatDataPointMatches(dataPoints.get(1), + createStringTestProperties("Aerobics", "2015-01-05T00:27:29.151Z", "2015-01-05T00:30:41.151Z", + "derived:com.google.activity.segment:com.mapmyrun.android2:session_activity_segment", + SCHEMA_ID)); } @Test public void asDataPointsShouldReturnSelfReportedAsModalityWhenDataSourceContainsUserInput() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - - assertThat(dataPoints.get(2).getHeader().getAcquisitionProvenance().getModality(), - equalTo(DataPointModality.SELF_REPORTED)); + assertThat(mapper.asDataPoints(responseNode).get(2).getHeader().getAcquisitionProvenance().getModality(), + equalTo(SELF_REPORTED)); + } - assertThat(dataPoints.get(1).getHeader().getAcquisitionProvenance().getModality(), nullValue()); + @Test + public void asDataPointsShouldReturnNoModalityWhenDataSourceDoesNotContainUserInput() { + assertThat(mapper.asDataPoints(responseNode).get(1).getHeader().getAcquisitionProvenance().getModality(), + nullValue()); } @Test public void asDataPointsShouldNotReturnDataPointsForSleepActivityType() { - List> dataPoints = mapper.asDataPoints(singletonList(sleepActivityNode)); - assertThat(dataPoints.size(), equalTo(0)); + JsonNode sleepActivityNode = + asJsonNode("org/openmhealth/shim/googlefit/mapper/googlefit-merge-activity-segments-only-sleep.json"); + + assertThat(mapper.asDataPoints(sleepActivityNode), is(empty())); } @Test @@ -81,20 +82,17 @@ public void asDataPointsShouldNotReturnDataPointsForStationaryActivityTypes() th "org/openmhealth/shim/googlefit/mapper/googlefit-merge-activity-segments-only-stationary-activity" + ".json"); - List> dataPoints = mapper.asDataPoints(singletonList(stationaryActivityNode)); - assertThat(dataPoints.size(), equalTo(0)); + assertThat(mapper.asDataPoints(stationaryActivityNode), is(empty())); } - /* Helper methods */ - @Override - public void testGoogleFitMeasureFromDataPoint(PhysicalActivity testMeasure, Map properties) { + public void assertThatMeasureMatches(PhysicalActivity testMeasure, GoogleFitTestProperties testProperties) { PhysicalActivity.Builder physicalActivityBuilder = - new PhysicalActivity.Builder((String) properties.get("stringValue")); - setExpectedEffectiveTimeFrame(physicalActivityBuilder, properties); - PhysicalActivity expectedPhysicalActivity = physicalActivityBuilder.build(); + new PhysicalActivity.Builder(testProperties.getStringValue()); + + setExpectedEffectiveTimeFrame(physicalActivityBuilder, testProperties); - assertThat(testMeasure, equalTo(expectedPhysicalActivity)); + assertThat(testMeasure, equalTo(physicalActivityBuilder.build())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitStepCountDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitStepCountDataPointMapperUnitTests.java index d3001bdc..bf69cd60 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitStepCountDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/googlefit/mapper/GoogleFitStepCountDataPointMapperUnitTests.java @@ -2,19 +2,22 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.DataPoint; -import org.openmhealth.schema.domain.omh.DataPointModality; import org.openmhealth.schema.domain.omh.StepCount; -import org.testng.annotations.BeforeTest; +import org.openmhealth.shim.googlefit.common.GoogleFitTestProperties; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.IOException; import java.util.List; -import java.util.Map; import static java.util.Collections.singletonList; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.collection.IsEmptyCollection.empty; +import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; +import static org.openmhealth.schema.domain.omh.StepCount.SCHEMA_ID; /** @@ -22,35 +25,34 @@ */ public class GoogleFitStepCountDataPointMapperUnitTests extends GoogleFitDataPointMapperUnitTests { - private GoogleFitStepCountDataPointMapper mapper = new GoogleFitStepCountDataPointMapper(); - JsonNode emptyNode; + private final GoogleFitStepCountDataPointMapper mapper = new GoogleFitStepCountDataPointMapper(); - @BeforeTest + @BeforeClass @Override public void initializeResponseNode() throws IOException { responseNode = asJsonNode("org/openmhealth/shim/googlefit/mapper/googlefit-merge-step-deltas.json"); - emptyNode = asJsonNode("org/openmhealth/shim/googlefit/mapper/googlefit-empty.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(3)); + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(3)); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - testGoogleFitDataPoint(dataPoints.get(0), + + assertThatDataPointMatches(dataPoints.get(0), createIntegerTestProperties(4146, "2015-02-02T22:49:39.811Z", "2015-02-02T23:25:20.811Z", - "derived:com.google.step_count.delta:com.nike.plusgps:")); - testGoogleFitDataPoint(dataPoints.get(1), + "derived:com.google.step_count.delta:com.nike.plusgps:", SCHEMA_ID)); + + assertThatDataPointMatches(dataPoints.get(1), createIntegerTestProperties(17, "2015-07-10T21:58:17.687316406Z", "2015-07-10T21:59:17.687316406Z", "derived:com.google.step_count.cumulative:com.google.android.gms:samsung:Galaxy " + - "Nexus:32b1bd9e:soft_step_counter")); + "Nexus:32b1bd9e:soft_step_counter", SCHEMA_ID)); } @Test @@ -59,7 +61,7 @@ public void asDataPointsShouldReturnSelfReportedAsModalityWhenDataSourceContains List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); assertThat(dataPoints.get(2).getHeader().getAcquisitionProvenance().getModality(), - equalTo(DataPointModality.SELF_REPORTED)); + equalTo(SELF_REPORTED)); assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getModality(), nullValue()); @@ -68,19 +70,20 @@ public void asDataPointsShouldReturnSelfReportedAsModalityWhenDataSourceContains @Test public void asDataPointsShouldReturnZeroDataPointsWithEmptyData() { - List> dataPoints = mapper.asDataPoints(singletonList(emptyNode)); - assertThat(dataPoints.size(), equalTo(0)); + JsonNode emptyNode = asJsonNode("org/openmhealth/shim/googlefit/mapper/googlefit-empty.json"); + + assertThat(mapper.asDataPoints(emptyNode), is(empty())); } /* Helper methods */ @Override - public void testGoogleFitMeasureFromDataPoint(StepCount testMeasure, Map properties) { + public void assertThatMeasureMatches(StepCount testMeasure, GoogleFitTestProperties testProperties) { + + StepCount.Builder expectedStepCountBuilder = new StepCount.Builder(testProperties.getIntValue()); - StepCount.Builder expectedStepCountBuilder = new StepCount.Builder((long) properties.get("intValue")); - setExpectedEffectiveTimeFrame(expectedStepCountBuilder, properties); - StepCount expectedStepCount = expectedStepCountBuilder.build(); + setExpectedEffectiveTimeFrame(expectedStepCountBuilder, testProperties); - assertThat(testMeasure, equalTo(expectedStepCount)); + assertThat(testMeasure, equalTo(expectedStepCountBuilder.build())); } } From f925199361bbc3b1333d71cc5a4a2c1c8ff9eeb8 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Tue, 22 Dec 2015 14:37:14 -0700 Subject: [PATCH 02/18] Simplify iHealth mapper tests --- ...hBloodGlucoseDataPointMapperUnitTests.java | 23 ++++----- ...ointHeartRateDataPointMapperUnitTests.java | 33 ++++++------ ...BloodPressureDataPointMapperUnitTests.java | 11 ++-- ...ointHeartRateDataPointMapperUnitTests.java | 24 ++++----- ...BodyMassIndexDataPointMapperUnitTests.java | 25 ++++----- ...lthBodyWeightDataPointMapperUnitTests.java | 39 +++++++------- ...sicalActivityDataPointMapperUnitTests.java | 7 ++- ...SleepDurationDataPointMapperUnitTests.java | 41 +++++++-------- ...althStepCountDataPointMapperUnitTests.java | 51 ++++++++++--------- 9 files changed, 127 insertions(+), 127 deletions(-) diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodGlucoseDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodGlucoseDataPointMapperUnitTests.java index d85ae1c1..5f5487f6 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodGlucoseDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodGlucoseDataPointMapperUnitTests.java @@ -20,15 +20,14 @@ import org.openmhealth.schema.domain.omh.BloodGlucose; import org.openmhealth.schema.domain.omh.DataPoint; import org.openmhealth.schema.domain.omh.TypedUnitValue; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.io.IOException; import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -48,10 +47,10 @@ public class IHealthBloodGlucoseDataPointMapperUnitTests extends IHealthDataPointMapperUnitTests { private JsonNode responseNode; - private IHealthBloodGlucoseDataPointMapper mapper = new IHealthBloodGlucoseDataPointMapper(); - List> dataPoints; + private final IHealthBloodGlucoseDataPointMapper mapper = new IHealthBloodGlucoseDataPointMapper(); + private List> dataPoints; - @BeforeTest + @BeforeClass public void initializeResponseNode() throws IOException { responseNode = asJsonNode("/org/openmhealth/shim/ihealth/mapper/ihealth-glucose.json"); @@ -60,7 +59,7 @@ public void initializeResponseNode() throws IOException { @BeforeMethod public void initializeDataPoints() { - dataPoints = mapper.asDataPoints(singletonList(responseNode)); + dataPoints = mapper.asDataPoints(responseNode); } @Test @@ -90,12 +89,12 @@ public void asDataPointsShouldReturnCorrectSensedDataPoints() { @Test public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() { - BloodGlucose.Builder expectedBloodGlucoseBuilder = - new BloodGlucose.Builder(new TypedUnitValue<>(MILLIGRAMS_PER_DECILITER, 70)) - .setTemporalRelationshipToMeal(AFTER_BREAKFAST) - .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-24T14:44:40-06:00")); + BloodGlucose expectedBloodGlucose = new BloodGlucose.Builder(new TypedUnitValue<>(MILLIGRAMS_PER_DECILITER, 70)) + .setTemporalRelationshipToMeal(AFTER_BREAKFAST) + .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-24T14:44:40-06:00")) + .build(); - assertThat(dataPoints.get(1).getBody(), equalTo(expectedBloodGlucoseBuilder.build())); + assertThat(dataPoints.get(1).getBody(), equalTo(expectedBloodGlucose)); assertThat(dataPoints.get(1).getBody().getAdditionalProperty("temporal_relationship_to_medication").get(), equalTo("After_taking_pills")); @@ -108,7 +107,7 @@ public void asDataPointsShouldReturnNoDataPointsWhenBloodGlucoseListIsEmpty() th JsonNode emptyListResponseNode = asJsonNode("/org/openmhealth/shim/ihealth/mapper/ihealth-glucose-empty.json"); - assertThat(mapper.asDataPoints(singletonList(emptyListResponseNode)), is(empty())); + assertThat(mapper.asDataPoints(emptyListResponseNode), is(empty())); } @Test diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenEndpointHeartRateDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenEndpointHeartRateDataPointMapperUnitTests.java index b7624aa3..4a587bb8 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenEndpointHeartRateDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenEndpointHeartRateDataPointMapperUnitTests.java @@ -19,21 +19,20 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.DataPoint; import org.openmhealth.schema.domain.omh.HeartRate; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.io.IOException; import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; -import static org.openmhealth.schema.domain.omh.HeartRate.*; +import static org.openmhealth.schema.domain.omh.HeartRate.SCHEMA_ID; /** @@ -41,14 +40,14 @@ */ public class IHealthBloodOxygenEndpointHeartRateDataPointMapperUnitTests extends IHealthDataPointMapperUnitTests { - JsonNode responseNode; + private JsonNode responseNode; - private IHealthBloodOxygenEndpointHeartRateDataPointMapper mapper = + private final IHealthBloodOxygenEndpointHeartRateDataPointMapper mapper = new IHealthBloodOxygenEndpointHeartRateDataPointMapper(); - List> dataPoints; + private List> dataPoints; - @BeforeTest + @BeforeClass public void initializeResponseNode() throws IOException { responseNode = asJsonNode("/org/openmhealth/shim/ihealth/mapper/ihealth-spo2.json"); @@ -57,7 +56,7 @@ public void initializeResponseNode() throws IOException { @BeforeMethod public void initializeDataPoints() { - dataPoints = mapper.asDataPoints(singletonList(responseNode)); + dataPoints = mapper.asDataPoints(responseNode); } @Test @@ -69,10 +68,11 @@ public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { @Test public void asDataPointsShouldReturnCorrectSensedDataPoints() { - HeartRate.Builder expectedHeartRateBuilder = new HeartRate.Builder(80) - .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-23T15:46:00-06:00")); + HeartRate expectedHeartRate = new HeartRate.Builder(80) + .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-23T15:46:00-06:00")) + .build(); - assertThat(dataPoints.get(0).getBody(), equalTo(expectedHeartRateBuilder.build())); + assertThat(dataPoints.get(0).getBody(), equalTo(expectedHeartRate)); testDataPointHeader(dataPoints.get(0).getHeader(), SCHEMA_ID, SENSED, "d7fb9db14b0fc3e8e1635720c28bda64", OffsetDateTime.parse("2015-09-23T21:46:00Z")); @@ -81,11 +81,12 @@ public void asDataPointsShouldReturnCorrectSensedDataPoints() { @Test public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() { - HeartRate.Builder expectedHeartRateBuilder = new HeartRate.Builder(65) + HeartRate expectedHeartRate = new HeartRate.Builder(65) .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-24T15:03:00-06:00")) - .setUserNotes("Satch on satch "); + .setUserNotes("Satch on satch ") + .build(); - assertThat(dataPoints.get(1).getBody(), equalTo(expectedHeartRateBuilder.build())); + assertThat(dataPoints.get(1).getBody(), equalTo(expectedHeartRate)); assertThat(dataPoints.get(1).getHeader().getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED)); } @@ -103,7 +104,7 @@ public void asDataPointsShouldReturnNoDataPointWhenHeartRateDataIsNotPresent() t JsonNode noHeartRateBloodOxygenNode = asJsonNode( "org/openmhealth/shim/ihealth/mapper/ihealth-spo2-no-heart-rate.json"); - assertThat(mapper.asDataPoints(singletonList(noHeartRateBloodOxygenNode)), is(empty())); + assertThat(mapper.asDataPoints(noHeartRateBloodOxygenNode), is(empty())); } @Test @@ -111,7 +112,7 @@ public void asDataPointsShouldReturnEmptyListWhenEmptyIHealthResponse() { JsonNode emptyNode = asJsonNode("/org/openmhealth/shim/ihealth/mapper/ihealth-spo2-empty.json"); - assertThat(mapper.asDataPoints(singletonList(emptyNode)), is(empty())); + assertThat(mapper.asDataPoints(emptyNode), is(empty())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodPressureDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodPressureDataPointMapperUnitTests.java index 28cc30e2..a0cb2cd8 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodPressureDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodPressureDataPointMapperUnitTests.java @@ -26,12 +26,11 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; -import static org.openmhealth.schema.domain.omh.BloodPressure.*; -import static org.openmhealth.schema.domain.omh.BloodPressureUnit.*; +import static org.openmhealth.schema.domain.omh.BloodPressure.SCHEMA_ID; +import static org.openmhealth.schema.domain.omh.BloodPressureUnit.MM_OF_MERCURY; import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; @@ -43,7 +42,7 @@ public class IHealthBloodPressureDataPointMapperUnitTests extends IHealthDataPoi private JsonNode responseNode; private IHealthBloodPressureDataPointMapper mapper = new IHealthBloodPressureDataPointMapper(); - List> dataPoints; + private List> dataPoints; @BeforeTest public void initializeResponseNode() throws IOException { @@ -54,7 +53,7 @@ public void initializeResponseNode() throws IOException { @BeforeMethod public void initializeDataPoints() { - dataPoints = mapper.asDataPoints(singletonList(responseNode)); + dataPoints = mapper.asDataPoints(responseNode); } @Test @@ -111,7 +110,7 @@ public void asDataPointsShouldReturnEmptyListWhenEmptyIHealthResponse() { JsonNode emptyNode = asJsonNode("org/openmhealth/shim/ihealth/mapper/ihealth-bp-empty.json"); - assertThat(mapper.asDataPoints(singletonList(emptyNode)), is(empty())); + assertThat(mapper.asDataPoints(emptyNode), is(empty())); } @Test diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodPressureEndpointHeartRateDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodPressureEndpointHeartRateDataPointMapperUnitTests.java index a009468d..eb4a303d 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodPressureEndpointHeartRateDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodPressureEndpointHeartRateDataPointMapperUnitTests.java @@ -20,15 +20,14 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.DataPoint; import org.openmhealth.schema.domain.omh.HeartRate; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.io.IOException; import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsEmptyCollection.empty; @@ -42,14 +41,14 @@ */ public class IHealthBloodPressureEndpointHeartRateDataPointMapperUnitTests extends IHealthDataPointMapperUnitTests { - JsonNode responseNode; + private JsonNode responseNode; - private IHealthBloodPressureEndpointHeartRateDataPointMapper mapper = + private final IHealthBloodPressureEndpointHeartRateDataPointMapper mapper = new IHealthBloodPressureEndpointHeartRateDataPointMapper(); - List> dataPoints; + private List> dataPoints; - @BeforeTest + @BeforeClass public void initializeResponseNodes() throws IOException { responseNode = asJsonNode("/org/openmhealth/shim/ihealth/mapper/ihealth-bp.json"); @@ -58,7 +57,7 @@ public void initializeResponseNodes() throws IOException { @BeforeMethod public void initializeDataPoints() { - dataPoints = mapper.asDataPoints(singletonList(responseNode)); + dataPoints = mapper.asDataPoints(responseNode); } @@ -71,10 +70,11 @@ public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { @Test public void asDataPointsShouldReturnCorrectSensedDataPoints() { - HeartRate.Builder expectedHeartRateBuilder = new HeartRate.Builder(100) - .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T12:04:23-08:00")); - HeartRate expectedSensedHeartRate = expectedHeartRateBuilder.build(); - assertThat(dataPoints.get(0).getBody(), equalTo(expectedSensedHeartRate)); + HeartRate expectedHeartRate = new HeartRate.Builder(100) + .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T12:04:23-08:00")) + .build(); + + assertThat(dataPoints.get(0).getBody(), equalTo(expectedHeartRate)); testDataPointHeader(dataPoints.get(0).getHeader(), SCHEMA_ID, SENSED, "c62b84d9d4b7480a8ff2aef1465aa454", OffsetDateTime.parse("2015-09-17T20:04:30Z")); @@ -105,6 +105,6 @@ public void asDataPointsShouldReturnNoDataPointWhenHeartRateDataIsNotPresent() t JsonNode noHeartRateBloodPressureNode = asJsonNode( "org/openmhealth/shim/ihealth/mapper/ihealth-bp-no-heart-rate.json"); - assertThat(mapper.asDataPoints(singletonList(noHeartRateBloodPressureNode)), is(empty())); + assertThat(mapper.asDataPoints(noHeartRateBloodPressureNode), is(empty())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBodyMassIndexDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBodyMassIndexDataPointMapperUnitTests.java index 9ce62583..03be6612 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBodyMassIndexDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBodyMassIndexDataPointMapperUnitTests.java @@ -28,7 +28,6 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -45,8 +44,8 @@ public class IHealthBodyMassIndexDataPointMapperUnitTests extends IHealthDataPointMapperUnitTests { private JsonNode responseNode; - private IHealthBodyMassIndexDataPointMapper mapper = new IHealthBodyMassIndexDataPointMapper(); - List> dataPoints; + private final IHealthBodyMassIndexDataPointMapper mapper = new IHealthBodyMassIndexDataPointMapper(); + private List> dataPoints; @BeforeTest public void initializeResponse() throws IOException { @@ -57,7 +56,7 @@ public void initializeResponse() throws IOException { @BeforeMethod public void initializeDataPoints() { - dataPoints = mapper.asDataPoints(singletonList(responseNode)); + dataPoints = mapper.asDataPoints(responseNode); } @Test @@ -69,11 +68,12 @@ public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { @Test public void asDataPointsShouldReturnCorrectSensedDataPoints() { - BodyMassIndex.Builder expectedBodyMassIndexBuilder = new BodyMassIndex.Builder(new TypedUnitValue<>( + BodyMassIndex expectedBodyMassIndex = new BodyMassIndex.Builder(new TypedUnitValue<>( KILOGRAMS_PER_SQUARE_METER, 22.56052563257619)) - .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T12:04:09-08:00")); + .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T12:04:09-08:00")) + .build(); - assertThat(dataPoints.get(0).getBody(), equalTo(expectedBodyMassIndexBuilder.build())); + assertThat(dataPoints.get(0).getBody(), equalTo(expectedBodyMassIndex)); testDataPointHeader(dataPoints.get(0).getHeader(), SCHEMA_ID, SENSED, "5fe5893c418b48cd8da7954f8b6c2f36", OffsetDateTime.parse("2015-09-17T20:04:17Z")); @@ -82,12 +82,13 @@ public void asDataPointsShouldReturnCorrectSensedDataPoints() { @Test public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() { - BodyMassIndex.Builder expectedBodyMassIndexBuilder = new BodyMassIndex.Builder( + BodyMassIndex expectedBodyMassIndex = new BodyMassIndex.Builder( new TypedUnitValue<>(KILOGRAMS_PER_SQUARE_METER, 22.56052398681641)) .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T14:07:57-06:00")) - .setUserNotes("Weight so good, look at me now"); + .setUserNotes("Weight so good, look at me now") + .build(); - assertThat(dataPoints.get(1).getBody(), equalTo(expectedBodyMassIndexBuilder.build())); + assertThat(dataPoints.get(1).getBody(), equalTo(expectedBodyMassIndex)); testDataPointHeader(dataPoints.get(1).getHeader(), SCHEMA_ID, SELF_REPORTED, "b702a3a5e998f2fca268df6daaa69871", OffsetDateTime.parse("2015-09-17T20:08:00Z")); @@ -99,7 +100,7 @@ public void asDataPointsShouldReturnNoDataPointsWhenBodyMassIndexValueIsZero() t JsonNode zeroValueNode = asJsonNode("org/openmhealth/shim/ihealth/mapper/ihealth-weight-no-weight-value.json"); - assertThat(mapper.asDataPoints(singletonList(zeroValueNode)), is(empty())); + assertThat(mapper.asDataPoints(zeroValueNode), is(empty())); } @Test @@ -107,7 +108,7 @@ public void asDataPointsShouldReturnNoDataPointsWhenWeightListIsEmpty() throws I JsonNode emptyListNode = asJsonNode("org/openmhealth/shim/ihealth/mapper/ihealth-weight-empty.json"); - assertThat(mapper.asDataPoints(singletonList(emptyListNode)), is(empty())); + assertThat(mapper.asDataPoints(emptyListNode), is(empty())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBodyWeightDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBodyWeightDataPointMapperUnitTests.java index 4a38513c..2ec338e6 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBodyWeightDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBodyWeightDataPointMapperUnitTests.java @@ -18,22 +18,21 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.*; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.io.IOException; import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.openmhealth.schema.domain.omh.BodyWeight.*; +import static org.openmhealth.schema.domain.omh.BodyWeight.SCHEMA_ID; import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; -import static org.openmhealth.shim.ihealth.mapper.IHealthBodyWeightDataPointMapper.*; +import static org.openmhealth.shim.ihealth.mapper.IHealthBodyWeightDataPointMapper.IHealthBodyWeightUnit; /** @@ -41,11 +40,11 @@ */ public class IHealthBodyWeightDataPointMapperUnitTests extends IHealthDataPointMapperUnitTests { - protected JsonNode responseNode; - IHealthBodyWeightDataPointMapper mapper = new IHealthBodyWeightDataPointMapper(); - List> dataPoints; + private JsonNode responseNode; + private final IHealthBodyWeightDataPointMapper mapper = new IHealthBodyWeightDataPointMapper(); + private List> dataPoints; - @BeforeTest + @BeforeClass public void initializeResponseNode() throws IOException { responseNode = asJsonNode("org/openmhealth/shim/ihealth/mapper/ihealth-weight.json"); @@ -54,7 +53,7 @@ public void initializeResponseNode() throws IOException { @BeforeMethod public void initializeDataPoints() { - dataPoints = mapper.asDataPoints(singletonList(responseNode)); + dataPoints = mapper.asDataPoints(responseNode); } @Test @@ -66,14 +65,15 @@ public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { @Test public void asDataPointsShouldReturnCorrectSensedDataPoints() { - BodyWeight.Builder expectedBodyWeightBuilder = new BodyWeight.Builder( + BodyWeight expectedBodyWeight = new BodyWeight.Builder( new MassUnitValue(MassUnit.KILOGRAM, 77.5643875134944)) - .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T12:04:09-08:00")); - - assertThat(dataPoints.get(0).getBody(), equalTo(expectedBodyWeightBuilder.build())); + .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T12:04:09-08:00")) + .build(); + assertThat(dataPoints.get(0).getBody(), equalTo(expectedBodyWeight)); DataPointHeader dataPointHeader = dataPoints.get(0).getHeader(); + testDataPointHeader(dataPointHeader, SCHEMA_ID, SENSED, "5fe5893c418b48cd8da7954f8b6c2f36", OffsetDateTime.parse("2015-09-17T20:04:17Z")); } @@ -81,12 +81,13 @@ public void asDataPointsShouldReturnCorrectSensedDataPoints() { @Test public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() { - BodyWeight.Builder expectedBodyWeightBuilder = + BodyWeight expectedBodyWeight = new BodyWeight.Builder(new MassUnitValue(MassUnit.KILOGRAM, 77.56438446044922)) .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-17T14:07:57-06:00")) - .setUserNotes("Weight so good, look at me now"); + .setUserNotes("Weight so good, look at me now") + .build(); - assertThat(dataPoints.get(1).getBody(), equalTo(expectedBodyWeightBuilder.build())); + assertThat(dataPoints.get(1).getBody(), equalTo(expectedBodyWeight)); testDataPointHeader(dataPoints.get(1).getHeader(), SCHEMA_ID, SELF_REPORTED, "b702a3a5e998f2fca268df6daaa69871", OffsetDateTime.parse("2015-09-17T20:08:00Z")); @@ -106,7 +107,7 @@ public void asDataPointsShouldReturnNoDataPointsWhenWeightValueEqualsZero() thro JsonNode zeroValueNode = asJsonNode("org/openmhealth/shim/ihealth/mapper/ihealth-weight-no-weight-value.json"); - assertThat(mapper.asDataPoints(singletonList(zeroValueNode)), is(empty())); + assertThat(mapper.asDataPoints(zeroValueNode), is(empty())); } @Test @@ -114,7 +115,7 @@ public void asDataPointsShouldReturnNoDataPointsWhenWeightListIsEmpty() throws I JsonNode emptyListNode = asJsonNode("org/openmhealth/shim/ihealth/mapper/ihealth-weight-empty.json"); - assertThat(mapper.asDataPoints(singletonList(emptyListNode)), is(empty())); + assertThat(mapper.asDataPoints(emptyListNode), is(empty())); } @Test @@ -126,6 +127,7 @@ public void getBodyWeightValueForUnitTypeShouldReturnCorrectValueForOmhCompatibl bodyWeightValueForUnitType = mapper.getBodyWeightValueForUnitType(100.5, IHealthBodyWeightUnit.LB); + assertThat(bodyWeightValueForUnitType, equalTo(100.5)); } @@ -134,6 +136,7 @@ public void getBodyWeightValueForUnitTypeShouldReturnCorrectValueForOmhIncompati double bodyWeightValueForUnitType = mapper.getBodyWeightValueForUnitType(12.4, IHealthBodyWeightUnit.STONE); + assertThat(bodyWeightValueForUnitType, equalTo(78.74372)); } diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapperUnitTests.java index fe4684b8..eb5fb160 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapperUnitTests.java @@ -28,7 +28,6 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -46,7 +45,7 @@ public class IHealthPhysicalActivityDataPointMapperUnitTests extends IHealthData private JsonNode responseNode; private IHealthPhysicalActivityDataPointMapper mapper = new IHealthPhysicalActivityDataPointMapper(); - List> dataPoints; + private List> dataPoints; @BeforeTest public void initializeResponseNode() throws IOException { @@ -57,7 +56,7 @@ public void initializeResponseNode() throws IOException { @BeforeMethod public void initializeDataPoints() { - dataPoints = mapper.asDataPoints(singletonList(responseNode)); + dataPoints = mapper.asDataPoints(responseNode); } @Test @@ -101,7 +100,7 @@ public void asDataPointsReturnsNoDataPointsForAnEmptyList() throws IOException { JsonNode emptyListResponseNode = asJsonNode("/org/openmhealth/shim/ihealth/mapper/ihealth-sport-empty.json"); - assertThat(mapper.asDataPoints(singletonList(emptyListResponseNode)), is(empty())); + assertThat(mapper.asDataPoints(emptyListResponseNode), is(empty())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthSleepDurationDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthSleepDurationDataPointMapperUnitTests.java index 4bdc94eb..4290b363 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthSleepDurationDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthSleepDurationDataPointMapperUnitTests.java @@ -28,16 +28,13 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; import static org.openmhealth.schema.domain.omh.DurationUnit.MINUTE; -import static org.openmhealth.schema.domain.omh.SleepDuration.*; +import static org.openmhealth.schema.domain.omh.SleepDuration.SCHEMA_ID; import static org.openmhealth.schema.domain.omh.TimeInterval.ofStartDateTimeAndEndDateTime; @@ -59,7 +56,7 @@ public void initializeResponse() { @BeforeMethod public void initializeDataPoints() { - dataPoints = mapper.asDataPoints(singletonList(responseNode)); + dataPoints = mapper.asDataPoints(responseNode); } @Test @@ -71,14 +68,14 @@ public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { @Test public void asDataPointsShouldReturnCorrectDataPointsWhenSensed() { - SleepDuration.Builder expectedSleepDurationBuilder = new SleepDuration.Builder(new DurationUnitValue( - MINUTE, 345)); + SleepDuration expectedSleepDuration = new SleepDuration.Builder(new DurationUnitValue( + MINUTE, 345)) + .setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime( + OffsetDateTime.parse("2015-11-15T01:51:00-07:00"), + OffsetDateTime.parse("2015-11-15T09:16:00-07:00"))) + .build(); - expectedSleepDurationBuilder.setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime( - OffsetDateTime.parse("2015-11-15T01:51:00-07:00"), - OffsetDateTime.parse("2015-11-15T09:16:00-07:00"))); - - assertThat(dataPoints.get(0).getBody(), equalTo(expectedSleepDurationBuilder.build())); + assertThat(dataPoints.get(0).getBody(), equalTo(expectedSleepDuration)); testDataPointHeader(dataPoints.get(0).getHeader(), SCHEMA_ID, SENSED, "7eb7292b90d710ae7b7f61b75f9425cf", OffsetDateTime.parse("2015-11-15T16:19:10Z")); @@ -97,16 +94,14 @@ public void asDataPointsShouldMapAwakenAsAdditionalProperty() { @Test public void asDataPointsShouldReturnDataPointWithUserNoteWhenNoteIsPresent() { - SleepDuration.Builder expectedSleepDurationBuilder = - new SleepDuration.Builder(new DurationUnitValue(MINUTE, 195)); - - expectedSleepDurationBuilder.setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime( - OffsetDateTime.parse("2015-11-15T13:51:00+01:00"), - OffsetDateTime.parse("2015-11-15T17:16:00+01:00"))); - - expectedSleepDurationBuilder.setUserNotes("Best sleep ever"); + SleepDuration expectedSleepDuration = new SleepDuration.Builder(new DurationUnitValue(MINUTE, 195)) + .setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime( + OffsetDateTime.parse("2015-11-15T13:51:00+01:00"), + OffsetDateTime.parse("2015-11-15T17:16:00+01:00"))) + .setUserNotes("Best sleep ever") + .build(); - assertThat(dataPoints.get(1).getBody(), equalTo(expectedSleepDurationBuilder.build())); + assertThat(dataPoints.get(1).getBody(), equalTo(expectedSleepDuration)); assertThat(dataPoints.get(0).getBody().getUserNotes(), nullValue()); assertThat(dataPoints.get(1).getBody().getUserNotes(), equalTo("Best sleep ever")); @@ -123,6 +118,6 @@ public void asDataPointsShouldReturnEmptyListWhenEmptyIHealthResponse() { JsonNode emptyNode = asJsonNode("/org/openmhealth/shim/ihealth/mapper/ihealth-sleep-empty.json"); - assertThat(mapper.asDataPoints(singletonList(emptyNode)), is(empty())); + assertThat(mapper.asDataPoints(emptyNode), is(empty())); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthStepCountDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthStepCountDataPointMapperUnitTests.java index 46319930..12d79341 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthStepCountDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthStepCountDataPointMapperUnitTests.java @@ -18,7 +18,10 @@ import com.fasterxml.jackson.databind.JsonNode; import org.hamcrest.Matchers; -import org.openmhealth.schema.domain.omh.*; +import org.openmhealth.schema.domain.omh.DataPoint; +import org.openmhealth.schema.domain.omh.DurationUnitValue; +import org.openmhealth.schema.domain.omh.StepCount; +import org.openmhealth.schema.domain.omh.TimeInterval; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -26,15 +29,15 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.core.Is.is; -import static org.openmhealth.schema.domain.omh.DataPointModality.*; -import static org.openmhealth.schema.domain.omh.DurationUnit.*; -import static org.openmhealth.schema.domain.omh.StepCount.*; +import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; +import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.DurationUnit.DAY; +import static org.openmhealth.schema.domain.omh.StepCount.SCHEMA_ID; /** @@ -44,7 +47,7 @@ public class IHealthStepCountDataPointMapperUnitTests extends IHealthDataPointMa private JsonNode responseNode; private IHealthStepCountDataPointMapper mapper = new IHealthStepCountDataPointMapper(); - List> dataPoints; + private List> dataPoints; @BeforeClass @@ -56,7 +59,7 @@ public void initializeResponseNode() { @BeforeMethod public void initializeDataPoints() { - dataPoints = mapper.asDataPoints(singletonList(responseNode)); + dataPoints = mapper.asDataPoints(responseNode); } @Test @@ -64,25 +67,25 @@ public void asDataPointsShouldNotMapDataPointsWithZeroSteps() { JsonNode nodeWithNoSteps = asJsonNode("org/openmhealth/shim/ihealth/mapper/ihealth-activity-no-steps.json"); - assertThat(mapper.asDataPoints(singletonList(nodeWithNoSteps)), is(empty())); + assertThat(mapper.asDataPoints(nodeWithNoSteps), is(empty())); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - assertThat(mapper.asDataPoints(singletonList(responseNode)).size(), equalTo(2)); + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(2)); } @Test public void asDataPointsShouldReturnCorrectDataPointsWhenSensed() { - StepCount.Builder expectedStepCountBuilder = new StepCount.Builder(21); + StepCount expectedStepCount = new StepCount.Builder(21) + .setEffectiveTimeFrame( + TimeInterval.ofStartDateTimeAndDuration(OffsetDateTime.parse("2015-11-16T00:00:00+05:00"), + new DurationUnitValue(DAY, 1))) + .build(); - expectedStepCountBuilder.setEffectiveTimeFrame( - TimeInterval.ofStartDateTimeAndDuration(OffsetDateTime.parse("2015-11-16T00:00:00+05:00"), - new DurationUnitValue(DAY, 1))); - - assertThat(dataPoints.get(0).getBody(), equalTo(expectedStepCountBuilder.build())); + assertThat(dataPoints.get(0).getBody(), equalTo(expectedStepCount)); testDataPointHeader(dataPoints.get(0).getHeader(), SCHEMA_ID, SENSED, "ac67c4ccf64af669d92569af85d19f59", OffsetDateTime.parse("2015-11-17T19:23:21Z")); @@ -91,13 +94,13 @@ public void asDataPointsShouldReturnCorrectDataPointsWhenSensed() { @Test public void asDataPointsShouldReturnDataPointWithUserNoteWhenNoteIsPresent() { - StepCount.Builder expectedStepCountBuilder = new StepCount.Builder(4398); - - expectedStepCountBuilder.setEffectiveTimeFrame( - TimeInterval.ofStartDateTimeAndDuration(OffsetDateTime.parse("2015-11-18T00:00:00Z"), - new DurationUnitValue(DAY, 1))).setUserNotes("Great steps"); + StepCount expectedStepCount = new StepCount.Builder(4398) + .setEffectiveTimeFrame( + TimeInterval.ofStartDateTimeAndDuration(OffsetDateTime.parse("2015-11-18T00:00:00Z"), + new DurationUnitValue(DAY, 1))).setUserNotes("Great steps") + .build(); - assertThat(dataPoints.get(1).getBody(), Matchers.equalTo(expectedStepCountBuilder.build())); + assertThat(dataPoints.get(1).getBody(), Matchers.equalTo(expectedStepCount)); assertThat(dataPoints.get(0).getBody().getUserNotes(), nullValue()); assertThat(dataPoints.get(1).getBody().getUserNotes(), equalTo("Great steps")); @@ -106,8 +109,8 @@ public void asDataPointsShouldReturnDataPointWithUserNoteWhenNoteIsPresent() { @Test public void asDataPointsShouldReturnSensedDataPointWhenManuallyEntered() { - assertThat(mapper.asDataPoints(singletonList(responseNode)).get(1).getHeader().getAcquisitionProvenance() - .getModality(), equalTo(SELF_REPORTED)); + assertThat(mapper.asDataPoints(responseNode).get(1).getHeader().getAcquisitionProvenance().getModality(), + equalTo(SELF_REPORTED)); } @Test @@ -115,6 +118,6 @@ public void asDataPointsShouldReturnEmptyListWhenEmptyIHealthResponse() { JsonNode emptyNode = asJsonNode("/org/openmhealth/shim/ihealth/mapper/ihealth-activity-empty.json"); - assertThat(mapper.asDataPoints(singletonList(emptyNode)), is(empty())); + assertThat(mapper.asDataPoints(emptyNode), is(empty())); } } From 45b7c0ac8419ad603aa95cca14950acb7417ef4e Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Tue, 22 Dec 2015 14:51:30 -0700 Subject: [PATCH 03/18] Simplify Misfit mapper tests --- ...sicalActivityDataPointMapperUnitTests.java | 15 +++------ ...SleepDurationDataPointMapperUnitTests.java | 33 +++++++------------ ...sfitStepCountDataPointMapperUnitTests.java | 15 +++------ 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapperUnitTests.java index 9c237a27..b85ec027 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapperUnitTests.java @@ -1,23 +1,20 @@ package org.openmhealth.shim.misfit.mapper; import com.fasterxml.jackson.databind.JsonNode; -import org.hamcrest.Matchers; import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.io.IOException; import java.time.OffsetDateTime; import java.time.ZoneOffset; -import java.util.Collections; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; import static org.openmhealth.schema.domain.omh.DurationUnit.SECOND; import static org.openmhealth.schema.domain.omh.LengthUnit.MILE; @@ -36,14 +33,13 @@ public class MisfitPhysicalActivityDataPointMapperUnitTests extends DataPointMap @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = new ClassPathResource("org/openmhealth/shim/misfit/mapper/misfit-sessions.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("org/openmhealth/shim/misfit/mapper/misfit-sessions.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(Collections.singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints, notNullValue()); assertThat(dataPoints.size(), equalTo(3)); @@ -52,7 +48,7 @@ public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(Collections.singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints, notNullValue()); assertThat(dataPoints.size(), greaterThan(0)); @@ -85,8 +81,7 @@ public void asDataPointsShouldReturnEmptyListIfEmptyResponse() throws IOExceptio JsonNode emptyNode = objectMapper.readTree("{\n" + " \"sessions\": []\n" + "}"); - List> dataPoints = mapper.asDataPoints(singletonList(emptyNode)); - assertThat(dataPoints.size(), Matchers.equalTo(0)); + assertThat(mapper.asDataPoints(emptyNode), empty()); } } \ No newline at end of file diff --git a/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitSleepDurationDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitSleepDurationDataPointMapperUnitTests.java index 54bac8cc..7ab87b49 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitSleepDurationDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitSleepDurationDataPointMapperUnitTests.java @@ -1,11 +1,9 @@ package org.openmhealth.shim.misfit.mapper; import com.fasterxml.jackson.databind.JsonNode; -import org.hamcrest.Matchers; import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; import org.openmhealth.shim.common.mapper.JsonNodeMappingException; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -14,10 +12,7 @@ import java.time.ZoneOffset; import java.util.List; -import static java.util.Collections.singletonList; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; @@ -38,9 +33,7 @@ public class MisfitSleepDurationDataPointMapperUnitTests extends DataPointMapper @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/misfit/mapper/misfit-sleeps.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("org/openmhealth/shim/misfit/mapper/misfit-sleeps.json"); } @Test(expectedExceptions = JsonNodeMappingException.class) @@ -58,7 +51,7 @@ public void asDataPointsShouldThrowExceptionOnEmptySleepDetails() throws IOExcep " ]\n" + "}"); - mapper.asDataPoints(singletonList(node)); + mapper.asDataPoints(node); } @Test @@ -81,7 +74,7 @@ public void asDataPointsShouldReturnEmptyListIfAwake() throws IOException { " ]\n" + "}"); - List> dataPoints = mapper.asDataPoints(singletonList(node)); + List> dataPoints = mapper.asDataPoints(node); assertThat(dataPoints, notNullValue()); assertThat(dataPoints, empty()); @@ -90,7 +83,7 @@ public void asDataPointsShouldReturnEmptyListIfAwake() throws IOException { @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints, notNullValue()); assertThat(dataPoints.size(), equalTo(2)); @@ -102,15 +95,14 @@ public void asDataPointsShouldReturnEmptyListIfEmptyResponse() throws IOExceptio JsonNode emptyNode = objectMapper.readTree("{\n" + " \"sleeps\": []\n" + "}"); - List> dataPoints = mapper.asDataPoints(singletonList(emptyNode)); - assertThat(dataPoints.size(), Matchers.equalTo(0)); + assertThat(mapper.asDataPoints(emptyNode), empty()); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints, notNullValue()); assertThat(dataPoints.size(), greaterThan(0)); @@ -139,15 +131,14 @@ public void asDataPointsShouldReturnCorrectDataPoints() { @Test public void asDataPointsShouldSetModalityAsSensedOnlyWhenAutodetectedIsTrue() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/misfit/mapper/misfit-sleeps-detected-and-not.json"); - JsonNode responseNodeForSleepSensing = objectMapper.readTree(resource.getInputStream()); + JsonNode responseNodeForSleepSensing = + asJsonNode("org/openmhealth/shim/misfit/mapper/misfit-sleeps-detected-and-not.json"); - List> dataPoints = mapper.asDataPoints(singletonList(responseNodeForSleepSensing)); + List> dataPoints = mapper.asDataPoints(responseNodeForSleepSensing); assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED)); - assertThat(dataPoints.get(1).getHeader().getAcquisitionProvenance().getModality(),nullValue()); - assertThat(dataPoints.get(2).getHeader().getAcquisitionProvenance().getModality(),nullValue()); + assertThat(dataPoints.get(1).getHeader().getAcquisitionProvenance().getModality(), nullValue()); + assertThat(dataPoints.get(2).getHeader().getAcquisitionProvenance().getModality(), nullValue()); } } \ No newline at end of file diff --git a/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitStepCountDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitStepCountDataPointMapperUnitTests.java index 30852c95..6c023796 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitStepCountDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitStepCountDataPointMapperUnitTests.java @@ -1,10 +1,8 @@ package org.openmhealth.shim.misfit.mapper; import com.fasterxml.jackson.databind.JsonNode; -import org.hamcrest.Matchers; import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -13,10 +11,10 @@ import java.util.List; import static java.time.ZoneOffset.UTC; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; import static org.openmhealth.schema.domain.omh.DurationUnit.DAY; import static org.openmhealth.shim.misfit.mapper.MisfitDataPointMapper.RESOURCE_API_SOURCE_NAME; @@ -34,15 +32,13 @@ public class MisfitStepCountDataPointMapperUnitTests extends DataPointMapperUnit @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/misfit/mapper/misfit-detailed-summaries.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("org/openmhealth/shim/misfit/mapper/misfit-detailed-summaries.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints, notNullValue()); assertThat(dataPoints.size(), equalTo(3)); @@ -51,7 +47,7 @@ public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints, notNullValue()); assertThat(dataPoints.size(), greaterThan(0)); @@ -81,8 +77,7 @@ public void asDataPointsShouldReturnEmptyListIfEmptyResponse() throws IOExceptio JsonNode emptyNode = objectMapper.readTree("{\n" + " \"summary\": []\n" + "}"); - List> dataPoints = mapper.asDataPoints(singletonList(emptyNode)); - assertThat(dataPoints.size(), Matchers.equalTo(0)); + assertThat(mapper.asDataPoints(emptyNode), empty()); } } \ No newline at end of file From bddfeffabb6f56f28ed54bab57e3bc643884e5bd Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Wed, 23 Dec 2015 09:58:51 -0500 Subject: [PATCH 04/18] Simplify a couple jawbone and runkeeper mapper tests --- ...BodyMassIndexDataPointMapperUnitTests.java | 13 +++--- ...aloriesBurnedDataPointMapperUnitTests.java | 40 +++++++++---------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawboneBodyMassIndexDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawboneBodyMassIndexDataPointMapperUnitTests.java index 0e235c65..eaf4a0ed 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawboneBodyMassIndexDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawboneBodyMassIndexDataPointMapperUnitTests.java @@ -1,8 +1,10 @@ package org.openmhealth.shim.jawbone.mapper; import com.google.common.collect.Maps; -import org.openmhealth.schema.domain.omh.*; -import org.springframework.core.io.ClassPathResource; +import org.openmhealth.schema.domain.omh.BodyMassIndex; +import org.openmhealth.schema.domain.omh.BodyMassIndexUnit; +import org.openmhealth.schema.domain.omh.DataPoint; +import org.openmhealth.schema.domain.omh.TypedUnitValue; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -21,14 +23,13 @@ */ public class JawboneBodyMassIndexDataPointMapperUnitTests extends JawboneDataPointMapperUnitTests { - private JawboneBodyMassIndexDataPointMapper mapper = new JawboneBodyMassIndexDataPointMapper(); + private final JawboneBodyMassIndexDataPointMapper mapper = new JawboneBodyMassIndexDataPointMapper(); @BeforeTest public void initializeResponseNodes() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/jawbone/mapper/jawbone-body-events.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + + responseNode = asJsonNode("org/openmhealth/shim/jawbone/mapper/jawbone-body-events.json"); initializeEmptyNode(); } diff --git a/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperCaloriesBurnedDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperCaloriesBurnedDataPointMapperUnitTests.java index b0d1c481..ba0a4ee4 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperCaloriesBurnedDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperCaloriesBurnedDataPointMapperUnitTests.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -11,9 +10,14 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.openmhealth.schema.domain.omh.CaloriesBurned.SCHEMA_ID; +import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.DurationUnit.SECOND; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; +import static org.openmhealth.schema.domain.omh.TimeInterval.ofStartDateTimeAndDuration; +import static org.openmhealth.shim.runkeeper.mapper.RunkeeperDataPointMapper.RESOURCE_API_SOURCE_NAME; /** @@ -22,54 +26,50 @@ public class RunkeeperCaloriesBurnedDataPointMapperUnitTests extends DataPointMapperUnitTests { private JsonNode responseNode; - private RunkeeperCaloriesBurnedDataPointMapper mapper = new RunkeeperCaloriesBurnedDataPointMapper(); + private final RunkeeperCaloriesBurnedDataPointMapper mapper = new RunkeeperCaloriesBurnedDataPointMapper(); @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/runkeeper/mapper/runkeeper-fitness-activities.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("org/openmhealth/shim/runkeeper/mapper/runkeeper-fitness-activities.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - - assertThat(dataPoints.size(), equalTo(1)); + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(1)); } @Test public void asDataPointsShouldReturnCorrectDataPointBodies() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); - CaloriesBurned.Builder expectedCaloriesBurnedBuilder = - new CaloriesBurned.Builder(new KcalUnitValue(KcalUnit.KILOCALORIE, 210.796359954334)) + CaloriesBurned expectedCaloriesBurned = + new CaloriesBurned.Builder(new KcalUnitValue(KILOCALORIE, 210.796359954334)) .setActivityName("Cycling") - .setEffectiveTimeFrame(TimeInterval.ofStartDateTimeAndDuration( + .setEffectiveTimeFrame(ofStartDateTimeAndDuration( OffsetDateTime.parse("2014-10-19T13:17:27+02:00"), - new DurationUnitValue(DurationUnit.SECOND, 4364.74158141667))); + new DurationUnitValue(SECOND, 4364.74158141667))) + .build(); - assertThat(dataPoints.get(0).getBody(), equalTo(expectedCaloriesBurnedBuilder.build())); + assertThat(dataPoints.get(0).getBody(), equalTo(expectedCaloriesBurned)); } @Test public void asDataPointsShouldReturnCorrectDataPointHeaders() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - DataPointHeader firstTestHeader = dataPoints.get(0).getHeader(); + DataPointHeader firstTestHeader = mapper.asDataPoints(responseNode).get(0).getHeader(); - assertThat(firstTestHeader.getAcquisitionProvenance().getModality(), equalTo(DataPointModality.SENSED)); + assertThat(firstTestHeader.getAcquisitionProvenance().getModality(), equalTo(SENSED)); - assertThat(firstTestHeader.getBodySchemaId(), equalTo(CaloriesBurned.SCHEMA_ID)); + assertThat(firstTestHeader.getBodySchemaId(), equalTo(SCHEMA_ID)); assertThat(firstTestHeader.getAcquisitionProvenance().getAdditionalProperty("external_id").get(), equalTo("/fitnessActivities/465161536")); assertThat(firstTestHeader.getAcquisitionProvenance().getSourceName(), - equalTo(RunkeeperDataPointMapper.RESOURCE_API_SOURCE_NAME)); + equalTo(RESOURCE_API_SOURCE_NAME)); } } From 6ba4b0743e3a3e3296f1a7832171332038c83ed7 Mon Sep 17 00:00:00 2001 From: Emerson Farrugia Date: Wed, 23 Dec 2015 16:43:38 +0100 Subject: [PATCH 05/18] Fix versions in develop --- build.gradle | 2 +- shim-server-ui/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 0527d34d..58336dc7 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ subprojects { ext { javaVersion = 1.8 - shimmerVersion = '0.4.2' + shimmerVersion = '0.5.0-SNAPSHOT' omhSchemaSdkVersion = '1.0.3' } diff --git a/shim-server-ui/package.json b/shim-server-ui/package.json index b8c21951..0bfcbc13 100644 --- a/shim-server-ui/package.json +++ b/shim-server-ui/package.json @@ -1,6 +1,6 @@ { "name": "shim-server-ui", - "version": "0.4.2", + "version": "0.5.0-SNAPSHOT", "dependencies": {}, "devDependencies": { "grunt": "~0.4.5", From 6bccb776bbaf59fb26e1dd64a0fe248d46ae2fdb Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Thu, 4 Feb 2016 14:25:28 -0700 Subject: [PATCH 06/18] Bump schema-sdk version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 58336dc7..553cfc86 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ subprojects { ext { javaVersion = 1.8 shimmerVersion = '0.5.0-SNAPSHOT' - omhSchemaSdkVersion = '1.0.3' + omhSchemaSdkVersion = '1.0.4' } sourceCompatibility = javaVersion From 6f26efa2d1f6609efe0d03960699640f4051ca73 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Thu, 4 Feb 2016 16:07:02 -0700 Subject: [PATCH 07/18] Map calories burned for Fitbit physical activity --- ...FitbitPhysicalActivityDataPointMapper.java | 4 +++ ...sicalActivityDataPointMapperUnitTests.java | 29 ++++++++++++------- ...ties-date-multiple-in-activities-list.json | 1 - 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/shim-server/src/main/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapper.java index e54e9484..0169d907 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapper.java +++ b/shim-server/src/main/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapper.java @@ -26,6 +26,7 @@ import static org.openmhealth.schema.domain.omh.DurationUnit.DAY; import static org.openmhealth.schema.domain.omh.DurationUnit.MILLISECOND; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; import static org.openmhealth.schema.domain.omh.LengthUnit.KILOMETER; import static org.openmhealth.shim.common.mapper.JsonNodeMappingSupport.*; @@ -95,6 +96,9 @@ protected Optional> asDataPoint(JsonNode node) { activityBuilder.setDistance(new LengthUnitValue(KILOMETER, distance.get())); } + asOptionalDouble(node, "calories").ifPresent(calories -> activityBuilder.setCaloriesBurned( + new KcalUnitValue(KILOCALORIE, calories))); + PhysicalActivity measure = activityBuilder.build(); Optional externalId = asOptionalLong(node, "logId"); diff --git a/shim-server/src/test/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapperUnitTests.java index 8d761986..bf64cd86 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapperUnitTests.java @@ -17,7 +17,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; +import static org.openmhealth.schema.domain.omh.DurationUnit.*; import static org.openmhealth.schema.domain.omh.DurationUnit.DAY; +import static org.openmhealth.schema.domain.omh.KcalUnit.*; import static org.openmhealth.schema.domain.omh.LengthUnit.KILOMETER; @@ -62,7 +64,7 @@ public void asDataPointsShouldReturnCorrectDataPointForSingleActivity() { List> dataPoints = mapper.asDataPoints(singleActivityResponseNode); - assertThatDataPointMatches(dataPoints.get(0), "Walk", "2014-06-19", "09:00", 3.36, 3600000L, 79441095L); + assertThatDataPointMatches(dataPoints.get(0), "Walk", "2014-06-19", "09:00", 3.36, 3600000L, 79441095L, 128.0); } @Test @@ -70,13 +72,15 @@ public void asDataPointsShouldReturnCorrectDataPointsForMultipleActivities() { List> dataPoints = mapper.asDataPoints(multipleActivityResponseNode); - assertThatDataPointMatches(dataPoints.get(0), "Run", "2015-06-23", "11:55", 6.43738, 1440000L, 253202765L); - assertThatDataPointMatches(dataPoints.get(1), "Swimming", "2015-06-23", "10:00", null, null, 253246706L); - assertThatDataPointMatches(dataPoints.get(2), "Walk", "2015-06-23", 6.43738, 253202766L); + assertThatDataPointMatches(dataPoints.get(0), "Run", "2015-06-23", "11:55", 6.43738, 1440000L, 253202765L, + 150.0); + assertThatDataPointMatches(dataPoints.get(1), "Swimming", "2015-06-23", "10:00", null, null, 253246706L, null); + assertThatDataPointMatches(dataPoints.get(2), "Walk", "2015-06-23", 6.43738, 253202766L, 200.0); } public void assertThatDataPointMatches(DataPoint dataPoint, String expectedActivityName, - String expectedEffectiveDate, Double expectedDistance, Long expectedExternalId) { + String expectedEffectiveDate, Double expectedDistance, Long expectedExternalId, + Double expectedCaloriesBurned) { OffsetDateTime expectedEffectiveStartDateTime = OffsetDateTime.of(LocalDate.parse(expectedEffectiveDate).atStartOfDay(), UTC); @@ -85,11 +89,12 @@ public void assertThatDataPointMatches(DataPoint dataPoint, St TimeInterval.ofStartDateTimeAndDuration(expectedEffectiveStartDateTime, new DurationUnitValue(DAY, 1))); assertThatDataPointMatches(dataPoint, expectedActivityName, expectedTimeFrame, expectedDistance, - expectedExternalId); + expectedExternalId, expectedCaloriesBurned); } public void assertThatDataPointMatches(DataPoint dataPoint, String expectedActivityName, - TimeFrame expectedTimeFrame, Double expectedDistance, Long expectedExternalId) { + TimeFrame expectedTimeFrame, Double expectedDistance, Long expectedExternalId, + Double expectedCaloriesBurned) { PhysicalActivity.Builder expectedMeasureBuilder = new PhysicalActivity.Builder(expectedActivityName); @@ -99,6 +104,10 @@ public void assertThatDataPointMatches(DataPoint dataPoint, St expectedMeasureBuilder.setDistance(new LengthUnitValue(KILOMETER, expectedDistance)); } + if (expectedCaloriesBurned != null) { + expectedMeasureBuilder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, expectedCaloriesBurned)); + } + PhysicalActivity expectedPhysicalActivity = expectedMeasureBuilder.build(); assertThat(dataPoint.getBody(), equalTo(expectedPhysicalActivity)); @@ -111,7 +120,7 @@ public void assertThatDataPointMatches(DataPoint dataPoint, St public void assertThatDataPointMatches(DataPoint dataPoint, String expectedActivityName, String expectedEffectiveDate, String expectedEffectiveStartTime, Double expectedDistance, - Long expectedDurationInMs, Long expectedExternalId) { + Long expectedDurationInMs, Long expectedExternalId, Double expectedCaloriesBurned) { OffsetDateTime expectedEffectiveStartDateTime = OffsetDateTime .of(LocalDate.parse(expectedEffectiveDate), LocalTime.parse(expectedEffectiveStartTime), UTC); @@ -119,7 +128,7 @@ public void assertThatDataPointMatches(DataPoint dataPoint, St TimeFrame expectedTimeFrame; if (expectedDurationInMs != null) { - DurationUnitValue expectedDuration = new DurationUnitValue(DurationUnit.MILLISECOND, expectedDurationInMs); + DurationUnitValue expectedDuration = new DurationUnitValue(MILLISECOND, expectedDurationInMs); expectedTimeFrame = new TimeFrame( TimeInterval.ofStartDateTimeAndDuration(expectedEffectiveStartDateTime, expectedDuration)); @@ -129,6 +138,6 @@ public void assertThatDataPointMatches(DataPoint dataPoint, St } assertThatDataPointMatches(dataPoint, expectedActivityName, expectedTimeFrame, expectedDistance, - expectedExternalId); + expectedExternalId, expectedCaloriesBurned); } } diff --git a/shim-server/src/test/resources/org/openmhealth/shim/fitbit/mapper/fitbit-activities-date-multiple-in-activities-list.json b/shim-server/src/test/resources/org/openmhealth/shim/fitbit/mapper/fitbit-activities-date-multiple-in-activities-list.json index eee8223e..7e70c94d 100644 --- a/shim-server/src/test/resources/org/openmhealth/shim/fitbit/mapper/fitbit-activities-date-multiple-in-activities-list.json +++ b/shim-server/src/test/resources/org/openmhealth/shim/fitbit/mapper/fitbit-activities-date-multiple-in-activities-list.json @@ -21,7 +21,6 @@ "activityId": 58002, "activityParentId": 90024, "activityParentName": "Swimming", - "calories": 100, "description": "50-75 yards/min", "hasStartTime": true, "isFavorite": false, From 74461df71498eff08b39f651f687aaec0ad8538b Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Thu, 4 Feb 2016 16:22:02 -0700 Subject: [PATCH 08/18] Map calories burned for iHealth physical activity --- .../IHealthPhysicalActivityDataPointMapper.java | 5 +++++ ...ealthPhysicalActivityDataPointMapperUnitTests.java | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapper.java index f735a677..d739ace3 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapper.java +++ b/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapper.java @@ -18,11 +18,13 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.DataPoint; +import org.openmhealth.schema.domain.omh.KcalUnitValue; import org.openmhealth.schema.domain.omh.PhysicalActivity; import java.time.ZoneOffset; import java.util.Optional; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; import static org.openmhealth.schema.domain.omh.TimeInterval.ofStartDateTimeAndEndDateTime; import static org.openmhealth.shim.common.mapper.JsonNodeMappingSupport.*; @@ -81,6 +83,9 @@ protected Optional> asDataPoint(JsonNode listEntryNo getDateTimeWithCorrectOffset(endTimeUnixEpochSecs.get(), ZoneOffset.of(timeZoneString)))); } + asOptionalDouble(listEntryNode, "Calories").ifPresent( + calories -> physicalActivityBuilder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, calories))); + PhysicalActivity physicalActivity = physicalActivityBuilder.build(); return Optional.of(new DataPoint<>(createDataPointHeader(listEntryNode, physicalActivity), physicalActivity)); diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapperUnitTests.java index fe4684b8..7e7adb36 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthPhysicalActivityDataPointMapperUnitTests.java @@ -17,9 +17,7 @@ package org.openmhealth.shim.ihealth.mapper; import com.fasterxml.jackson.databind.JsonNode; -import org.openmhealth.schema.domain.omh.DataPoint; -import org.openmhealth.schema.domain.omh.PhysicalActivity; -import org.openmhealth.schema.domain.omh.TimeInterval; +import org.openmhealth.schema.domain.omh.*; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -35,6 +33,7 @@ import static org.hamcrest.Matchers.empty; import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; import static org.openmhealth.schema.domain.omh.PhysicalActivity.SCHEMA_ID; @@ -73,7 +72,8 @@ public void asDataPointsShouldReturnCorrectSensedDataPoints() { new PhysicalActivity.Builder("Swimming, breaststroke") .setEffectiveTimeFrame(TimeInterval.ofStartDateTimeAndEndDateTime( OffsetDateTime.parse("2015-09-17T20:02:28-08:00"), - OffsetDateTime.parse("2015-09-17T20:32:28-08:00"))); + OffsetDateTime.parse("2015-09-17T20:32:28-08:00"))) + .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 221.5)); assertThat(dataPoints.get(0).getBody(), equalTo(expectedPhysicalActivityBuilder.build())); @@ -88,7 +88,8 @@ public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() { .setEffectiveTimeFrame( TimeInterval.ofStartDateTimeAndEndDateTime( OffsetDateTime.parse("2015-09-22T20:43:03+01:00"), - OffsetDateTime.parse("2015-09-22T21:13:03+01:00"))); + OffsetDateTime.parse("2015-09-22T21:13:03+01:00"))) + .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 202.5)); assertThat(dataPoints.get(1).getBody(), equalTo(expectedPhysicalActivityBuilder.build())); From 19c2044c624098edc6a04f31ecea659c7eca2044 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Thu, 4 Feb 2016 17:05:19 -0700 Subject: [PATCH 09/18] Map calories burned for Jawbone physical activity --- .../JawbonePhysicalActivityDataPointMapper.java | 14 ++++++++++++++ ...nePhysicalActivityDataPointMapperUnitTests.java | 10 ++++++++++ .../shim/jawbone/mapper/jawbone-workouts.json | 2 -- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java index 8157d8d1..cd5e3267 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java +++ b/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java @@ -18,11 +18,13 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.DurationUnitValue; +import org.openmhealth.schema.domain.omh.KcalUnitValue; import org.openmhealth.schema.domain.omh.LengthUnitValue; import org.openmhealth.schema.domain.omh.PhysicalActivity; import org.openmhealth.schema.domain.omh.PhysicalActivity.SelfReportedIntensity; import javax.annotation.Nullable; +import java.math.BigDecimal; import java.time.OffsetDateTime; import java.time.ZoneId; import java.util.HashMap; @@ -34,6 +36,7 @@ import static java.time.Instant.ofEpochSecond; import static java.time.OffsetDateTime.ofInstant; import static org.openmhealth.schema.domain.omh.DurationUnit.SECOND; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; import static org.openmhealth.schema.domain.omh.LengthUnit.METER; import static org.openmhealth.schema.domain.omh.PhysicalActivity.SelfReportedIntensity.*; import static org.openmhealth.schema.domain.omh.TimeInterval.ofEndDateTimeAndDuration; @@ -107,12 +110,23 @@ protected Optional getMeasure(JsonNode workoutNode) { Optional timeZoneId = asOptionalZoneId(workoutNode, "details.tz"); if (endTimestamp.isPresent() && durationInSec.isPresent() && timeZoneId.isPresent()) { + DurationUnitValue durationUnitValue = new DurationUnitValue(SECOND, durationInSec.get()); + OffsetDateTime endDateTime = ofInstant(ofEpochSecond(endTimestamp.get()), JawboneDataPointMapper.getTimeZoneForTimestamp(workoutNode, endTimestamp.get())); + builder.setEffectiveTimeFrame(ofEndDateTimeAndDuration(endDateTime, durationUnitValue)); } + Optional totalCalories = asOptionalBigDecimal(workoutNode, "details.calories"); + + if (totalCalories.isPresent()) { + + asOptionalBigDecimal(workoutNode, "details.bmr_calories").ifPresent(bmrCalories -> builder + .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, totalCalories.get().subtract(bmrCalories)))); + } + asOptionalInteger(workoutNode, "details.intensity") .ifPresent(intensity -> builder.setReportedActivityIntensity(asSelfReportedIntensity(intensity))); diff --git a/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapperUnitTests.java index 123b7769..e4b23f36 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapperUnitTests.java @@ -19,10 +19,12 @@ import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; import static org.openmhealth.schema.domain.omh.DurationUnit.SECOND; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; import static org.openmhealth.schema.domain.omh.LengthUnit.METER; import static org.openmhealth.schema.domain.omh.PhysicalActivity.SelfReportedIntensity.MODERATE; import static org.openmhealth.shim.jawbone.mapper.JawboneDataPointMapper.RESOURCE_API_SOURCE_NAME; @@ -79,6 +81,7 @@ public void asDataPointsShouldReturnCorrectSensedDataPoints() { .setDistance(new LengthUnitValue(METER, 5_116)) .setEffectiveTimeFrame(effectiveTimeInterval) .setReportedActivityIntensity(MODERATE) + .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 634.928678924)) .build(); DataPoint firstDataPoint = dataPoints.get(0); @@ -105,6 +108,7 @@ public void asDataPointsShouldReturnCorrectMissingSensedDataPoints() { .setEffectiveTimeFrame( TimeInterval.ofEndDateTimeAndDuration(OffsetDateTime.parse("2015-04-29T16:07:07-04:00"), new DurationUnitValue(SECOND, 343))) + .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 27.16863765916)) .build(); assertThat(dataPoints.get(1).getBody(), equalTo(expectedPhysicalActivity)); @@ -117,6 +121,12 @@ public void asDataPointsShouldReturnCorrectMissingSensedDataPoints() { testDataPointHeader(testDataPointHeader, testProperties); } + @Test + public void asDataPointsShouldReturnDataPointWithoutCaloriesBurnedWhenCaloriesAreMissing() { + + assertThat(mapper.asDataPoints(responseNode).get(2).getBody().getCaloriesBurned(), nullValue()); + } + // TODO multiple tests? @Test public void asSelfReportedIntensityShouldReturnCorrectIntensityWhenWithinSpecification() { diff --git a/shim-server/src/test/resources/org/openmhealth/shim/jawbone/mapper/jawbone-workouts.json b/shim-server/src/test/resources/org/openmhealth/shim/jawbone/mapper/jawbone-workouts.json index c6e4ba47..1cb5236c 100644 --- a/shim-server/src/test/resources/org/openmhealth/shim/jawbone/mapper/jawbone-workouts.json +++ b/shim-server/src/test/resources/org/openmhealth/shim/jawbone/mapper/jawbone-workouts.json @@ -69,8 +69,6 @@ "details": { "bg_active_time": 0, "bg_calories": 0, - "bmr": 19.2051012053, - "bmr_calories": 19.2051012053, "calories": 221.0, "goal": 0, "intensity": null, From 260ee8eec969ae9850ed92c9fc6634781ec853b1 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Fri, 5 Feb 2016 11:04:19 -0700 Subject: [PATCH 10/18] Simplify Runkeeper and Withings mapper tests --- .../RunkeeperDataPointMapperUnitTests.java | 7 +-- ...sicalActivityDataPointMapperUnitTests.java | 27 +++------- ...BloodPressureDataPointMapperUnitTests.java | 10 ++-- ...ngsBodyHeightDataPointMapperUnitTests.java | 19 ++++--- ...ngsBodyWeightDataPointMapperUnitTests.java | 40 ++++++++------- ...aloriesBurnedDataPointMapperUnitTests.java | 37 +++++++------- ...ailyStepCountDataPointMapperUnitTests.java | 36 ++++++++------ ...ingsHeartRateDataPointMapperUnitTests.java | 28 ++++------- ...aloriesBurnedDataPointMapperUnitTests.java | 49 ++++++++++--------- ...adayStepCountDataPointMapperUnitTests.java | 37 ++++++++------ ...SleepDurationDataPointMapperUnitTests.java | 37 +++++++------- 11 files changed, 160 insertions(+), 167 deletions(-) diff --git a/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperDataPointMapperUnitTests.java index 329a65bb..6b1d5147 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperDataPointMapperUnitTests.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.DataPoint; -import org.openmhealth.schema.domain.omh.DataPointModality; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; import org.testng.annotations.Test; @@ -11,6 +10,8 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; +import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; /** @@ -33,7 +34,7 @@ public void getModalityShouldReturnSensedOnlyWhenSourceIsRunkeeperAndModeIsApiAn " \"has_path\": true,\n" + " \"source\": \"RunKeeper\"}"); - assertThat(mapper.getModality(expectedSensedNode).get(), equalTo(DataPointModality.SENSED)); + assertThat(mapper.getModality(expectedSensedNode).get(), equalTo(SENSED)); JsonNode expectedEmptyNodeMissingMode = objectMapper.readTree("{\"has_path\": true,\n" + " \"source\": \"RunKeeper\"}"); @@ -64,7 +65,7 @@ public void getModalityShouldReturnSelfReportedModeIsWeb() throws IOException { " \"has_path\": true,\n" + " \"source\": \"RunKeeper\"}"); - assertThat(mapper.getModality(expectedSensedNode).get(), equalTo(DataPointModality.SELF_REPORTED)); + assertThat(mapper.getModality(expectedSensedNode).get(), equalTo(SELF_REPORTED)); } @Test diff --git a/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperPhysicalActivityDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperPhysicalActivityDataPointMapperUnitTests.java index 6b424097..a8485cc0 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperPhysicalActivityDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/runkeeper/mapper/RunkeeperPhysicalActivityDataPointMapperUnitTests.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -12,10 +11,7 @@ import java.time.ZoneOffset; import java.util.List; -import static java.util.Collections.singletonList; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; @@ -39,16 +35,13 @@ public class RunkeeperPhysicalActivityDataPointMapperUnitTests extends DataPoint @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/runkeeper/mapper/runkeeper-fitness-activities.json"); - - responseNode = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("org/openmhealth/shim/runkeeper/mapper/runkeeper-fitness-activities.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints, notNullValue()); assertThat(dataPoints.size(), equalTo(2)); @@ -57,7 +50,7 @@ public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { @Test public void asDataPointsShouldReturnCorrectSensedDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints, notNullValue()); assertThat(dataPoints.size(), greaterThan(0)); @@ -71,11 +64,9 @@ public void asDataPointsShouldReturnCorrectSensedDataPoints() { .setEffectiveTimeFrame(effectiveTimeInterval) .build(); - DataPoint dataPoint = dataPoints.get(0); - - assertThat(dataPoint.getBody(), equalTo(physicalActivity)); + assertThat(dataPoints.get(0).getBody(), equalTo(physicalActivity)); - DataPointAcquisitionProvenance acquisitionProvenance = dataPoint.getHeader().getAcquisitionProvenance(); + DataPointAcquisitionProvenance acquisitionProvenance = dataPoints.get(0).getHeader().getAcquisitionProvenance(); assertThat(acquisitionProvenance, notNullValue()); assertThat(acquisitionProvenance.getSourceName(), equalTo(RESOURCE_API_SOURCE_NAME)); @@ -88,7 +79,7 @@ public void asDataPointsShouldReturnCorrectSensedDataPoints() { @Test public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints, notNullValue()); assertThat(dataPoints.size(), equalTo(2)); @@ -105,9 +96,7 @@ public void asDataPointsShouldReturnCorrectSelfReportedDataPoints() { public void asDataPointsShouldNotCreateDataPointWhenOffsetMissing() throws IOException { assertThat(mapper.asDataPoints( - asJsonNode( - "org/openmhealth/shim/runkeeper/mapper/runkeeper-fitness-activities-missing-offset" + - ".json")), + asJsonNode("org/openmhealth/shim/runkeeper/mapper/runkeeper-fitness-activities-missing-offset.json")), is(empty())); } } \ No newline at end of file diff --git a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBloodPressureDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBloodPressureDataPointMapperUnitTests.java index 5b15ee11..d1fca89f 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBloodPressureDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBloodPressureDataPointMapperUnitTests.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -30,6 +29,7 @@ import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +import static org.openmhealth.schema.domain.omh.BloodPressure.*; import static org.openmhealth.schema.domain.omh.BloodPressureUnit.MM_OF_MERCURY; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; import static org.openmhealth.shim.withings.mapper.WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME; @@ -46,16 +46,14 @@ public class WithingsBloodPressureDataPointMapperUnitTests extends DataPointMapp @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/withings/mapper/withings-body-measures.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("org/openmhealth/shim/withings/mapper/withings-body-measures.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + List> dataPoints = mapper.asDataPoints(responseNode); assertThat(dataPoints.size(), equalTo(1)); } @@ -73,7 +71,7 @@ public void asDataPointsShouldReturnCorrectDataPoints() { assertThat(actualDataPoints.get(0).getBody(), equalTo(expectedBloodPressure)); DataPointHeader actualDataPointHeader = actualDataPoints.get(0).getHeader(); - assertThat(actualDataPointHeader.getBodySchemaId(), equalTo(BloodPressure.SCHEMA_ID)); + assertThat(actualDataPointHeader.getBodySchemaId(), equalTo(SCHEMA_ID)); assertThat(actualDataPointHeader.getAcquisitionProvenance().getModality(), equalTo(SENSED)); assertThat(actualDataPointHeader.getAcquisitionProvenance().getSourceName(), equalTo(RESOURCE_API_SOURCE_NAME)); assertThat(actualDataPointHeader.getAcquisitionProvenance().getAdditionalProperties().get("external_id"), diff --git a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBodyHeightDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBodyHeightDataPointMapperUnitTests.java index a01f678c..c271a769 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBodyHeightDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBodyHeightDataPointMapperUnitTests.java @@ -21,7 +21,6 @@ import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; import org.openmhealth.shim.common.mapper.JsonNodeMappingException; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -29,10 +28,11 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +import static org.openmhealth.schema.domain.omh.BodyHeight.*; import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; +import static org.openmhealth.schema.domain.omh.LengthUnit.*; import static org.openmhealth.shim.withings.domain.WithingsBodyMeasureType.BODY_HEIGHT; import static org.openmhealth.shim.withings.mapper.WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME; @@ -50,10 +50,8 @@ public class WithingsBodyHeightDataPointMapperUnitTests extends DataPointMapperU @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/withings/mapper/withings-body-measures.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("org/openmhealth/shim/withings/mapper/withings-body-measures.json"); } // this is included in only one mapper for brevity, can be rinsed and repeated in others if necessary @@ -78,22 +76,23 @@ public void getValueForMeasureTypeShouldThrowExceptionOnDuplicateMeasureTypes() @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(1)); + + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(1)); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> actualDataPoints = mapper.asDataPoints(singletonList(responseNode)); - BodyHeight expectedBodyHeight = new BodyHeight.Builder(new LengthUnitValue(LengthUnit.METER, 1.93)) + List> actualDataPoints = mapper.asDataPoints(responseNode); + + BodyHeight expectedBodyHeight = new BodyHeight.Builder(new LengthUnitValue(METER, 1.93)) .setEffectiveTimeFrame(OffsetDateTime.parse("2015-02-23T19:24:49Z")) .build(); assertThat(actualDataPoints.get(0).getBody(), equalTo(expectedBodyHeight)); DataPointHeader actualDataPointHeader = actualDataPoints.get(0).getHeader(); - assertThat(actualDataPointHeader.getBodySchemaId(), equalTo(BodyHeight.SCHEMA_ID)); + assertThat(actualDataPointHeader.getBodySchemaId(), equalTo(SCHEMA_ID)); assertThat(actualDataPointHeader.getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED)); assertThat(actualDataPointHeader.getAcquisitionProvenance().getSourceName(), equalTo(RESOURCE_API_SOURCE_NAME)); assertThat(actualDataPointHeader.getAcquisitionProvenance().getAdditionalProperties().get("external_id"), diff --git a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBodyWeightDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBodyWeightDataPointMapperUnitTests.java index 762c13cc..e2ebb661 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBodyWeightDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsBodyWeightDataPointMapperUnitTests.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -27,14 +26,17 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +import static org.openmhealth.schema.domain.omh.BodyWeight.*; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.MassUnit.*; import static org.openmhealth.shim.withings.mapper.WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME; -// TODO add Javadoc and clean up +/** + * @author Chris Schaefbauer + */ public class WithingsBodyWeightDataPointMapperUnitTests extends DataPointMapperUnitTests { WithingsBodyWeightDataPointMapper mapper = new WithingsBodyWeightDataPointMapper(); @@ -43,51 +45,51 @@ public class WithingsBodyWeightDataPointMapperUnitTests extends DataPointMapperU @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/withings/mapper/withings-body-measures.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); - resource = new ClassPathResource("org/openmhealth/shim/withings/mapper/withings-body-measures-only-goal.json"); - responseNodeWithGoal = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("org/openmhealth/shim/withings/mapper/withings-body-measures.json"); + responseNodeWithGoal = asJsonNode("org/openmhealth/shim/withings/mapper/withings-body-measures-only-goal.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPointList = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPointList.size(), equalTo(2)); + + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(2)); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPointList = mapper.asDataPoints(singletonList(responseNode)); + + List> dataPointList = mapper.asDataPoints(responseNode); testDataPoint(dataPointList.get(0), 74.126, "2015-05-31T06:06:23Z", 366956482L); testDataPoint(dataPointList.get(1), 74.128, "2015-04-20T17:13:56Z", 347186704L); - } @Test public void asDataPointsShouldIgnoreGoalsForBodyMeasures() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNodeWithGoal)); - assertThat(dataPoints.size(), equalTo(0)); + + assertThat(mapper.asDataPoints(responseNodeWithGoal).size(), equalTo(0)); } //TODO: Refactor this out with an "expectedProperties" dictionary for all the inputs and then one for all // Withings points public void testDataPoint(DataPoint testDataPoint, double massValue, String offsetTimeString, long externalId) { - BodyWeight.Builder bodyWeightExpectedMeasureBuilder = - new BodyWeight.Builder(new MassUnitValue(MassUnit.KILOGRAM, massValue)); - bodyWeightExpectedMeasureBuilder.setEffectiveTimeFrame(OffsetDateTime.parse(offsetTimeString)); - BodyWeight bodyWeightExpected = bodyWeightExpectedMeasureBuilder.build(); + + BodyWeight bodyWeightExpected = new BodyWeight.Builder(new MassUnitValue(KILOGRAM, massValue)) + .setEffectiveTimeFrame(OffsetDateTime.parse(offsetTimeString)) + .build(); assertThat(testDataPoint.getBody(), equalTo(bodyWeightExpected)); DataPointAcquisitionProvenance testProvenance = testDataPoint.getHeader().getAcquisitionProvenance(); + assertThat(testProvenance.getSourceName(), equalTo(RESOURCE_API_SOURCE_NAME)); assertThat(testProvenance.getModality(), equalTo(SENSED)); + Long expectedExternalId = (Long) testDataPoint.getHeader().getAcquisitionProvenance().getAdditionalProperties() .get("external_id"); + assertThat(expectedExternalId, equalTo(externalId)); - assertThat(testDataPoint.getHeader().getBodySchemaId(), equalTo(BodyWeight.SCHEMA_ID)); + assertThat(testDataPoint.getHeader().getBodySchemaId(), equalTo(SCHEMA_ID)); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsDailyCaloriesBurnedDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsDailyCaloriesBurnedDataPointMapperUnitTests.java index 8fa59734..94d32d63 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsDailyCaloriesBurnedDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsDailyCaloriesBurnedDataPointMapperUnitTests.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode; import org.openmhealth.schema.domain.omh.*; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -31,10 +30,14 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.KcalUnit.*; +import static org.openmhealth.schema.domain.omh.TimeInterval.*; import static org.openmhealth.shim.withings.mapper.WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME; -// TODO clean up +/** + * @author Chris Schaefbauer + */ public class WithingsDailyCaloriesBurnedDataPointMapperUnitTests extends DataPointMapperUnitTests { private JsonNode responseNode; @@ -42,20 +45,21 @@ public class WithingsDailyCaloriesBurnedDataPointMapperUnitTests extends DataPoi @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("/org/openmhealth/shim/withings/mapper/withings-activity-measures.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + + responseNode = asJsonNode("/org/openmhealth/shim/withings/mapper/withings-activity-measures.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(4)); + + assertThat(mapper.asDataPoints(singletonList(responseNode)).size(), equalTo(4)); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + + List> dataPoints = mapper.asDataPoints(responseNode); + testDailyCaloriesBurnedDataPoint(dataPoints.get(0), 139, "2015-06-18T00:00:00-07:00", "2015-06-19T00:00:00-07:00"); testDailyCaloriesBurnedDataPoint(dataPoints.get(1), 130, "2015-06-19T00:00:00-07:00", @@ -64,19 +68,18 @@ public void asDataPointsShouldReturnCorrectDataPoints() { "2015-06-21T00:00:00-07:00"); testDailyCaloriesBurnedDataPoint(dataPoints.get(3), 99, "2015-02-21T00:00:00-08:00", "2015-02-22T00:00:00-08:00"); - } public void testDailyCaloriesBurnedDataPoint(DataPoint caloriesBurnedDataPoint, long expectedCaloriesBurnedValue, String expectedDateString, String expectedEndDateString) { - CaloriesBurned.Builder expectedCaloriesBurnedBuilder = - new CaloriesBurned.Builder(new KcalUnitValue(KcalUnit.KILOCALORIE, expectedCaloriesBurnedValue)); - expectedCaloriesBurnedBuilder.setEffectiveTimeFrame( - TimeInterval.ofStartDateTimeAndEndDateTime(OffsetDateTime.parse(expectedDateString), - OffsetDateTime.parse(expectedEndDateString))); - CaloriesBurned testCaloriesBurned = caloriesBurnedDataPoint.getBody(); - CaloriesBurned expectedCaloriesBurned = expectedCaloriesBurnedBuilder.build(); - assertThat(testCaloriesBurned, equalTo(expectedCaloriesBurned)); + + CaloriesBurned expectedCaloriesBurned = + new CaloriesBurned.Builder(new KcalUnitValue(KILOCALORIE, expectedCaloriesBurnedValue)) + .setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime(OffsetDateTime.parse(expectedDateString), + OffsetDateTime.parse(expectedEndDateString))) + .build(); + + assertThat(caloriesBurnedDataPoint.getBody(), equalTo(expectedCaloriesBurned)); assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED)); assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getSourceName(), equalTo( RESOURCE_API_SOURCE_NAME)); diff --git a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsDailyStepCountDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsDailyStepCountDataPointMapperUnitTests.java index dff0e2af..9ea4220a 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsDailyStepCountDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsDailyStepCountDataPointMapperUnitTests.java @@ -21,7 +21,6 @@ import org.openmhealth.schema.domain.omh.StepCount; import org.openmhealth.schema.domain.omh.TimeInterval; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -33,10 +32,14 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.StepCount.*; import static org.openmhealth.shim.withings.mapper.WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME; -// TODO clean up + +/** + * @author Chris Schaefbauer + */ public class WithingsDailyStepCountDataPointMapperUnitTests extends DataPointMapperUnitTests { @@ -45,21 +48,21 @@ public class WithingsDailyStepCountDataPointMapperUnitTests extends DataPointMap @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("/org/openmhealth/shim/withings/mapper/withings-activity-measures.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + + responseNode = asJsonNode("/org/openmhealth/shim/withings/mapper/withings-activity-measures.json"); } @Test public void asDataPointsReturnsCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(4)); + assertThat(mapper.asDataPoints(singletonList(responseNode)).size(), equalTo(4)); } @Test public void asDataPointsReturnsCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + + List> dataPoints = mapper.asDataPoints(responseNode); + testDailyStepCountDataPoint(dataPoints.get(0), 2934, "2015-06-18T00:00:00-07:00", "2015-06-19T00:00:00-07:00"); testDailyStepCountDataPoint(dataPoints.get(1), 2600, "2015-06-19T00:00:00-07:00", "2015-06-20T00:00:00-07:00"); testDailyStepCountDataPoint(dataPoints.get(2), 5458, "2015-06-20T00:00:00-07:00", "2015-06-21T00:00:00-07:00"); @@ -68,19 +71,20 @@ public void asDataPointsReturnsCorrectDataPoints() { public void testDailyStepCountDataPoint(DataPoint stepCountDataPoint, long expectedStepCountValue, String expectedDateString, String expectedEndDateString) { - StepCount.Builder expectedStepCountBuilder = new StepCount.Builder(expectedStepCountValue); - expectedStepCountBuilder.setEffectiveTimeFrame(TimeInterval - .ofStartDateTimeAndEndDateTime(OffsetDateTime.parse(expectedDateString), - OffsetDateTime.parse(expectedEndDateString))); - //ofStartDateTimeAndDuration(OffsetDateTime.parse(expectedDateString),new DurationUnitValue( - //DurationUnit.DAY, 1))); + + StepCount expectedStepCount = new StepCount.Builder(expectedStepCountValue) + .setEffectiveTimeFrame(TimeInterval + .ofStartDateTimeAndEndDateTime(OffsetDateTime.parse(expectedDateString), + OffsetDateTime.parse(expectedEndDateString))) + .build(); + StepCount testStepCount = stepCountDataPoint.getBody(); - StepCount expectedStepCount = expectedStepCountBuilder.build(); + assertThat(testStepCount, equalTo(expectedStepCount)); assertThat(stepCountDataPoint.getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED)); assertThat(stepCountDataPoint.getHeader().getAcquisitionProvenance().getSourceName(), equalTo( RESOURCE_API_SOURCE_NAME)); - assertThat(stepCountDataPoint.getHeader().getBodySchemaId(), equalTo(StepCount.SCHEMA_ID)); + assertThat(stepCountDataPoint.getHeader().getBodySchemaId(), equalTo(SCHEMA_ID)); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsHeartRateDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsHeartRateDataPointMapperUnitTests.java index 880dc62e..d783ae7f 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsHeartRateDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsHeartRateDataPointMapperUnitTests.java @@ -22,19 +22,18 @@ import org.openmhealth.schema.domain.omh.DataPointModality; import org.openmhealth.schema.domain.omh.HeartRate; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.io.IOException; import java.time.OffsetDateTime; -import java.util.List; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.HeartRate.*; import static org.openmhealth.shim.withings.mapper.WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME; @@ -51,34 +50,26 @@ public class WithingsHeartRateDataPointMapperUnitTests extends DataPointMapperUn @BeforeTest public void initializeDataPoints() throws IOException { - ClassPathResource resource = - new ClassPathResource("/org/openmhealth/shim/withings/mapper/withings-body-measures.json"); - - responseNode = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("/org/openmhealth/shim/withings/mapper/withings-body-measures.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - - assertThat(dataPoints.size(), equalTo(3)); + assertThat(mapper.asDataPoints(singletonList(responseNode)).size(), equalTo(3)); } @Test public void asDataPointsShouldReturnCorrectSensedDataPoint() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - - assertThatDataPointMatches(dataPoints.get(0), 41.0, "2015-05-31T06:06:23Z", 366956482L, null, SENSED); + assertThatDataPointMatches(mapper.asDataPoints(responseNode).get(0), 41.0, "2015-05-31T06:06:23Z", 366956482L, + null, SENSED); } @Test public void asDataPointsShouldReturnCorrectSelfReportedDataPoint() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - - assertThatDataPointMatches(dataPoints.get(2), 47.0, "2015-02-26T21:57:17Z", 321858727L, + assertThatDataPointMatches(mapper.asDataPoints(responseNode).get(2), 47.0, "2015-02-26T21:57:17Z", 321858727L, "a few minutes after a walk", SELF_REPORTED); } @@ -86,8 +77,8 @@ private void assertThatDataPointMatches(DataPoint actualDataPoint, do String expectedDateTimeAsString, long expectedExternalId, String expectedComment, DataPointModality expectedModality) { - HeartRate.Builder expectedHeartRateBuilder = new HeartRate.Builder(expectedHeartRateValue); - expectedHeartRateBuilder.setEffectiveTimeFrame(OffsetDateTime.parse(expectedDateTimeAsString)); + HeartRate.Builder expectedHeartRateBuilder = new HeartRate.Builder(expectedHeartRateValue) + .setEffectiveTimeFrame(OffsetDateTime.parse(expectedDateTimeAsString)); if (expectedComment != null) { expectedHeartRateBuilder.setUserNotes(expectedComment); @@ -96,9 +87,10 @@ private void assertThatDataPointMatches(DataPoint actualDataPoint, do HeartRate expectedHeartRate = expectedHeartRateBuilder.build(); assertThat(actualDataPoint.getBody(), equalTo(expectedHeartRate)); - assertThat(actualDataPoint.getHeader().getBodySchemaId(), equalTo(HeartRate.SCHEMA_ID)); + assertThat(actualDataPoint.getHeader().getBodySchemaId(), equalTo(SCHEMA_ID)); DataPointAcquisitionProvenance actualProvenance = actualDataPoint.getHeader().getAcquisitionProvenance(); + assertThat(actualProvenance.getModality(), equalTo(expectedModality)); assertThat(actualProvenance.getSourceName(), equalTo(RESOURCE_API_SOURCE_NAME)); assertThat(actualProvenance.getAdditionalProperties().get("external_id"), equalTo(expectedExternalId)); diff --git a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsIntradayCaloriesBurnedDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsIntradayCaloriesBurnedDataPointMapperUnitTests.java index c125058e..92ad8a7c 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsIntradayCaloriesBurnedDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsIntradayCaloriesBurnedDataPointMapperUnitTests.java @@ -17,9 +17,11 @@ package org.openmhealth.shim.withings.mapper; import com.fasterxml.jackson.databind.JsonNode; -import org.openmhealth.schema.domain.omh.*; +import org.openmhealth.schema.domain.omh.CaloriesBurned; +import org.openmhealth.schema.domain.omh.DataPoint; +import org.openmhealth.schema.domain.omh.DurationUnitValue; +import org.openmhealth.schema.domain.omh.KcalUnitValue; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -27,16 +29,18 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +import static org.openmhealth.schema.domain.omh.CaloriesBurned.SCHEMA_ID; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.DurationUnit.SECOND; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; +import static org.openmhealth.schema.domain.omh.TimeInterval.ofStartDateTimeAndDuration; import static org.openmhealth.shim.withings.mapper.WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME; -// TODO clean up /** - * Created by Chris Schaefbauer on 7/5/15. + * @author Chris Schaefbauer */ public class WithingsIntradayCaloriesBurnedDataPointMapperUnitTests extends DataPointMapperUnitTests { @@ -45,45 +49,42 @@ public class WithingsIntradayCaloriesBurnedDataPointMapperUnitTests extends Data @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("/org/openmhealth/shim/withings/mapper/withings-intraday-activity.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + + responseNode = asJsonNode("/org/openmhealth/shim/withings/mapper/withings-intraday-activity.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(4)); + + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(4)); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + + List> dataPoints = mapper.asDataPoints(responseNode); + testIntradayCaloriesBurnedDataPoint(dataPoints.get(0), 1, "2015-06-20T00:04:00Z", 60L); testIntradayCaloriesBurnedDataPoint(dataPoints.get(1), 2, "2015-06-20T00:29:00Z", 60L); testIntradayCaloriesBurnedDataPoint(dataPoints.get(2), 1, "2015-06-20T00:30:00Z", 60L); testIntradayCaloriesBurnedDataPoint(dataPoints.get(3), 7, "2015-06-20T00:41:00Z", 60L); - - } public void testIntradayCaloriesBurnedDataPoint(DataPoint caloriesBurnedDataPoint, long expectedCaloriesBurnedValue, String expectedDateString, Long expectedDuration) { - CaloriesBurned.Builder expectedCaloriesBurnedBuilder = - new CaloriesBurned.Builder(new KcalUnitValue(KcalUnit.KILOCALORIE, expectedCaloriesBurnedValue)); - - expectedCaloriesBurnedBuilder.setEffectiveTimeFrame( - TimeInterval.ofStartDateTimeAndDuration(OffsetDateTime.parse(expectedDateString), new DurationUnitValue( - DurationUnit.SECOND, expectedDuration))); - CaloriesBurned testCaloriesBurned = caloriesBurnedDataPoint.getBody(); - CaloriesBurned expectedCaloriesBurned = expectedCaloriesBurnedBuilder.build(); - assertThat(testCaloriesBurned, equalTo(expectedCaloriesBurned)); + + CaloriesBurned expectedCaloriesBurned = + new CaloriesBurned.Builder(new KcalUnitValue(KILOCALORIE, expectedCaloriesBurnedValue)) + .setEffectiveTimeFrame( + ofStartDateTimeAndDuration(OffsetDateTime.parse(expectedDateString), + new DurationUnitValue(SECOND, expectedDuration))).build(); + + assertThat(caloriesBurnedDataPoint.getBody(), equalTo(expectedCaloriesBurned)); assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED)); assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getSourceName(), equalTo( RESOURCE_API_SOURCE_NAME)); - assertThat(caloriesBurnedDataPoint.getHeader().getBodySchemaId(), equalTo(CaloriesBurned.SCHEMA_ID)); - + assertThat(caloriesBurnedDataPoint.getHeader().getBodySchemaId(), equalTo(SCHEMA_ID)); } } diff --git a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsIntradayStepCountDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsIntradayStepCountDataPointMapperUnitTests.java index 784d7921..eb63de62 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsIntradayStepCountDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsIntradayStepCountDataPointMapperUnitTests.java @@ -17,9 +17,10 @@ package org.openmhealth.shim.withings.mapper; import com.fasterxml.jackson.databind.JsonNode; -import org.openmhealth.schema.domain.omh.*; +import org.openmhealth.schema.domain.omh.DataPoint; +import org.openmhealth.schema.domain.omh.DurationUnitValue; +import org.openmhealth.schema.domain.omh.StepCount; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -31,12 +32,14 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.DurationUnit.SECOND; +import static org.openmhealth.schema.domain.omh.StepCount.SCHEMA_ID; +import static org.openmhealth.schema.domain.omh.TimeInterval.ofStartDateTimeAndDuration; import static org.openmhealth.shim.withings.mapper.WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME; -// TODO clean up /** - * Created by Chris Schaefbauer on 7/2/15. + * @author Chris Schaefbauer */ public class WithingsIntradayStepCountDataPointMapperUnitTests extends DataPointMapperUnitTests { @@ -45,21 +48,21 @@ public class WithingsIntradayStepCountDataPointMapperUnitTests extends DataPoint @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("/org/openmhealth/shim/withings/mapper/withings-intraday-activity.json"); - responseNode = objectMapper.readTree(resource.getInputStream()); + + responseNode = asJsonNode("/org/openmhealth/shim/withings/mapper/withings-intraday-activity.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(4)); + assertThat(mapper.asDataPoints(singletonList(responseNode)).size(), equalTo(4)); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); + + List> dataPoints = mapper.asDataPoints(responseNode); + testIntradayStepCountDataPoint(dataPoints.get(0), 21, "2015-06-20T00:04:00Z", 60L); testIntradayStepCountDataPoint(dataPoints.get(1), 47, "2015-06-20T00:29:00Z", 60L); testIntradayStepCountDataPoint(dataPoints.get(2), 20, "2015-06-20T00:30:00Z", 60L); @@ -68,17 +71,19 @@ public void asDataPointsShouldReturnCorrectDataPoints() { public void testIntradayStepCountDataPoint(DataPoint stepCountDataPoint, long expectedStepCountValue, String expectedDateString, Long expectedDuration) { - StepCount.Builder expectedStepCountBuilder = new StepCount.Builder(expectedStepCountValue); - expectedStepCountBuilder.setEffectiveTimeFrame( - TimeInterval.ofStartDateTimeAndDuration(OffsetDateTime.parse(expectedDateString), new DurationUnitValue( - DurationUnit.SECOND, expectedDuration))); + + StepCount expectedStepCount = new StepCount.Builder(expectedStepCountValue).setEffectiveTimeFrame( + ofStartDateTimeAndDuration(OffsetDateTime.parse(expectedDateString), + new DurationUnitValue(SECOND, expectedDuration))) + .build(); + StepCount testStepCount = stepCountDataPoint.getBody(); - StepCount expectedStepCount = expectedStepCountBuilder.build(); + assertThat(testStepCount, equalTo(expectedStepCount)); assertThat(stepCountDataPoint.getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED)); assertThat(stepCountDataPoint.getHeader().getAcquisitionProvenance().getSourceName(), equalTo( RESOURCE_API_SOURCE_NAME)); - assertThat(stepCountDataPoint.getHeader().getBodySchemaId(), equalTo(StepCount.SCHEMA_ID)); + assertThat(stepCountDataPoint.getHeader().getBodySchemaId(), equalTo(SCHEMA_ID)); } diff --git a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsSleepDurationDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsSleepDurationDataPointMapperUnitTests.java index 02985c53..d2bdbdf6 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsSleepDurationDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/withings/mapper/WithingsSleepDurationDataPointMapperUnitTests.java @@ -17,9 +17,11 @@ package org.openmhealth.shim.withings.mapper; import com.fasterxml.jackson.databind.JsonNode; -import org.openmhealth.schema.domain.omh.*; +import org.openmhealth.schema.domain.omh.DataPoint; +import org.openmhealth.schema.domain.omh.DataPointAcquisitionProvenance; +import org.openmhealth.schema.domain.omh.DurationUnitValue; +import org.openmhealth.schema.domain.omh.SleepDuration; import org.openmhealth.shim.common.mapper.DataPointMapperUnitTests; -import org.springframework.core.io.ClassPathResource; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -27,16 +29,16 @@ import java.time.OffsetDateTime; import java.util.List; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; import static org.openmhealth.schema.domain.omh.DurationUnit.SECOND; +import static org.openmhealth.schema.domain.omh.SleepDuration.*; +import static org.openmhealth.schema.domain.omh.TimeInterval.ofStartDateTimeAndEndDateTime; -// TODO clean this up /** - * Created by Chris Schaefbauer on 7/6/15. + * @author Chris Schaefbauer */ public class WithingsSleepDurationDataPointMapperUnitTests extends DataPointMapperUnitTests { @@ -46,45 +48,42 @@ public class WithingsSleepDurationDataPointMapperUnitTests extends DataPointMapp @BeforeTest public void initializeResponseNode() throws IOException { - ClassPathResource resource = - new ClassPathResource("org/openmhealth/shim/withings/mapper/withings-sleep-summary.json"); - - responseNode = objectMapper.readTree(resource.getInputStream()); + responseNode = asJsonNode("org/openmhealth/shim/withings/mapper/withings-sleep-summary.json"); } @Test public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - assertThat(dataPoints.size(), equalTo(1)); + assertThat(mapper.asDataPoints(responseNode).size(), equalTo(1)); } @Test public void asDataPointsShouldReturnCorrectDataPoints() { - List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); - SleepDuration.Builder sleepDurationBuilder = new SleepDuration.Builder(new DurationUnitValue(SECOND, 37460)); + List> dataPoints = mapper.asDataPoints(responseNode); - OffsetDateTime offsetStartDateTime = OffsetDateTime.parse("2014-09-12T11:34:19Z"); - OffsetDateTime offsetEndDateTime = OffsetDateTime.parse("2014-09-12T17:22:57Z"); - sleepDurationBuilder.setEffectiveTimeFrame( - TimeInterval.ofStartDateTimeAndEndDateTime(offsetStartDateTime, offsetEndDateTime)); + SleepDuration expectedSleepDuration = new SleepDuration.Builder(new DurationUnitValue(SECOND, 37460)) + .setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime(OffsetDateTime.parse("2014-09-12T11:34:19Z"), + OffsetDateTime.parse("2014-09-12T17:22:57Z"))) + .build(); - SleepDuration expectedSleepDuration = sleepDurationBuilder.build(); expectedSleepDuration.setAdditionalProperty("wakeup_count", 3); expectedSleepDuration.setAdditionalProperty("light_sleep_duration", new DurationUnitValue(SECOND, 18540)); expectedSleepDuration.setAdditionalProperty("deep_sleep_duration", new DurationUnitValue(SECOND, 8460)); expectedSleepDuration.setAdditionalProperty("rem_sleep_duration", new DurationUnitValue(SECOND, 10460)); expectedSleepDuration.setAdditionalProperty("duration_to_sleep", new DurationUnitValue(SECOND, 420)); + assertThat(dataPoints.get(0).getBody(), equalTo(expectedSleepDuration)); assertThat(dataPoints.get(0).getBody().getAdditionalProperties(), equalTo(expectedSleepDuration.getAdditionalProperties())); + DataPointAcquisitionProvenance acquisitionProvenance = dataPoints.get(0).getHeader().getAcquisitionProvenance(); + assertThat(acquisitionProvenance.getSourceName(), equalTo(WithingsDataPointMapper.RESOURCE_API_SOURCE_NAME)); assertThat(acquisitionProvenance.getModality(), equalTo(SENSED)); assertThat(acquisitionProvenance.getAdditionalProperties().get("external_id"), equalTo(16616514L)); assertThat(acquisitionProvenance.getAdditionalProperties().get("device_name"), equalTo("Aura")); - assertThat(dataPoints.get(0).getHeader().getBodySchemaId(), equalTo(SleepDuration.SCHEMA_ID)); + assertThat(dataPoints.get(0).getHeader().getBodySchemaId(), equalTo(SCHEMA_ID)); } } From 9547a108393175d1ef6879b48b748dae0590f922 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Fri, 5 Feb 2016 16:45:16 -0700 Subject: [PATCH 11/18] Map calories burned in Misfit physical activity --- .../mapper/MisfitPhysicalActivityDataPointMapper.java | 9 +++++---- .../MisfitPhysicalActivityDataPointMapperUnitTests.java | 9 +++++++++ .../openmhealth/shim/misfit/mapper/misfit-sessions.json | 1 - 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/shim-server/src/main/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapper.java index 950b13b9..f1ff3730 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapper.java +++ b/shim-server/src/main/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapper.java @@ -17,16 +17,14 @@ package org.openmhealth.shim.misfit.mapper; import com.fasterxml.jackson.databind.JsonNode; -import org.openmhealth.schema.domain.omh.DataPoint; -import org.openmhealth.schema.domain.omh.DurationUnitValue; -import org.openmhealth.schema.domain.omh.LengthUnitValue; -import org.openmhealth.schema.domain.omh.PhysicalActivity; +import org.openmhealth.schema.domain.omh.*; import java.time.OffsetDateTime; import java.util.Optional; import static com.google.common.base.Preconditions.checkNotNull; import static org.openmhealth.schema.domain.omh.DurationUnit.SECOND; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; import static org.openmhealth.schema.domain.omh.LengthUnit.MILE; import static org.openmhealth.schema.domain.omh.TimeInterval.ofStartDateTimeAndDuration; import static org.openmhealth.shim.common.mapper.JsonNodeMappingSupport.*; @@ -69,6 +67,9 @@ public Optional> asDataPoint(JsonNode sessionNode) { builder.setEffectiveTimeFrame(ofStartDateTimeAndDuration(startDateTime.get(), durationUnitValue)); } + asOptionalBigDecimal(sessionNode, "calories") + .ifPresent(calories -> builder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 96.8))); + PhysicalActivity measure = builder.build(); Optional externalId = asOptionalString(sessionNode, "id"); diff --git a/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapperUnitTests.java index b85ec027..7e4fcaea 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/misfit/mapper/MisfitPhysicalActivityDataPointMapperUnitTests.java @@ -13,10 +13,12 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; import static org.openmhealth.schema.domain.omh.DurationUnit.SECOND; +import static org.openmhealth.schema.domain.omh.KcalUnit.KILOCALORIE; import static org.openmhealth.schema.domain.omh.LengthUnit.MILE; import static org.openmhealth.shim.misfit.mapper.MisfitDataPointMapper.RESOURCE_API_SOURCE_NAME; @@ -60,6 +62,7 @@ public void asDataPointsShouldReturnCorrectDataPoints() { PhysicalActivity physicalActivity = new PhysicalActivity.Builder("Walking") .setDistance(new LengthUnitValue(MILE, 0.9371)) .setEffectiveTimeFrame(effectiveTimeInterval) + .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 96.8)) .build(); DataPoint firstDataPoint = dataPoints.get(0); @@ -75,6 +78,12 @@ public void asDataPointsShouldReturnCorrectDataPoints() { equalTo("552eab896c59ae1f7300003e")); } + @Test + public void asDataPointsShouldReturnPhysicalActivityWithoutCaloriesBurnedWhenCaloriesMissing() { + + assertThat(mapper.asDataPoints(responseNode).get(1).getBody().getCaloriesBurned(), nullValue()); + } + @Test public void asDataPointsShouldReturnEmptyListIfEmptyResponse() throws IOException { diff --git a/shim-server/src/test/resources/org/openmhealth/shim/misfit/mapper/misfit-sessions.json b/shim-server/src/test/resources/org/openmhealth/shim/misfit/mapper/misfit-sessions.json index 38536f8c..f4447581 100644 --- a/shim-server/src/test/resources/org/openmhealth/shim/misfit/mapper/misfit-sessions.json +++ b/shim-server/src/test/resources/org/openmhealth/shim/misfit/mapper/misfit-sessions.json @@ -17,7 +17,6 @@ "duration": 420, "points": 0.8, "steps": 8, - "calories": 0.3, "distance": 0.003 }, { From 8c853b3770bf0f28fc74176c5d1ac4082c328597 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Tue, 9 Feb 2016 09:08:29 -0700 Subject: [PATCH 12/18] Bump schema-sdk version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 553cfc86..d55c0e56 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ subprojects { ext { javaVersion = 1.8 shimmerVersion = '0.5.0-SNAPSHOT' - omhSchemaSdkVersion = '1.0.4' + omhSchemaSdkVersion = '1.0.5' } sourceCompatibility = javaVersion From c0549a3968362d205c60e137c402da1f7ea0f678 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Tue, 9 Feb 2016 10:20:21 -0700 Subject: [PATCH 13/18] Map oxygen saturation data from iHealth --- .../IHealthBloodOxygenDataPointMapper.java | 79 ++++++++++++ ...thBloodOxygenDataPointMapperUnitTests.java | 114 ++++++++++++++++++ .../ihealth-spo2-no-oxygen-saturation.json | 22 ++++ 3 files changed, 215 insertions(+) create mode 100644 shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapper.java create mode 100644 shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapperUnitTests.java create mode 100644 shim-server/src/test/resources/org/openmhealth/shim/ihealth/mapper/ihealth-spo2-no-oxygen-saturation.json diff --git a/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapper.java new file mode 100644 index 00000000..7785c9a1 --- /dev/null +++ b/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapper.java @@ -0,0 +1,79 @@ +/* + * 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.shim.ihealth.mapper; + +import com.fasterxml.jackson.databind.JsonNode; +import org.openmhealth.schema.domain.omh.DataPoint; +import org.openmhealth.schema.domain.omh.OxygenSaturation; +import org.openmhealth.schema.domain.omh.TypedUnitValue; + +import java.math.BigDecimal; +import java.util.Optional; + +import static org.openmhealth.schema.domain.omh.OxygenSaturation.MeasurementMethod.PULSE_OXIMETRY; +import static org.openmhealth.schema.domain.omh.OxygenSaturation.MeasurementSystem.PERIPHERAL_CAPILLARY; +import static org.openmhealth.schema.domain.omh.PercentUnit.PERCENT; +import static org.openmhealth.shim.common.mapper.JsonNodeMappingSupport.asRequiredBigDecimal; + + +/** + * A mapper that translates responses from the iHealth /spo2.json endpoint into {@link OxygenSaturation} + * measures. + * + * @author Chris Schaefbauer + * @see endpoint + * documentation + */ +public class IHealthBloodOxygenDataPointMapper extends IHealthDataPointMapper { + + @Override + protected String getListNodeName() { + return "BODataList"; + } + + @Override + protected Optional getMeasureUnitNodeName() { + + return Optional.empty(); + } + + @Override + protected Optional> asDataPoint(JsonNode listEntryNode, + Integer measureUnitMagicNumber) { + + BigDecimal bloodOxygenValue = asRequiredBigDecimal(listEntryNode, "BO"); + + // iHealth has stated that missing values would most likely be represented as a 0 value for the field + if (bloodOxygenValue.compareTo(BigDecimal.ZERO) == 0) { + + return Optional.empty(); + } + + OxygenSaturation.Builder oxygenSaturationBuilder = + new OxygenSaturation.Builder(new TypedUnitValue<>(PERCENT, bloodOxygenValue)) + .setMeasurementMethod(PULSE_OXIMETRY) + .setMeasurementSystem(PERIPHERAL_CAPILLARY); + + + getEffectiveTimeFrameAsDateTime(listEntryNode).ifPresent(oxygenSaturationBuilder::setEffectiveTimeFrame); + getUserNoteIfExists(listEntryNode).ifPresent(oxygenSaturationBuilder::setUserNotes); + + OxygenSaturation oxygenSaturation = oxygenSaturationBuilder.build(); + + return Optional.of(new DataPoint<>(createDataPointHeader(listEntryNode, oxygenSaturation), oxygenSaturation)); + } +} diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapperUnitTests.java new file mode 100644 index 00000000..e4207800 --- /dev/null +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapperUnitTests.java @@ -0,0 +1,114 @@ +/* + * 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.shim.ihealth.mapper; + +import com.fasterxml.jackson.databind.JsonNode; +import org.openmhealth.schema.domain.omh.DataPoint; +import org.openmhealth.schema.domain.omh.OxygenSaturation; +import org.openmhealth.schema.domain.omh.TypedUnitValue; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.time.OffsetDateTime; +import java.util.List; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED; +import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED; +import static org.openmhealth.schema.domain.omh.OxygenSaturation.*; +import static org.openmhealth.schema.domain.omh.OxygenSaturation.MeasurementMethod.PULSE_OXIMETRY; +import static org.openmhealth.schema.domain.omh.OxygenSaturation.MeasurementSystem.*; +import static org.openmhealth.schema.domain.omh.PercentUnit.PERCENT; +import static org.openmhealth.shim.ihealth.mapper.IHealthDataPointMapper.*; + + +/** + * @author Chris Schaefbauer + */ +public class IHealthBloodOxygenDataPointMapperUnitTests extends IHealthDataPointMapperUnitTests { + + private JsonNode responseNode; + private final IHealthBloodOxygenDataPointMapper mapper = new IHealthBloodOxygenDataPointMapper(); + private List> dataPoints; + + @BeforeClass + public void initializeResponseNode() throws IOException { + + responseNode = asJsonNode("org/openmhealth/shim/ihealth/mapper/ihealth-spo2.json"); + } + + @BeforeMethod + public void initializeDataPoints() { + + dataPoints = mapper.asDataPoints(responseNode); + } + + @Test + public void asDataPointsShouldReturnCorrectNumberOfDataPoints() { + + assertThat(dataPoints.size(), equalTo(2)); + } + + @Test + public void asDataPointsShouldReturnCorrectSensedDataPoints() { + + OxygenSaturation expectedOxygenSaturation = new OxygenSaturation.Builder(new TypedUnitValue<>(PERCENT, 99)) + .setMeasurementMethod(PULSE_OXIMETRY) + .setMeasurementSystem(PERIPHERAL_CAPILLARY) + .setEffectiveTimeFrame(OffsetDateTime.parse("2015-09-23T15:46:00-06:00")) + .build(); + + assertThat(dataPoints.get(0).getBody(), equalTo(expectedOxygenSaturation)); + assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED)); + assertThat(dataPoints.get(0).getHeader().getBodySchemaId(), equalTo(SCHEMA_ID)); + assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getSourceName(), + equalTo(RESOURCE_API_SOURCE_NAME)); + } + + @Test + public void asDataPointsShouldReturnCorrectSelfReportedAcquisitionProvenance() { + + assertThat(dataPoints.get(1).getHeader().getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED)); + } + + @Test + public void asDataPointsShouldReturnCorrectUserNotesWithDataPoints() { + + assertThat(dataPoints.get(0).getBody().getUserNotes(), nullValue()); + assertThat(dataPoints.get(1).getBody().getUserNotes(), equalTo("Satch on satch ")); + } + + @Test + public void asDataPointsShouldReturnNoDataPointsWhenOxygenSaturationListIsEmpty() { + + assertThat(mapper.asDataPoints(asJsonNode("/org/openmhealth/shim/ihealth/mapper/ihealth-spo2-empty.json")), + is(empty())); + } + + @Test + public void asDataPointsShouldReturnNoDataPointWhenOxygenSaturationDataIsNotPresent() throws IOException { + + assertThat(mapper.asDataPoints( + asJsonNode("org/openmhealth/shim/ihealth/mapper/ihealth-spo2-no-oxygen-saturation.json")), is(empty())); + } +} diff --git a/shim-server/src/test/resources/org/openmhealth/shim/ihealth/mapper/ihealth-spo2-no-oxygen-saturation.json b/shim-server/src/test/resources/org/openmhealth/shim/ihealth/mapper/ihealth-spo2-no-oxygen-saturation.json new file mode 100644 index 00000000..8410987a --- /dev/null +++ b/shim-server/src/test/resources/org/openmhealth/shim/ihealth/mapper/ihealth-spo2-no-oxygen-saturation.json @@ -0,0 +1,22 @@ +{ + "BODataList": [ + { + "BO": 0, + "DataID": "d7fb9db14b0fc3e8e1635720c28bda64", + "DataSource": "FromDevice", + "HR": 0, + "LastChangeTime": 1443044760, + "Lat": 0, + "Lon": 0, + "MDate": 1443023160, + "Note": "", + "TimeZone": "-0600" + } + ], + "CurrentRecordCount": 1, + "NextPageUrl": "", + "PageLength": 50, + "PageNumber": 1, + "PrevPageUrl": "", + "RecordCount": 1 +} From 127622b08a98d16e75052b502341eb040cf3b8b6 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Tue, 9 Feb 2016 10:56:20 -0700 Subject: [PATCH 14/18] Rename oxygen saturation iHealth mapper --- ...apper.java => IHealthOxygenSaturationDataPointMapper.java} | 2 +- ...a => IHealthOxygenSaturationDataPointMapperUnitTests.java} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/{IHealthBloodOxygenDataPointMapper.java => IHealthOxygenSaturationDataPointMapper.java} (96%) rename shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/{IHealthBloodOxygenDataPointMapperUnitTests.java => IHealthOxygenSaturationDataPointMapperUnitTests.java} (95%) diff --git a/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapper.java similarity index 96% rename from shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapper.java rename to shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapper.java index 7785c9a1..903af7b1 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapper.java +++ b/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapper.java @@ -38,7 +38,7 @@ * @see endpoint * documentation */ -public class IHealthBloodOxygenDataPointMapper extends IHealthDataPointMapper { +public class IHealthOxygenSaturationDataPointMapper extends IHealthDataPointMapper { @Override protected String getListNodeName() { diff --git a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapperUnitTests.java similarity index 95% rename from shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapperUnitTests.java rename to shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapperUnitTests.java index e4207800..bc096ee7 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthBloodOxygenDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapperUnitTests.java @@ -45,10 +45,10 @@ /** * @author Chris Schaefbauer */ -public class IHealthBloodOxygenDataPointMapperUnitTests extends IHealthDataPointMapperUnitTests { +public class IHealthOxygenSaturationDataPointMapperUnitTests extends IHealthDataPointMapperUnitTests { private JsonNode responseNode; - private final IHealthBloodOxygenDataPointMapper mapper = new IHealthBloodOxygenDataPointMapper(); + private final IHealthOxygenSaturationDataPointMapper mapper = new IHealthOxygenSaturationDataPointMapper(); private List> dataPoints; @BeforeClass From 3e5a99616cf3249030ae06b6444afd4b3c81b788 Mon Sep 17 00:00:00 2001 From: Chris Schaefbauer Date: Tue, 9 Feb 2016 18:10:16 -0700 Subject: [PATCH 15/18] Add oxygen saturation to iHealth shim --- .../org/openmhealth/shim/ihealth/IHealthShim.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/shim-server/src/main/java/org/openmhealth/shim/ihealth/IHealthShim.java b/shim-server/src/main/java/org/openmhealth/shim/ihealth/IHealthShim.java index 31250005..e074af44 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/ihealth/IHealthShim.java +++ b/shim-server/src/main/java/org/openmhealth/shim/ihealth/IHealthShim.java @@ -136,7 +136,8 @@ public ShimDataType[] getShimDataTypes() { BODY_MASS_INDEX, HEART_RATE, STEP_COUNT, - SLEEP_DURATION + SLEEP_DURATION, + OXYGEN_SATURATION }; } @@ -164,7 +165,8 @@ public enum IHealthDataTypes implements ShimDataType { BODY_MASS_INDEX(singletonList("weight.json")), HEART_RATE(newArrayList("bp.json", "spo2.json")), STEP_COUNT(singletonList("activity.json")), - SLEEP_DURATION(singletonList("sleep.json")); + SLEEP_DURATION(singletonList("sleep.json")), + OXYGEN_SATURATION(singletonList("spo2.json")); private List endPoint; @@ -296,6 +298,9 @@ else if (endPoint == "spo2.json") { mapper = new IHealthBloodOxygenEndpointHeartRateDataPointMapper(); break; } + case OXYGEN_SATURATION: + mapper = new IHealthOxygenSaturationDataPointMapper(); + break; default: throw new UnsupportedOperationException(); } @@ -339,6 +344,8 @@ private List getSvValues(IHealthDataTypes dataType) { return singletonList(serialValues.get("sleepSV")); case HEART_RATE: return newArrayList(serialValues.get("bloodPressureSV"), serialValues.get("spo2SV")); + case OXYGEN_SATURATION: + return singletonList(serialValues.get("spo2SV")); default: throw new UnsupportedOperationException(); } From 05c737782dd61b1ac035d2f777071ad5e344d921 Mon Sep 17 00:00:00 2001 From: Emerson Farrugia Date: Mon, 22 Feb 2016 16:39:03 +0100 Subject: [PATCH 16/18] Bump Spring Boot version to 1.3.2 --- shim-server/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shim-server/build.gradle b/shim-server/build.gradle index b5d8d9ee..7c310e0b 100644 --- a/shim-server/build.gradle +++ b/shim-server/build.gradle @@ -5,7 +5,7 @@ buildscript { } ext { - springBootVersion = "1.3.1.RELEASE" + springBootVersion = "1.3.2.RELEASE" } dependencies { From b5f4cb6eaa7733800b81954573e7521cd2eb18ac Mon Sep 17 00:00:00 2001 From: Emerson Farrugia Date: Tue, 23 Feb 2016 17:35:06 +0100 Subject: [PATCH 17/18] Clean up formatting --- .../FitbitPhysicalActivityDataPointMapper.java | 4 ++-- .../IHealthOxygenSaturationDataPointMapper.java | 5 ++--- .../JawbonePhysicalActivityDataPointMapper.java | 16 +++++++++------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/shim-server/src/main/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapper.java index 0169d907..fd463d66 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapper.java +++ b/shim-server/src/main/java/org/openmhealth/shim/fitbit/mapper/FitbitPhysicalActivityDataPointMapper.java @@ -96,8 +96,8 @@ protected Optional> asDataPoint(JsonNode node) { activityBuilder.setDistance(new LengthUnitValue(KILOMETER, distance.get())); } - asOptionalDouble(node, "calories").ifPresent(calories -> activityBuilder.setCaloriesBurned( - new KcalUnitValue(KILOCALORIE, calories))); + asOptionalDouble(node, "calories") + .ifPresent(calories -> activityBuilder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, calories))); PhysicalActivity measure = activityBuilder.build(); Optional externalId = asOptionalLong(node, "logId"); diff --git a/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapper.java index 903af7b1..bfe889bb 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapper.java +++ b/shim-server/src/main/java/org/openmhealth/shim/ihealth/mapper/IHealthOxygenSaturationDataPointMapper.java @@ -24,6 +24,7 @@ import java.math.BigDecimal; import java.util.Optional; +import static java.math.BigDecimal.ZERO; import static org.openmhealth.schema.domain.omh.OxygenSaturation.MeasurementMethod.PULSE_OXIMETRY; import static org.openmhealth.schema.domain.omh.OxygenSaturation.MeasurementSystem.PERIPHERAL_CAPILLARY; import static org.openmhealth.schema.domain.omh.PercentUnit.PERCENT; @@ -58,8 +59,7 @@ protected Optional> asDataPoint(JsonNode listEntryNo BigDecimal bloodOxygenValue = asRequiredBigDecimal(listEntryNode, "BO"); // iHealth has stated that missing values would most likely be represented as a 0 value for the field - if (bloodOxygenValue.compareTo(BigDecimal.ZERO) == 0) { - + if (bloodOxygenValue.compareTo(ZERO) == 0) { return Optional.empty(); } @@ -68,7 +68,6 @@ protected Optional> asDataPoint(JsonNode listEntryNo .setMeasurementMethod(PULSE_OXIMETRY) .setMeasurementSystem(PERIPHERAL_CAPILLARY); - getEffectiveTimeFrameAsDateTime(listEntryNode).ifPresent(oxygenSaturationBuilder::setEffectiveTimeFrame); getUserNoteIfExists(listEntryNode).ifPresent(oxygenSaturationBuilder::setUserNotes); diff --git a/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java index cd5e3267..7d0efb74 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java +++ b/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java @@ -111,20 +111,22 @@ protected Optional getMeasure(JsonNode workoutNode) { if (endTimestamp.isPresent() && durationInSec.isPresent() && timeZoneId.isPresent()) { - DurationUnitValue durationUnitValue = new DurationUnitValue(SECOND, durationInSec.get()); - OffsetDateTime endDateTime = ofInstant(ofEpochSecond(endTimestamp.get()), - JawboneDataPointMapper.getTimeZoneForTimestamp(workoutNode, endTimestamp.get())); + getTimeZoneForTimestamp(workoutNode, endTimestamp.get())); - builder.setEffectiveTimeFrame(ofEndDateTimeAndDuration(endDateTime, durationUnitValue)); + builder.setEffectiveTimeFrame( + ofEndDateTimeAndDuration(endDateTime, new DurationUnitValue(SECOND, durationInSec.get()))); } Optional totalCalories = asOptionalBigDecimal(workoutNode, "details.calories"); if (totalCalories.isPresent()) { - asOptionalBigDecimal(workoutNode, "details.bmr_calories").ifPresent(bmrCalories -> builder - .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, totalCalories.get().subtract(bmrCalories)))); + asOptionalBigDecimal(workoutNode, "details.bmr_calories") + .ifPresent(bmrCalories -> { + BigDecimal caloriesBurned = totalCalories.get().subtract(bmrCalories); + builder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, caloriesBurned)); + }); } asOptionalInteger(workoutNode, "details.intensity") @@ -165,7 +167,7 @@ public String getActivityName(@Nullable String title, @Nullable Integer workoutT */ public SelfReportedIntensity asSelfReportedIntensity(int intensityValue) { - switch ( intensityValue ) { + switch (intensityValue) { case 1: return LIGHT; case 2: From 01369fda3f9caf7c2e030991e71d198799e09d6d Mon Sep 17 00:00:00 2001 From: Emerson Farrugia Date: Tue, 23 Feb 2016 18:28:53 +0100 Subject: [PATCH 18/18] Bump versions for release --- build.gradle | 2 +- shim-server-ui/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index d55c0e56..8d5db565 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ subprojects { ext { javaVersion = 1.8 - shimmerVersion = '0.5.0-SNAPSHOT' + shimmerVersion = '0.4.3' omhSchemaSdkVersion = '1.0.5' } diff --git a/shim-server-ui/package.json b/shim-server-ui/package.json index 0bfcbc13..9a068095 100644 --- a/shim-server-ui/package.json +++ b/shim-server-ui/package.json @@ -1,6 +1,6 @@ { "name": "shim-server-ui", - "version": "0.5.0-SNAPSHOT", + "version": "0.4.3", "dependencies": {}, "devDependencies": { "grunt": "~0.4.5",