use of org.sagebionetworks.bridge.json.BridgeObjectMapper in project BridgeServer2 by Sage-Bionetworks.
the class ActivityTest method canSerializeTaskActivity.
@Test
public void canSerializeTaskActivity() throws Exception {
Activity activity = new Activity.Builder().withGuid("actGuid").withLabel("Label").withLabelDetail("Label Detail").withTask("taskId").build();
BridgeObjectMapper mapper = BridgeObjectMapper.get();
String json = mapper.writeValueAsString(activity);
JsonNode node = mapper.readTree(json);
assertEquals(node.get("label").asText(), "Label");
assertEquals(node.get("labelDetail").asText(), "Label Detail");
assertEquals(node.get("activityType").asText(), "task");
assertEquals(node.get("task").get("identifier").asText(), "taskId");
assertEquals(node.get("guid").asText(), "actGuid");
assertEquals(node.get("type").asText(), "Activity");
JsonNode taskRef = node.get("task");
assertEquals(taskRef.get("identifier").asText(), "taskId");
assertEquals(taskRef.get("type").asText(), "TaskReference");
activity = mapper.readValue(json, Activity.class);
assertEquals(activity.getLabel(), "Label");
assertEquals(activity.getLabelDetail(), "Label Detail");
assertEquals(activity.getActivityType(), ActivityType.TASK);
assertEquals(activity.getTask().getIdentifier(), "taskId");
}
use of org.sagebionetworks.bridge.json.BridgeObjectMapper in project BridgeServer2 by Sage-Bionetworks.
the class ActivityTest method submittingJsonWithHrefWillNotBreak.
@Test
public void submittingJsonWithHrefWillNotBreak() throws Exception {
String oldJson = "{\"label\":\"Personal Health Survey\",\"ref\":\"https://webservices-staging.sagebridge.org/api/v2/surveys/ac1e57fd-5e8e-473f-b82f-bac7547b6783/revisions/published\",\"activityType\":\"survey\",\"survey\":{\"guid\":\"ac1e57fd-5e8e-473f-b82f-bac7547b6783\",\"href\":\"junk\",\"identifier\":\"identifier\",\"type\":\"SurveyReference\"},\"type\":\"Activity\"}";
BridgeObjectMapper mapper = BridgeObjectMapper.get();
Activity activity = mapper.readValue(oldJson, Activity.class);
assertNotEquals(activity.getSurvey().getHref(), "junk");
}
use of org.sagebionetworks.bridge.json.BridgeObjectMapper in project BridgeServer2 by Sage-Bionetworks.
the class ActivityTest method canSerializePublishedSurveyActivity.
@Test
public void canSerializePublishedSurveyActivity() throws Exception {
Activity activity = new Activity.Builder().withGuid("actGuid").withLabel("Label").withLabelDetail("Label Detail").withPublishedSurvey("identifier", "guid").build();
BridgeObjectMapper mapper = BridgeObjectMapper.get();
String json = mapper.writeValueAsString(activity);
JsonNode node = mapper.readTree(json);
assertEquals(node.get("label").asText(), "Label");
assertEquals(node.get("labelDetail").asText(), "Label Detail");
assertEquals(node.get("activityType").asText(), "survey");
String hrefString = node.get("survey").get("href").asText();
assertTrue(hrefString.matches("http[s]?://.*/v3/surveys/guid/revisions/published"));
assertEquals(node.get("guid").asText(), "actGuid");
assertEquals(node.get("type").asText(), "Activity");
JsonNode ref = node.get("survey");
assertEquals(ref.get("identifier").asText(), "identifier");
assertEquals(ref.get("guid").asText(), "guid");
String href = ref.get("href").asText();
assertTrue(href.matches("http[s]?://.*/v3/surveys/guid/revisions/published"));
assertEquals(ref.get("type").asText(), "SurveyReference");
activity = mapper.readValue(json, Activity.class);
assertEquals(activity.getLabel(), "Label");
assertEquals(activity.getLabelDetail(), "Label Detail");
assertEquals(activity.getActivityType(), ActivityType.SURVEY);
SurveyReference ref1 = activity.getSurvey();
assertEquals(ref1.getIdentifier(), "identifier");
assertNull(ref1.getCreatedOn(), "createdOn");
assertEquals(ref1.getGuid(), "guid");
assertTrue(ref1.getHref().matches("http[s]?://.*/v3/surveys/guid/revisions/published"));
}
use of org.sagebionetworks.bridge.json.BridgeObjectMapper in project BridgeServer2 by Sage-Bionetworks.
the class ActivityTest method canSerializeSurveyActivity.
@Test
public void canSerializeSurveyActivity() throws Exception {
Activity activity = new Activity.Builder().withGuid("actGuid").withLabel("Label").withLabelDetail("Label Detail").withSurvey("identifier", "guid", DateTime.parse("2015-01-01T10:10:10Z")).build();
BridgeObjectMapper mapper = BridgeObjectMapper.get();
String json = mapper.writeValueAsString(activity);
JsonNode node = mapper.readTree(json);
assertEquals(node.get("label").asText(), "Label");
assertEquals(node.get("labelDetail").asText(), "Label Detail");
assertEquals(node.get("activityType").asText(), "survey");
String hrefString = node.get("survey").get("href").asText();
assertTrue(hrefString.matches("http[s]?://.*/v3/surveys/guid/revisions/2015-01-01T10:10:10.000Z"));
assertEquals(node.get("guid").asText(), "actGuid");
assertEquals(node.get("type").asText(), "Activity");
JsonNode ref = node.get("survey");
assertEquals(ref.get("identifier").asText(), "identifier");
assertEquals(ref.get("guid").asText(), "guid");
assertEquals(ref.get("createdOn").asText(), "2015-01-01T10:10:10.000Z");
String href = ref.get("href").asText();
assertTrue(href.matches("http[s]?://.*/v3/surveys/guid/revisions/2015-01-01T10:10:10.000Z"));
assertEquals(ref.get("type").asText(), "SurveyReference");
activity = mapper.readValue(json, Activity.class);
assertEquals(activity.getLabel(), "Label");
assertEquals(activity.getLabelDetail(), "Label Detail");
assertEquals(activity.getActivityType(), ActivityType.SURVEY);
SurveyReference ref1 = activity.getSurvey();
assertEquals(ref1.getIdentifier(), "identifier");
assertEquals(ref1.getCreatedOn(), DateTime.parse("2015-01-01T10:10:10.000Z"));
assertEquals(ref1.getGuid(), "guid");
assertTrue(ref1.getHref().matches("http[s]?://.*/v3/surveys/guid/revisions/2015-01-01T10:10:10.000Z"));
}
use of org.sagebionetworks.bridge.json.BridgeObjectMapper in project BridgeServer2 by Sage-Bionetworks.
the class MimeTypeTest method canSerializeWithNormalObjectMaper.
/**
* Test that serialization works with a normal ObjectMapper, not just BridgeObjectMapper.
*/
@Test
public void canSerializeWithNormalObjectMaper() throws Exception {
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(MimeType.HTML);
MimeType type = mapper.readValue(json, MimeType.class);
assertEquals(type, MimeType.HTML);
}
Aggregations