Example usage for com.fasterxml.jackson.databind.node TextNode valueOf

List of usage examples for com.fasterxml.jackson.databind.node TextNode valueOf

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node TextNode valueOf.

Prototype

public static TextNode valueOf(String paramString) 

Source Link

Usage

From source file:snow.console.Connect.java

@Override
public void execute(JsonNode data, StreamResults stream) {
    JsonNode ref = data.get("ref");
    if (ref instanceof TextNode)
        stream.put("ref", ref);
    stream.put("id", TextNode.valueOf(Terminal.create().id()));
}

From source file:com.spotify.helios.system.APITest.java

/**
 * Verify that the Helios master generates and returns a hash if the submitted job creation
 * request does not include one.//from w w  w .ja v a 2  s  .  c  om
 */
@Test
public void testHashLessJobCreation() throws Exception {
    startDefaultMaster();

    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX)
            .setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();

    // Remove the hash from the id in the json serialized job
    final ObjectNode json = (ObjectNode) Json.reader().readTree(Json.asString(job));
    json.set("id", TextNode.valueOf(testJobName + ":" + testJobVersion));

    final HttpURLConnection req = post("/jobs?user=" + TEST_USER, Json.asBytes(json));

    assertEquals(req.getResponseCode(), 200);

    final CreateJobResponse res = Json.read(toByteArray(req.getInputStream()), CreateJobResponse.class);

    assertEquals(OK, res.getStatus());
    assertTrue(res.getErrors().isEmpty());
    assertEquals(job.getId().toString(), res.getId());
}

From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.api.LiveEndpointsControllerTest.java

@Test
public void testLiveNodes() throws Exception {
    Tuple2<Integer, JsonNode> tup = fetchJson("/live-nodes?limit=2", false);

    // must return HTTP/500 if no nodes are present
    assertEquals(400, tup._1.intValue());

    // add one live node
    addNode("exec1", "1.2.3.4");

    tup = fetchJson("/live-nodes?limit=2", false);
    assertEquals(200, tup._1.intValue());
    JsonNode json = tup._2;/*from  w ww  .j a va2s  .com*/
    assertEquals(9042, json.get("nativePort").asInt());
    assertEquals(9160, json.get("rpcPort").asInt());
    assertEquals(7199, json.get("jmxPort").asInt());
    JsonNode nodes = json.get("liveNodes");
    assertEquals(JsonNodeType.ARRAY, nodes.getNodeType());
    assertThat(nodes).hasSize(1).contains(TextNode.valueOf("1.2.3.4"));

    // test more output formats

    Tuple2<Integer, String> str = fetchText("/live-nodes/cqlsh", "text/x-cassandra-cqlsh");
    assertEquals(200, str._1.intValue());
    assertEquals("1.2.3.4 9042", str._2);

    str = fetchText("/live-nodes/stress?limit=2", "text/x-cassandra-stress");
    assertEquals(200, str._1.intValue());
    assertEquals("-node 1.2.3.4 -port native=9042 thrift=9160 jmx=7199", str._2);

    str = fetchText("/live-nodes/nodetool", "text/x-cassandra-nodetool");
    assertEquals(200, str._1.intValue());
    assertEquals("-h 1.2.3.4 -p 7199", str._2);

    str = fetchText("/live-nodes/text?limit=2", "text/plain");
    assertEquals(200, str._1.intValue());
    assertEquals("NATIVE: 9042\n" + "RPC: 9160\n" + "JMX: 7199\n" + "IP: 1.2.3.4\n", str._2);

    str = fetchText("/live-nodes/cqlsh", "text/x-cassandra-cqlsh");
    assertEquals(200, str._1.intValue());
    assertEquals("1.2.3.4 9042", str._2);

    str = fetchText("/live-nodes/stress", "text/x-cassandra-stress");
    assertEquals(200, str._1.intValue());
    assertEquals("-node 1.2.3.4 -port native=9042 thrift=9160 jmx=7199", str._2);

    str = fetchText("/live-nodes/nodetool", "text/x-cassandra-nodetool");
    assertEquals(200, str._1.intValue());
    assertEquals("-h 1.2.3.4 -p 7199", str._2);

    str = fetchText("/live-nodes/text", "text/plain");
    assertEquals(200, str._1.intValue());
    assertEquals("NATIVE: 9042\n" + "RPC: 9160\n" + "JMX: 7199\n" + "IP: 1.2.3.4\n", str._2);

    //
    // mark node as dead
    //

    cluster.recordHealthCheck("exec1", healthCheckDetailsFailed());
    tup = fetchJson("/live-nodes?limit=2", false);
    assertEquals(400, tup._1.intValue());

    str = fetchText("/live-nodes/cqlsh", "text/x-cassandra-cqlsh");
    assertEquals(400, str._1.intValue());

    str = fetchText("/live-nodes/stress?limit=2", "text/x-cassandra-stress");
    assertEquals(400, str._1.intValue());

    str = fetchText("/live-nodes/nodetool", "text/x-cassandra-nodetool");
    assertEquals(400, str._1.intValue());

    str = fetchText("/live-nodes/text?limit=2", "text/plain");
    assertEquals(400, str._1.intValue());

    // add a live nodes

    addNode("exec2", "2.2.2.2");

    tup = fetchJson("/live-nodes?limit=2", false);
    assertEquals(200, tup._1.intValue());
    json = tup._2;
    assertEquals(9042, json.get("nativePort").asInt());
    assertEquals(9160, json.get("rpcPort").asInt());
    assertEquals(7199, json.get("jmxPort").asInt());
    nodes = json.get("liveNodes");
    assertEquals(JsonNodeType.ARRAY, nodes.getNodeType());
    assertThat(nodes).hasSize(1).contains(TextNode.valueOf("2.2.2.2"));

    str = fetchText("/live-nodes/cqlsh", "text/x-cassandra-cqlsh");
    assertEquals(200, str._1.intValue());
    assertEquals("2.2.2.2 9042", str._2);

    str = fetchText("/live-nodes/stress?limit=2", "text/x-cassandra-stress");
    assertEquals(200, str._1.intValue());
    assertEquals("-node 2.2.2.2 -port native=9042 thrift=9160 jmx=7199", str._2);

    str = fetchText("/live-nodes/nodetool", "text/x-cassandra-nodetool");
    assertEquals(200, str._1.intValue());
    assertEquals("-h 2.2.2.2 -p 7199", str._2);

    str = fetchText("/live-nodes/text?limit=2", "text/plain");
    assertEquals(200, str._1.intValue());
    assertEquals("NATIVE: 9042\n" + "RPC: 9160\n" + "JMX: 7199\n" + "IP: 2.2.2.2\n", str._2);

    // mark 1st node as live

    cluster.recordHealthCheck("exec1", healthCheckDetailsSuccess("NORMAL", true));

    tup = fetchJson("/live-nodes?limit=2", false);
    assertEquals(200, tup._1.intValue());
    json = tup._2;
    assertEquals(9042, json.get("nativePort").asInt());
    assertEquals(9160, json.get("rpcPort").asInt());
    assertEquals(7199, json.get("jmxPort").asInt());
    nodes = json.get("liveNodes");
    assertEquals(JsonNodeType.ARRAY, nodes.getNodeType());
    assertThat(nodes).hasSize(2).contains(TextNode.valueOf("1.2.3.4")).contains(TextNode.valueOf("2.2.2.2"));

    str = fetchText("/live-nodes/cqlsh", "text/x-cassandra-cqlsh");
    assertEquals(200, str._1.intValue());

    str = fetchText("/live-nodes/stress?limit=2", "text/x-cassandra-stress");
    assertEquals(200, str._1.intValue());

    str = fetchText("/live-nodes/nodetool", "text/x-cassandra-nodetool");
    assertEquals(200, str._1.intValue());

    str = fetchText("/live-nodes/text?limit=2", "text/plain");
    assertEquals(200, str._1.intValue());
}

From source file:com.googlecode.jsonschema2pojo.rules.FormatRuleTest.java

@Test
public void applyGeneratesTypeFromFormatValue() {
    TextNode formatNode = TextNode.valueOf(formatValue);

    JType result = rule.apply("fooBar", formatNode, new JCodeModel().ref(String.class), null);

    assertThat(result.fullName(), equalTo(expectedType.getName()));
}

From source file:com.googlecode.jsonschema2pojo.rules.TypeRuleTest.java

@Test
public void applyGeneratesDate() {

    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());

    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "string");

    TextNode formatNode = TextNode.valueOf("date-time");
    objectNode.put("format", formatNode);

    JType mockDateType = mock(JType.class);
    FormatRule mockFormatRule = mock(FormatRule.class);
    when(mockFormatRule.apply(eq("fooBar"), eq(formatNode), Mockito.isA(JType.class), isNull(Schema.class)))
            .thenReturn(mockDateType);//from   www  . j a v  a2  s.  co  m
    when(ruleFactory.getFormatRule()).thenReturn(mockFormatRule);

    JType result = rule.apply("fooBar", objectNode, jpackage, null);

    assertThat(result, equalTo(mockDateType));
}

From source file:com.googlecode.jsonschema2pojo.rules.FormatRuleTest.java

@Test
public void applyDefaultsToBaseType() {
    TextNode formatNode = TextNode.valueOf("unknown-format");

    JType baseType = new JCodeModel().ref(Long.class);

    JType result = rule.apply("fooBar", formatNode, baseType, null);

    assertThat(result, equalTo(baseType));
}

From source file:org.jsonschema2pojo.rules.TypeRuleTest.java

@Test
public void applyGeneratesDate() {

    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());

    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "string");

    TextNode formatNode = TextNode.valueOf("date-time");
    objectNode.set("format", formatNode);

    JType mockDateType = mock(JType.class);
    FormatRule mockFormatRule = mock(FormatRule.class);
    when(mockFormatRule.apply(eq("fooBar"), eq(formatNode), Mockito.isA(JType.class), isNull(Schema.class)))
            .thenReturn(mockDateType);/*  w ww .ja v  a2s . co  m*/
    when(ruleFactory.getFormatRule()).thenReturn(mockFormatRule);

    JType result = rule.apply("fooBar", objectNode, jpackage, null);

    assertThat(result, equalTo(mockDateType));
}

From source file:com.turn.shapeshifter.NamedSchemaSerializer.java

/**
 * Returns the JSON representation of the value of a message's field.
 *
 * @param value the value to represent in JSON
 * @param field the descriptor of the value's field.
 * @param schemas a container for object schemas to use for formatting
 * fields that refer to other messages//w  w  w. jav a2  s  . com
 * @throws SerializationException
 */
private JsonNode serializeValue(Object value, FieldDescriptor field, ReadableSchemaRegistry schemas)
        throws SerializationException {
    JsonNode valueNode = NullNode.instance;
    if (schema.getTransforms().containsKey(field.getName())) {
        return schema.getTransforms().get(field.getName()).serialize(value);
    }
    switch (field.getType()) {
    case BOOL:
        valueNode = BooleanNode.valueOf((Boolean) value);
        break;
    case BYTES:
        byte[] bytes = ((ByteString) value).toByteArray();
        String content = new String();
        for (int i = 0; i < bytes.length; i++) {
            content += (char) bytes[i];
        }
        valueNode = TextNode.valueOf(content);
        break;
    case DOUBLE:
        valueNode = new DoubleNode((Double) value);
        break;
    case ENUM:
        EnumValueDescriptor enumValueDescriptor = (EnumValueDescriptor) value;
        String enumValue = NamedSchema.PROTO_ENUM_CASE_FORMAT.to(schema.getEnumCaseFormat(),
                enumValueDescriptor.getName());
        valueNode = new TextNode(enumValue);
        break;
    case FLOAT:
        valueNode = new DoubleNode((Float) value);
        break;
    case GROUP:
        break;
    case FIXED32:
    case INT32:
    case SFIXED32:
    case SINT32:
    case UINT32:
        valueNode = new IntNode((Integer) value);
        break;
    case FIXED64:
    case INT64:
    case SFIXED64:
    case SINT64:
    case UINT64:
        valueNode = schema.getSurfaceLongsAsStrings() ? new TextNode(((Long) value).toString())
                : new LongNode((Long) value);
        break;
    case MESSAGE:
        Message messageValue = (Message) value;
        Schema subSchema = null;
        if (schema.getSubObjectsSchemas().containsKey(field.getName())) {
            String schemaName = schema.getSubObjectsSchemas().get(field.getName());
            if (schemas.contains(schemaName)) {
                subSchema = schemas.get(schemaName);
            } else {
                throw new IllegalStateException();
            }
        } else {
            try {
                subSchema = schemas.get(field.getMessageType());
            } catch (SchemaObtentionException soe) {
                throw new SerializationException(soe);
            }
        }
        valueNode = subSchema.getSerializer().serialize(messageValue, schemas);
        valueNode = valueNode.size() == 0 ? NullNode.instance : valueNode;
        break;
    case STRING:
        valueNode = new TextNode((String) value);
        break;
    default:
        break;
    }
    return valueNode;
}

From source file:io.apicurio.hub.api.bitbucket.BitbucketSourceConnectorTest.java

@Test
@Ignore/*from ww  w.  ja  va 2  s .  c o  m*/
public void testUpdateResourceContent() throws SourceConnectorException, BitbucketException, NotFoundException,
        UnirestException, JsonProcessingException, IOException {
    String repositoryUrl = "https://bitbucket.org/apicurio/apicurio-test/src/1b684236c6434bc5c6644cbf62c46bbd8d40f3d1/junit-apis/test-update-content.json?at=master&fileviewer=file-view-default";

    ResourceContent content = service.getResourceContent(repositoryUrl);
    Assert.assertTrue(content.getContent().contains("Animation API"));
    Assert.assertNotNull(content.getSha());

    ObjectMapper mapper = new ObjectMapper();
    JsonNode root = mapper.readTree(content.getContent());
    ObjectNode info = (ObjectNode) root.get("info");
    long newVersion = System.currentTimeMillis();
    info.set("version", TextNode.valueOf(String.valueOf(newVersion)));

    System.out.println("Setting new version to: " + newVersion);

    String newContent = mapper.writeValueAsString(root);
    content.setContent(newContent);
    String newSha = service.updateResourceContent(repositoryUrl, "Unit Test: Update Content",
            "Updated the version of: " + repositoryUrl, content);
    System.out.println("New SHA: " + newSha);
}

From source file:de.thomaskrille.dropwizard.environment_configuration.EnvironmentConfigurationFactory.java

private void replaceEnvironmentVariablesForArray(final Queue<JsonNode> q, final ArrayNode node) {
    for (int i = 0; i < node.size(); i++) {
        JsonNode element = node.get(i);/*from   ww  w  .  j ava2 s.  c om*/

        if (element.isContainerNode()) {
            q.offer(element);
            continue;
        }

        if (!element.isValueNode()) {
            continue;
        }

        String replacement = getReplacementForValue(element);

        if (replacement == null) {
            continue;
        }

        node.set(i, TextNode.valueOf(replacement));

    }
}