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));
}
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());
}
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());
}
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());
}
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());
}
Aggregations