Search in sources :

Example 66 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project thingsboard by thingsboard.

the class DefaultGatewayNotificationsService method onDeviceDeleted.

@Override
public void onDeviceDeleted(Device device) {
    Optional<DeviceId> gatewayDeviceId = getGatewayDeviceIdFromAdditionalInfoInDevice(device);
    if (gatewayDeviceId.isPresent()) {
        TextNode deletedDeviceNode = new TextNode(device.getName());
        ToDeviceRpcRequest rpcRequest = formDeviceToGatewayRPCRequest(device.getTenantId(), gatewayDeviceId.get(), deletedDeviceNode, DEVICE_DELETED_METHOD_NAME);
        deviceRpcService.processRestApiRpcRequest(rpcRequest, fromDeviceRpcResponse -> {
            log.trace("Device deleted RPC with id: [{}] processed to gateway device with id: [{}], deleted device name: [{}]", rpcRequest.getId(), gatewayDeviceId, device.getName());
        }, null);
    }
}
Also used : ToDeviceRpcRequest(org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest) DeviceId(org.thingsboard.server.common.data.id.DeviceId) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 67 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project template-compiler by Squarespace.

the class ExprTest method testNumberFormatting.

@Test
public void testNumberFormatting() {
    Context c = ctx();
    // large magnitude
    assertEquals(reduce("str(1e20)", c), new TextNode("100000000000000000000"));
    assertEquals(reduce("str(1e21)", c), new TextNode("1e+21"));
    assertEquals(reduce("str(1e300)", c), new TextNode("1e+300"));
    // small magnitude
    assertEquals(reduce("str(1e-5)", c), new TextNode("0.00001"));
    assertEquals(reduce("str(1e-6)", c), new TextNode("0.000001"));
    assertEquals(reduce("str(1e-7)", c), new TextNode("1e-7"));
    assertEquals(reduce("str(1e-20)", c), new TextNode("1e-20"));
    assertEquals(reduce("str(1e-21)", c), new TextNode("1e-21"));
    assertEquals(reduce("str(1e-300)", c), new TextNode("1e-300"));
    // negative large magnitude
    assertEquals(reduce("str(-1e20)", c), new TextNode("-100000000000000000000"));
    assertEquals(reduce("str(-1e21)", c), new TextNode("-1e+21"));
    assertEquals(reduce("str(-1e300)", c), new TextNode("-1e+300"));
    // negative small magnitude
    assertEquals(reduce("str(-1e-5)", c), new TextNode("-0.00001"));
    assertEquals(reduce("str(-1e-6)", c), new TextNode("-0.000001"));
    assertEquals(reduce("str(-1e-7)", c), new TextNode("-1e-7"));
    assertEquals(reduce("str(-1e-20)", c), new TextNode("-1e-20"));
    assertEquals(reduce("str(-1e-21)", c), new TextNode("-1e-21"));
    assertEquals(reduce("str(-1e-300)", c), new TextNode("-1e-300"));
}
Also used : Context(com.squarespace.template.Context) TextNode(com.fasterxml.jackson.databind.node.TextNode) Test(org.testng.annotations.Test)

Example 68 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project template-compiler by Squarespace.

the class ExprTest method testTypeConversions.

@Test
public void testTypeConversions() {
    Context c = ctx("{\"a\":{\"b\":3.75,\"c\":\"3.1415\",\"flag\":true,\"nil\":null,\"s\":\"foo\"}," + "\"n0\":\"-0x1234\",\"n1\":\"-1.2e21\",\"n2\":\"--1.2\",\"n3\":\"--0x1234\"}");
    assertEquals(reduce("str()", c), null);
    assertEquals(reduce("str(\"\")", c), new TextNode(""));
    assertEquals(reduce("str(\"foobar\")", c), new TextNode("foobar"));
    assertEquals(reduce("str(zzz)", c), new TextNode("null"));
    assertEquals(reduce("str(a.b)", c), new TextNode("3.75"));
    assertEquals(reduce("str(true)", c), new TextNode("true"));
    assertEquals(reduce("str(false)", c), new TextNode("false"));
    assertEquals(reduce("str(null)", c), new TextNode("null"));
    assertEquals(reduce("str(a.flag)", c), new TextNode("true"));
    assertEquals(reduce("str(a.nil)", c), new TextNode("null"));
    assertEquals(reduce("str(a.s)", c), new TextNode("foo"));
    assertEquals(reduce("str(-Infinity)", c), new TextNode("-Infinity"));
    assertEquals(reduce("str(Infinity)", c), new TextNode("Infinity"));
    assertEquals(reduce("str(NaN)", c), new TextNode("NaN"));
    assertEquals(reduce("str(12e20)", c), new TextNode("1.2e+21"));
    assertEquals(reduce("num()", c), null);
    assertEquals(reduce("num(zzz)", c), new DoubleNode(0));
    assertEquals(reduce("num(a.c)", c), new DoubleNode(3.1415));
    assertEquals(reduce("num(\"0xcafe\")", c), new DoubleNode(0xcafe));
    assertEquals(reduce("num(\"0Xcafe\")", c), new DoubleNode(0xcafe));
    assertEquals(reduce("num(\"000123\")", c), new DoubleNode(123));
    assertEquals(reduce("num(\"0x\")", c), new DoubleNode(Double.NaN));
    assertEquals(reduce("num(\"0xfoo\")", c), new DoubleNode(Double.NaN));
    assertEquals(reduce("num(\"123foo\")", c), new DoubleNode(Double.NaN));
    assertEquals(reduce("num(\"-123\")", c), new DoubleNode(-123));
    assertEquals(reduce("num(\"-\")", c), new DoubleNode(Double.NaN));
    assertEquals(reduce("num(\"--123\")", c), new DoubleNode(Double.NaN));
    assertEquals(reduce("num(n0)", c), new DoubleNode(-0x1234));
    assertEquals(reduce("num(n1)", c), new DoubleNode(-1.2e21));
    assertEquals(reduce("num(n2)", c), new DoubleNode(Double.NaN));
    assertEquals(reduce("num(n3)", c), new DoubleNode(Double.NaN));
    assertEquals(reduce("bool()", c), null);
    assertEquals(reduce("bool(zzz)", c), BooleanNode.FALSE);
    assertEquals(reduce("bool(a.b)", c), BooleanNode.TRUE);
    assertEquals(reduce("bool(\"foo\")", c), BooleanNode.TRUE);
    assertEquals(reduce("str(num(bool(true)))", c), new TextNode("1"));
}
Also used : Context(com.squarespace.template.Context) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) Test(org.testng.annotations.Test)

Example 69 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project template-compiler by Squarespace.

the class ExprTest method testConcatenate.

@Test
public void testConcatenate() {
    Context c = new Context(JsonUtils.decode("{}"));
    assertEquals(reduce("\"foo\" + 1", c), new TextNode("foo1"));
    assertEquals(reduce("\"foo\" + null", c), new TextNode("foonull"));
    assertEquals(reduce("\"foo\" + true", c), new TextNode("footrue"));
    assertEquals(reduce("\"foo\" + false", c), new TextNode("foofalse"));
    assertEquals(reduce("\"\" + false", c), new TextNode("false"));
    assertEquals(reduce("1 + \"foo\"", c), new TextNode("1foo"));
    assertEquals(reduce("null + \"bar\"", c), new TextNode("nullbar"));
    assertEquals(reduce("true + \"bar\"", c), new TextNode("truebar"));
    assertEquals(reduce("false + \"bar\"", c), new TextNode("falsebar"));
    assertEquals(reduce("false + \"\"", c), new TextNode("false"));
}
Also used : Context(com.squarespace.template.Context) TextNode(com.fasterxml.jackson.databind.node.TextNode) Test(org.testng.annotations.Test)

Example 70 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project template-compiler by Squarespace.

the class MessageFormatsTest method testDecimal.

@Test
public void testDecimal() {
    String actual;
    CLDR cldr = CLDR.get("en");
    MessageFormats formats = new MessageFormats(cldr);
    formats.setTimeZone("America/New_York");
    String message = "{0 decimal style:short}";
    actual = formats.formatter().format(message, args().add(new TextNode("12345.789")));
    assertEquals(actual, "12K");
}
Also used : CLDR(com.squarespace.cldrengine.CLDR) TextNode(com.fasterxml.jackson.databind.node.TextNode) MessageFormats(com.squarespace.template.MessageFormats) Test(org.testng.annotations.Test)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)140 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)48 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)37 Test (org.junit.Test)37 JsonNode (com.fasterxml.jackson.databind.JsonNode)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 IntNode (com.fasterxml.jackson.databind.node.IntNode)16 ArrayList (java.util.ArrayList)16 Test (org.junit.jupiter.api.Test)15 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)12 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 TreeNode (com.fasterxml.jackson.core.TreeNode)11 HashMap (java.util.HashMap)11 List (java.util.List)11 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 Map (java.util.Map)10