@Test public void inboundPropertyMapCopy() { Map<String, Serializable> inboundProperties = singletonMap(PROPERTY_KEY, PROPERTY_VALUE); InternalMessage copy = new DefaultMessageBuilder(new DefaultMessageBuilder().value(TEST_PAYLOAD) .inboundProperties(inboundProperties).build()).build(); assertThat(copy.getInboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(copy.getInboundPropertyDataType(PROPERTY_KEY), equalTo(STRING)); assertThat(copy.getInboundPropertyNames(), hasSize(1)); assertThat(copy.getInboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void outboundPropertyMapCopy() { Map<String, Serializable> outboundProperties = singletonMap(PROPERTY_KEY, PROPERTY_VALUE); InternalMessage copy = new DefaultMessageBuilder(new DefaultMessageBuilder().value(TEST_PAYLOAD) .outboundProperties(outboundProperties).build()).build(); assertThat(copy.getOutboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(copy.getOutboundPropertyDataType(PROPERTY_KEY), equalTo(STRING)); assertThat(copy.getOutboundPropertyNames(), hasSize(1)); assertThat(copy.getOutboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void copyPreservesDataType() { Apple apple = new Apple(); long appleSize = 111; Message message = new DefaultMessageBuilder().payload(new TypedValue(apple, fromObject(apple), OptionalLong.of(appleSize))).build(); Message copy = new DefaultMessageBuilder(message).build(); assertThat(copy.getPayload(), is(message.getPayload())); assertThat(copy.getAttributes(), is(message.getAttributes())); assertThat(message.getPayload().getByteLength().getAsLong(), is(appleSize)); assertThat(copy.getPayload().getByteLength().getAsLong(), is(appleSize)); }
@Test public void outboundPropertyMap() { Map<String, Serializable> outboundProperties = singletonMap(PROPERTY_KEY, PROPERTY_VALUE); InternalMessage message = new DefaultMessageBuilder().value(TEST_PAYLOAD).outboundProperties(outboundProperties).build(); assertThat(message.getOutboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(message.getOutboundPropertyDataType(PROPERTY_KEY), equalTo(STRING)); assertThat(message.getOutboundPropertyNames(), hasSize(1)); assertThat(message.getOutboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void inboundPropertyDataType() { InternalMessage message = new DefaultMessageBuilder().value(TEST_PAYLOAD).addInboundProperty(PROPERTY_KEY, PROPERTY_VALUE, HTML_STRING).build(); assertThat(message.getInboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(message.getInboundPropertyDataType(PROPERTY_KEY), equalTo(HTML_STRING)); assertThat(message.getInboundPropertyNames(), hasSize(1)); assertThat(message.getInboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void outboundPropertyDataType() { InternalMessage message = new DefaultMessageBuilder().value(TEST_PAYLOAD) .addOutboundProperty(PROPERTY_KEY, PROPERTY_VALUE, HTML_STRING).build(); assertThat(message.getOutboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(message.getOutboundPropertyDataType(PROPERTY_KEY), equalTo(HTML_STRING)); assertThat(message.getOutboundPropertyNames(), hasSize(1)); assertThat(message.getOutboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void inboundPropertyMap() { Map<String, Serializable> inboundProperties = singletonMap(PROPERTY_KEY, PROPERTY_VALUE); InternalMessage message = new DefaultMessageBuilder().value(TEST_PAYLOAD).inboundProperties(inboundProperties).build(); assertThat(message.getInboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(message.getInboundPropertyDataType(PROPERTY_KEY), equalTo(STRING)); assertThat(message.getInboundPropertyNames(), hasSize(1)); assertThat(message.getInboundPropertyNames(), hasItem(PROPERTY_KEY)); }
private Message createTestMessage() { return new DefaultMessageBuilder().value(TEST_PAYLOAD).mediaType(TEXT).build(); }
@Test public void inboundProperty() { InternalMessage message = new DefaultMessageBuilder().value(TEST_PAYLOAD).addInboundProperty(PROPERTY_KEY, PROPERTY_VALUE).build(); assertThat(message.getInboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(message.getInboundPropertyDataType(PROPERTY_KEY), equalTo(STRING)); assertThat(message.getInboundPropertyNames(), hasSize(1)); assertThat(message.getInboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void outboundProperty() { InternalMessage message = new DefaultMessageBuilder().value(TEST_PAYLOAD).addOutboundProperty(PROPERTY_KEY, PROPERTY_VALUE) .build(); assertThat(message.getOutboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(message.getOutboundPropertyDataType(PROPERTY_KEY), equalTo(STRING)); assertThat(message.getOutboundPropertyNames(), hasSize(1)); assertThat(message.getOutboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void mutatePayloadSameTypeConserveTypeAndMimeType() { Message message = createTestMessage(); Message copy = new DefaultMessageBuilder(message).value(NEW_PAYLOAD).build(); assertThat(copy.getPayload().getValue(), equalTo(NEW_PAYLOAD)); assertThat(copy.getPayload().getDataType().getType(), equalTo(String.class)); assertThat(copy.getPayload().getDataType().getMediaType(), is(TEXT)); }
@Test public void mutatePayloadDifferentTypeUpdateTypeAndConserveMimeType() { Message copy = new DefaultMessageBuilder(createTestMessage()).value(1).build(); assertThat(copy.getPayload().getValue(), equalTo(1)); assertThat(copy.getPayload().getDataType().getType(), equalTo(Integer.class)); assertThat(copy.getPayload().getDataType().getMediaType(), is(TEXT)); }
@Test public void mutatePayloadDifferentTypeWithMediaTypeUpdateTypeAndConserveMimeType() { Long payload = new Long(1); DataHandler dataHandler = new DataHandler(payload, XML.toString()); Message copy = new DefaultMessageBuilder(createTestMessage()).value(dataHandler).build(); assertThat(copy.getPayload().getValue(), is(dataHandler)); assertThat(copy.getPayload().getDataType().getType(), equalTo(DataHandler.class)); assertThat(copy.getPayload().getDataType().getMediaType(), is(XML)); }
@Test public void mutateEntirePayload() { Message message = createTestMessage(); Message copy = new DefaultMessageBuilder(message).payload(new TypedValue<>(EMPTY_JSON, JSON_STRING)).build(); assertThat(copy.getPayload().getValue(), equalTo(EMPTY_JSON)); assertThat(copy.getPayload().getDataType().getType(), equalTo(String.class)); assertThat(copy.getPayload().getDataType().getMediaType(), is(APPLICATION_JSON)); }
@Test public void messageAttributesCopy() { assertTestMessage(new DefaultMessageBuilder(createTestMessage()).build()); }
@Test public void inboundPropertyMap() { Map<String, Serializable> inboundProperties = singletonMap(PROPERTY_KEY, PROPERTY_VALUE); InternalMessage message = new DefaultMessageBuilder().value(TEST_PAYLOAD).inboundProperties(inboundProperties).build(); assertThat(message.getInboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(message.getInboundPropertyDataType(PROPERTY_KEY), equalTo(STRING)); assertThat(message.getInboundPropertyNames(), hasSize(1)); assertThat(message.getInboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void outboundPropertyMap() { Map<String, Serializable> outboundProperties = singletonMap(PROPERTY_KEY, PROPERTY_VALUE); InternalMessage message = new DefaultMessageBuilder().value(TEST_PAYLOAD).outboundProperties(outboundProperties).build(); assertThat(message.getOutboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(message.getOutboundPropertyDataType(PROPERTY_KEY), equalTo(STRING)); assertThat(message.getOutboundPropertyNames(), hasSize(1)); assertThat(message.getOutboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void outboundPropertyDataType() { InternalMessage message = new DefaultMessageBuilder().value(TEST_PAYLOAD) .addOutboundProperty(PROPERTY_KEY, PROPERTY_VALUE, HTML_STRING).build(); assertThat(message.getOutboundProperty(PROPERTY_KEY), equalTo(PROPERTY_VALUE)); assertThat(message.getOutboundPropertyDataType(PROPERTY_KEY), equalTo(HTML_STRING)); assertThat(message.getOutboundPropertyNames(), hasSize(1)); assertThat(message.getOutboundPropertyNames(), hasItem(PROPERTY_KEY)); }
@Test public void mutatePayloadSameTypeConserveTypeAndMimeType() { Message message = createTestMessage(); Message copy = new DefaultMessageBuilder(message).value(NEW_PAYLOAD).build(); assertThat(copy.getPayload().getValue(), equalTo(NEW_PAYLOAD)); assertThat(copy.getPayload().getDataType().getType(), equalTo(String.class)); assertThat(copy.getPayload().getDataType().getMediaType(), is(TEXT)); }
@Test public void mutatePayloadDifferentTypeUpdateTypeAndConserveMimeType() { Message copy = new DefaultMessageBuilder(createTestMessage()).value(1).build(); assertThat(copy.getPayload().getValue(), equalTo(1)); assertThat(copy.getPayload().getDataType().getType(), equalTo(Integer.class)); assertThat(copy.getPayload().getDataType().getMediaType(), is(TEXT)); }