Search in sources :

Example 6 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class ByteBufCodecTest method testParseEscapeSymbolsInData.

@Test
public void testParseEscapeSymbolsInData() {
    List<String> get = ImmutableList.of("q");
    List<String> match = ImmutableList.of("data");
    ByteBufCodec.decode(copiedBuffer("{\"data\":\"\\u1234\"," + "\"q\":\"" + 123 + "\"}", UTF_8), get, match, consumer);
    StreamMessage message = messageBuilder.build();
    assertEquals("Parsed string doesn't match source one", "123", message.qualifier());
    assertEquals("Data is not equal", "\"\\u1234\"", ((ByteBuf) message.data()).toString(CharsetUtil.UTF_8));
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) Test(org.junit.Test)

Example 7 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class ByteBufCodecTest method testSkipExtraFields.

@Test
public void testSkipExtraFields() {
    List<String> get = ImmutableList.of("q");
    List<String> match = Collections.emptyList();
    ByteBufCodec.decode(copiedBuffer("{\"extra\":\"1234\"," + "\"q\":\"" + 123 + "\"}", UTF_8), get, match, consumer);
    StreamMessage message = messageBuilder.build();
    assertEquals("Parsed string doesn't match source one", "123", message.qualifier());
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) Test(org.junit.Test)

Example 8 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class ByteBufCodecTest method testParseAndCheckData.

@Test
public void testParseAndCheckData() {
    String sourceJson = "{" + "\"data\":{" + "\"contextId\":\"hack\"," + "\"data\":{[\"yadayada\", 1, 1e-005]}," + "\"q\":\"hack\"" + "}";
    List<String> get = ImmutableList.of("nothing");
    List<String> match = ImmutableList.of("data");
    ByteBufCodec.decode(copiedBuffer(sourceJson, UTF_8), get, match, (headerName, value) -> {
        switch(headerName) {
            case DATA_NAME:
                messageBuilder = messageBuilder.data(((ByteBuf) value).toString(CharsetUtil.UTF_8));
                break;
            default:
        }
    });
    StreamMessage message = messageBuilder.build();
    assertEquals("{\"contextId\":\"hack\",\"data\":{[\"yadayada\", 1, 1e-005]},\"q\":\"hack\"}", message.data());
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 9 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class ByteBufCodecTest method testParseWithoutDataAndWithEscapedDoubleQuotes.

@Test
public void testParseWithoutDataAndWithEscapedDoubleQuotes() {
    List<String> get = ImmutableList.of("subject");
    List<String> match = ImmutableList.of("data");
    ByteBufCodec.decode(copiedBuffer("{\"subject\":\"" + SUBJECT + "\\\"\\\"" + "\"}", UTF_8), get, match, consumer);
    StreamMessage message = messageBuilder.build();
    assertEquals(SUBJECT + "\"\"", message.subject());
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) Test(org.junit.Test)

Example 10 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class ByteBufCodecTest method testParseAndCheckDataTrickyCurlyBrace.

@Test
public void testParseAndCheckDataTrickyCurlyBrace() {
    String sourceJson = "{" + "\"data\":{" + "\"contextId\":\"hack\"," + "\"data\":{[\"ya{da}}\",\"ya{da}}\"]}," + "\"q\":\"hack\"" + "}";
    List<String> get = ImmutableList.of("nothing");
    List<String> match = ImmutableList.of("data");
    ByteBufCodec.decode(copiedBuffer(sourceJson, UTF_8), get, match, (headerName, value) -> {
        switch(headerName) {
            case DATA_NAME:
                messageBuilder = messageBuilder.data(((ByteBuf) value).toString(CharsetUtil.UTF_8));
                break;
            default:
        }
    });
    StreamMessage message = messageBuilder.build();
    assertEquals("{\"contextId\":\"hack\",\"data\":{[\"ya{da}}\",\"ya{da}}\"]},\"q\":\"hack\"}", message.data());
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

StreamMessage (io.scalecube.streams.StreamMessage)21 Test (org.junit.Test)21 ByteBuf (io.netty.buffer.ByteBuf)11