Search in sources :

Example 16 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project buck by facebook.

the class TargetsCommandIntegrationTest method testJsonOutputWithShowFullOutput.

@Test
public void testJsonOutputWithShowFullOutput() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "output_path", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets", "--json", "--show-full-output", "//:test");
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    // Parse the observed JSON.
    JsonNode observed = objectMapper.readTree(objectMapper.getFactory().createParser(result.getStdout()));
    assertTrue(observed.isArray());
    JsonNode targetNode = observed.get(0);
    assertTrue(targetNode.isObject());
    JsonNode cellPath = targetNode.get("buck.outputPath");
    assertNotNull(cellPath);
    Path expectedPath = tmp.getRoot().resolve("buck-out/gen/test/test-output");
    String expectedRootPath = MorePaths.pathWithPlatformSeparators(expectedPath);
    assertEquals(expectedRootPath, cellPath.asText());
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 17 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project hadoop by apache.

the class TestLog4Json method testNestedException.

@Test
public void testNestedException() throws Throwable {
    Exception e = new NoRouteToHostException("that box caught fire 3 years ago");
    Exception ioe = new IOException("Datacenter problems", e);
    ThrowableInformation ti = new ThrowableInformation(ioe);
    Log4Json l4j = new Log4Json();
    long timeStamp = Time.now();
    String outcome = l4j.toJson(new StringWriter(), "testNestedException", timeStamp, "INFO", "quoted\"", "new line\n and {}", ti).toString();
    println("testNestedException", outcome);
    ContainerNode rootNode = Log4Json.parse(outcome);
    assertEntryEquals(rootNode, Log4Json.LEVEL, "INFO");
    assertEntryEquals(rootNode, Log4Json.NAME, "testNestedException");
    assertEntryEquals(rootNode, Log4Json.TIME, timeStamp);
    assertEntryEquals(rootNode, Log4Json.EXCEPTION_CLASS, ioe.getClass().getName());
    JsonNode node = assertNodeContains(rootNode, Log4Json.STACK);
    assertTrue("Not an array: " + node, node.isArray());
    node = assertNodeContains(rootNode, Log4Json.DATE);
    assertTrue("Not a string: " + node, node.isTextual());
    //rather than try and make assertions about the format of the text
    //message equalling another ISO date, this test asserts that the hypen
    //and colon characters are in the string.
    String dateText = node.textValue();
    assertTrue("No '-' in " + dateText, dateText.contains("-"));
    assertTrue("No '-' in " + dateText, dateText.contains(":"));
}
Also used : StringWriter(java.io.StringWriter) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) ContainerNode(com.fasterxml.jackson.databind.node.ContainerNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) NoRouteToHostException(java.net.NoRouteToHostException) IOException(java.io.IOException) NoRouteToHostException(java.net.NoRouteToHostException) Test(org.junit.Test)

Example 18 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project hadoop by apache.

the class TestLog4Json method assertEntryEquals.

void assertEntryEquals(ContainerNode rootNode, String key, String value) {
    JsonNode node = assertNodeContains(rootNode, key);
    assertEquals(value, node.textValue());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 19 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project hadoop by apache.

the class TestLog4Json method assertEntryEquals.

void assertEntryEquals(ContainerNode rootNode, String key, long value) {
    JsonNode node = assertNodeContains(rootNode, key);
    assertEquals(value, node.numberValue());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 20 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project OpenAM by OpenRock.

the class SubjectTypesResource method jsonify.

/**
     * Transforms a subclass of {@link EntitlementSubject} in to a JsonSchema representation.
     * This schema is then combined with the Subject's name (taken as the resourceId) and all this is
     * compiled together into a new {@link JsonValue} object until "title" and "config" fields respectively.
     *
     * @param subjectClass The class whose schema to produce.
     * @param resourceId The ID of the resource to return
     * @return A JsonValue containing the schema of the EntitlementSubject
     */
private JsonValue jsonify(Class<? extends EntitlementSubject> subjectClass, String resourceId, boolean logical) {
    try {
        final JsonSchema schema = mapper.generateJsonSchema(subjectClass);
        //this will remove the 'subjectName' attribute from those subjects which incorporate it unnecessarily
        final JsonNode node = schema.getSchemaNode().get("properties");
        if (node instanceof ObjectNode) {
            final ObjectNode alter = (ObjectNode) node;
            alter.remove("subjectName");
        }
        return JsonValue.json(JsonValue.object(JsonValue.field(JSON_OBJ_TITLE, resourceId), JsonValue.field(JSON_OBJ_LOGICAL, logical), JsonValue.field(JSON_OBJ_CONFIG, schema)));
    } catch (JsonMappingException e) {
        if (debug.errorEnabled()) {
            debug.error("SubjectTypesResource :: JSONIFY - Error applying " + "jsonification to the Subject class representation.", e);
        }
        return null;
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)4105 Test (org.junit.Test)1257 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)802 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)544 IOException (java.io.IOException)532 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)384 ArrayList (java.util.ArrayList)315 Test (org.junit.jupiter.api.Test)277 HashMap (java.util.HashMap)249 Map (java.util.Map)201 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)174 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)127 List (java.util.List)122 InputStream (java.io.InputStream)116 KernelTest (com.twosigma.beakerx.KernelTest)114 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)84 Response (javax.ws.rs.core.Response)79 File (java.io.File)78 HttpGet (org.apache.http.client.methods.HttpGet)75 ByteArrayInputStream (java.io.ByteArrayInputStream)70