From 85cbc4d062e4423a0405ef914a5e04108799010b Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Mon, 17 Sep 2018 13:56:43 +0100 Subject: [PATCH] Added JSON tests for NewObservation. --- .../Observations/api/NewObservation.java | 6 ++-- .../Observations/api/NewObservationTest.java | 30 +++++++++++++++++++ .../resources/fixtures/NewObservation.json | 12 ++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 backend/src/test/java/uk/co/neviyn/Observations/api/NewObservationTest.java create mode 100644 backend/src/test/resources/fixtures/NewObservation.json diff --git a/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java b/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java index c05f63e..0fc967a 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java @@ -2,12 +2,12 @@ package uk.co.neviyn.Observations.api; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; + +import lombok.*; @Data @NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PROTECTED) public class NewObservation { @NonNull diff --git a/backend/src/test/java/uk/co/neviyn/Observations/api/NewObservationTest.java b/backend/src/test/java/uk/co/neviyn/Observations/api/NewObservationTest.java new file mode 100644 index 0000000..1f3d8bf --- /dev/null +++ b/backend/src/test/java/uk/co/neviyn/Observations/api/NewObservationTest.java @@ -0,0 +1,30 @@ +package uk.co.neviyn.Observations.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.dropwizard.jackson.Jackson; +import org.junit.Test; + +import java.util.Arrays; + +import static io.dropwizard.testing.FixtureHelpers.fixture; +import static org.junit.Assert.*; + +public class NewObservationTest { + + private static final ObjectMapper mapper = Jackson.newObjectMapper(); + + private final NewObservation newObservation = new NewObservation(1, Arrays.asList(1, 2, 3), "A random thing made for testing.", + "INITIAL", 1, 2, 3, 4, 5, "{\"data\":\"Looks like there's nothing here.\"}"); + + @Test + public void serializesToJson() throws Exception { + final String expected = mapper.writeValueAsString(mapper.readValue(fixture("fixtures/NewObservation.json"), NewObservation.class)); + assertEquals(expected, mapper.writeValueAsString(newObservation)); + } + + @Test + public void deserializesFromJson() throws Exception { + assertEquals(newObservation, mapper.readValue(fixture("fixtures/NewObservation.json"), NewObservation.class)); + } + +} \ No newline at end of file diff --git a/backend/src/test/resources/fixtures/NewObservation.json b/backend/src/test/resources/fixtures/NewObservation.json new file mode 100644 index 0000000..237a7fa --- /dev/null +++ b/backend/src/test/resources/fixtures/NewObservation.json @@ -0,0 +1,12 @@ +{ + "siteId":1, + "tutorIds":[1,2,3], + "observed":"A random thing made for testing.", + "type":"INITIAL", + "monitoring":1, + "control":2, + "conservatism":3, + "teamwork":4, + "knowledge":5, + "rawData":"{\"data\":\"Looks like there's nothing here.\"}" +} \ No newline at end of file