use of org.codehaus.jackson.node.ObjectNode in project motech by motech.
the class TaskControllerTest method shouldImportTask.
@Test
public void shouldImportTask() throws Exception {
ObjectMapper mapper = new ObjectMapper();
StringWriter writer = new StringWriter();
IOUtils.copy(this.getClass().getResourceAsStream("/new-task-version.json"), writer);
ObjectNode node = (ObjectNode) mapper.readTree(writer.toString());
node.remove(asList("validationErrors", "type", "_rev"));
String json = node.toString();
when(taskService.importTask(json.toString())).thenReturn(new Task(null, trigger, null));
when(file.getInputStream()).thenReturn(new ByteArrayInputStream(json.getBytes()));
controller.importTask(file);
verify(taskService).importTask(json);
}
use of org.codehaus.jackson.node.ObjectNode in project motech by motech.
the class TaskControllerTest method shouldExportTask.
@Test
public void shouldExportTask() throws Exception {
long taskId = 12345;
StringWriter writer = new StringWriter();
ObjectMapper mapper = new ObjectMapper();
IOUtils.copy(this.getClass().getResourceAsStream("/new-task-version.json"), writer);
ObjectNode node = (ObjectNode) mapper.readTree(writer.toString());
node.remove(asList("validationErrors", "type", "_id", "_rev"));
when(response.getWriter()).thenReturn(printWriter);
when(taskService.exportTask(taskId)).thenReturn(node.toString());
controller.exportTask(taskId, response);
ArgumentCaptor<String> headerCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> jsonCaptor = ArgumentCaptor.forClass(String.class);
verify(response).setContentType(APPLICATION_JSON_VALUE);
verify(response).setCharacterEncoding(UTF_8);
verify(response).setHeader(eq("Content-Disposition"), headerCaptor.capture());
verify(printWriter).write(jsonCaptor.capture());
assertEquals(format("attachment; filename=%s.json", encode("Pregnancy SMS", UTF_8)), headerCaptor.getValue());
assertEquals(node, mapper.readTree(jsonCaptor.getValue()));
}
use of org.codehaus.jackson.node.ObjectNode in project motech by motech.
the class SettingsControllerTest method settingsJson.
private String settingsJson(String host, String port, String username, String password, Properties props, String logAddress, String logSubject, String logBody, String logPurgeEnable, String logPurgeTime, String logPurgeTimeMultiplier) {
ObjectNode jsonNode = new ObjectMapper().createObjectNode();
jsonNode.put("host", host);
jsonNode.put("port", port);
jsonNode.put("username", username);
jsonNode.put("password", password);
jsonNode.put("logAddress", logAddress);
jsonNode.put("logSubject", logSubject);
jsonNode.put("logBody", logBody);
jsonNode.put("logPurgeEnable", logPurgeEnable);
jsonNode.put("logPurgeTime", logPurgeTime);
jsonNode.put("logPurgeTimeMultiplier", logPurgeTimeMultiplier);
ObjectNode jsonProps = new ObjectMapper().createObjectNode();
if (props != null) {
for (Entry<Object, Object> entry : props.entrySet()) {
jsonProps.put((String) entry.getKey(), (String) entry.getValue());
}
}
jsonNode.put("additionalProperties", jsonProps);
return jsonNode.toString();
}
use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.
the class AbstractGwtDynamicHostPageServletTest method testGetUserInfoObject.
@Test
public void testGetUserInfoObject() {
// $NON-NLS-1$ //$NON-NLS-2$
ObjectNode result = testServlet.getUserInfoObject(mockUser, "mockSsoToken");
// $NON-NLS-1$
assertNotNull(result.get("id"));
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("admin", result.get("userName").asText());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("internal", result.get("domain").asText());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("mockSsoToken", result.get("ssoToken").asText());
}
use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.
the class WebAdminHostPageServletTest method testGetApplicationModeObject.
@Test
public void testGetApplicationModeObject() {
ObjectNode result = testServlet.getApplicationModeObject(255);
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("255", result.get("value").asText());
}
Aggregations