@Override protected Message getOutputMessage(CoreEvent result) { Message message = result.getMessage(); assertThat(message, is(notNullValue())); return message; } }
@Test public void processToApplyRespondAndMapInFlow() throws Exception { assertThat(processToApply(input, createFlow(respondAndMap)).getMessage(), is(response.getMessage())); assertThat(from(responsePublisher).block(), is(response)); }
@Test public void processRespondAndMapInFlow() throws Exception { assertThat(from(MessageProcessors.process(input, createFlow(respondAndMap))).block().getMessage(), is(response.getMessage())); assertThat(from(responsePublisher).block(), is(response)); }
@Test public void payloadAsDataType() throws Exception { InternalMessage transformedMessage = mock(InternalMessage.class, RETURNS_DEEP_STUBS); TransformationService transformationService = mock(TransformationService.class); when(transformedMessage.getPayload()).thenReturn(new TypedValue<Object>(TEST_PAYLOAD, STRING)); muleContext.setTransformationService(transformationService); when(transformationService.transform(event.getMessage(), DataType.STRING)).thenReturn(transformedMessage); Object result = evaluate("message.payloadAs(" + DataType.class.getName() + ".STRING)", event); assertSame(TEST_PAYLOAD, result); }
@Test public void mapStreamBlockingGetNullResult() { CoreEvent result = just(event).transform(testProcessorReturnsNull).block(); assertThat(result.getMessage().getPayload().getValue(), is(nullValue())); }
@Test public void mapStreamSubscribe() throws Exception { CoreEvent result = just(event).transform(testProcessor).block(); assertThat(result.getMessage().getPayload().getValue(), equalTo(TEST_PAYLOAD)); }
@Test public void testDoNothingFlow() throws Exception { CoreEvent muleEvent = flowRunner("testDoNothingFlow").run(); assertThat(muleEvent.getMessage().getPayload().getValue(), is("before calling")); assertThat(muleEvent.getVariables().get("variableBeforeCalling").getValue(), is("value of flowvar before calling")); }
@Test public void mapBlockingNullResult() throws Exception { CoreEvent result = testProcessorReturnsNull.process(event); assertThat(result.getMessage().getPayload().getValue(), is(nullValue())); }
@Test public void copiableCollection() { Copiable<Collection<String>> collection = mock(Copiable.class, withSettings().extraInterfaces(Collection.class)); when(collection.copy()).thenReturn(testCollection); when(event.getMessage().getPayload()).thenReturn(new TypedValue<>(collection, fromObject(collection))); assertCollectionSequence(); verify(collection).copy(); }
@Test public void testSetPayloadParamFlow() throws Exception { CoreEvent muleEvent = flowRunner("testSetPayloadParamFlow").run(); assertThat(muleEvent.getMessage().getPayload().getValue(), is("new payload")); }
@Test public void testSetPayloadHardcodedFlowThruSubflow() throws Exception { CoreEvent event = flowRunner("testSetPayloadHardcodedFlowThruSubflow").run(); assertThat(event.getMessage().getPayload().getValue(), is("hardcoded value")); }
@Test public void testSetPayloadHardcodedFlowThruSubflowWithNestedElements() throws Exception { CoreEvent event = flowRunner("testSetPayloadHardcodedFlowThruSubflowWithNestedElements").run(); assertThat(event.getMessage().getPayload().getValue(), is("hardcoded value")); } }
@Test public void exceptionCausedBy() throws Exception { CoreEvent event = createEvent(); Message message = event.getMessage(); MessagingException me = new MessagingException(CoreMessages.createStaticMessage(""), InternalEvent.builder(context).message(message).build(), new IllegalAccessException()); when(mockError.getCause()).thenReturn(me); assertTrue((Boolean) evaluate("exception.causedBy(java.lang.IllegalAccessException)", event)); }
@Test public void testSetPayloadAddParamAndPropertyValues() throws Exception { CoreEvent muleEvent = flowRunner("testSetPayloadAddParamAndPropertyValues").run(); assertThat(muleEvent.getMessage().getPayload().getValue(), is("a parameter value some config-value-parameter")); }
@Test public void operationReturnsOperationResultThatOnlySpecifiesPayload() throws Exception { Object payload = "hello world!"; when(operationExecutor.execute(any(ExecutionContext.class))).thenReturn(just(builder().output(payload).build())); event = CoreEvent.builder(event).message(Message.builder().value("").attributesValue(mock(Object.class)).build()).build(); Message message = messageProcessor.process(event).getMessage(); assertThat(message, is(notNullValue())); assertThat(message.getPayload().getValue(), is(sameInstance(payload))); assertThat(message.getAttributes().getValue(), is(nullValue())); assertThat(message.getPayload().getDataType().getType().equals(String.class), is(true)); }
@SuppressWarnings("unchecked") @Test public void inboundValues() throws Exception { Message message = event.getMessage(); event = CoreEvent.builder(event) .message(InternalMessage.builder(message).addInboundProperty("foo", "abc").addInboundProperty("bar", "xyz").build()) .build(); Collection<DataHandler> values = (Collection<DataHandler>) evaluate("message.inboundProperties.values()", event); assertEquals(2, values.size()); values.contains("abc"); values.contains("xyz"); }
@SuppressWarnings("unchecked") @Test public void outboundEntrySet() throws Exception { event = CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).addOutboundProperty("foo", "abc") .addOutboundProperty("bar", "xyz").build()).build(); Set<Map.Entry<String, Object>> entrySet = (Set<Entry<String, Object>>) evaluate("message.outboundProperties.entrySet()", event); assertEquals(2, entrySet.size()); entrySet.contains(new DefaultMapEntry("foo", "abc")); entrySet.contains(new DefaultMapEntry("bar", "xyz")); }
@Test public void assignValueToNewOutboundProperty() throws Exception { CoreEvent.Builder eventBuilder = CoreEvent.builder(event); evaluate("message.outboundProperties['foo']='bar'", event, eventBuilder); assertEquals("bar", ((InternalMessage) eventBuilder.build().getMessage()).getOutboundProperty("foo")); }
@Test public void inboundSize() throws Exception { Message message = event.getMessage(); mock(DataHandler.class); event = CoreEvent.builder(event) .message(InternalMessage.builder(message).addInboundProperty("foo", "abc").addInboundProperty("bar", "xyz").build()) .build(); assertEquals(2, evaluate("message.inboundProperties.size()", event)); }
@Test public void outboundIsEmpty() throws Exception { assertTrue((Boolean) evaluate("message.outboundProperties.isEmpty()", event)); event = CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).addOutboundProperty("foo", "abc") .addOutboundProperty("bar", "xyz").build()).build(); assertFalse((Boolean) evaluate("message.outboundProperties.isEmpty()", event)); }