Added JSON tests for NewObservation.
This commit is contained in:
parent
0eeee408ec
commit
85cbc4d062
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
12
backend/src/test/resources/fixtures/NewObservation.json
Normal file
12
backend/src/test/resources/fixtures/NewObservation.json
Normal file
@ -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.\"}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user