Search in sources :

Example 71 with ObjectNode

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);
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) StringWriter(java.io.StringWriter) ObjectNode(org.codehaus.jackson.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 72 with ObjectNode

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()));
}
Also used : StringWriter(java.io.StringWriter) ObjectNode(org.codehaus.jackson.node.ObjectNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 73 with ObjectNode

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();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 74 with ObjectNode

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());
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) Test(org.junit.Test)

Example 75 with ObjectNode

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());
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) Test(org.junit.Test)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)29 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)16 Produces (javax.ws.rs.Produces)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)5 JsonFactory (org.codehaus.jackson.JsonFactory)5 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Span (org.apache.stanbol.enhancer.nlp.model.Span)4 DatasetImpl (org.eol.globi.service.DatasetImpl)4 Date (java.util.Date)3 TaskDriver (org.apache.helix.task.TaskDriver)3 WorkflowConfig (org.apache.helix.task.WorkflowConfig)3