@Test
  public void testInterceptMessageConstruction() throws Exception {
    MessageConstructionInterceptor interceptor =
        new AbstractMessageConstructionInterceptor() {
          @Override
          public boolean supportsMessageType(String messageType) {
            return MessageType.XML.toString().equalsIgnoreCase(messageType);
          }

          @Override
          protected Message interceptMessage(
              Message message, String messageType, TestContext context) {
            return new DefaultMessage("Intercepted!");
          }

          @Override
          protected String getName() {
            return "MockInterceptor";
          }
        };

    Message in = new DefaultMessage("Hello Citrus!");
    Message intercepted =
        interceptor.interceptMessageConstruction(in, MessageType.XML.toString(), context);
    Assert.assertEquals(intercepted.getPayload(String.class), "Intercepted!");

    intercepted =
        interceptor.interceptMessageConstruction(in, MessageType.PLAINTEXT.toString(), context);
    Assert.assertEquals(intercepted.getPayload(String.class), "Hello Citrus!");
  }
コード例 #2
0
  @Test(
      expectedExceptions = CitrusRuntimeException.class,
      expectedExceptionsMessageRegExp = "Invalid use of http and soap action builder")
  public void testSendBuilderWithSoapAndHttpMixed() {
    reset(applicationContextMock);
    when(applicationContextMock.getBean(TestActionListeners.class))
        .thenReturn(new TestActionListeners());
    when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class))
        .thenReturn(new HashMap<String, SequenceBeforeTest>());
    when(applicationContextMock.getBeansOfType(SequenceAfterTest.class))
        .thenReturn(new HashMap<String, SequenceAfterTest>());
    MockTestDesigner builder =
        new MockTestDesigner(applicationContextMock) {
          @Override
          public void configure() {
            send("httpClient")
                .http()
                .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")
                .header("operation", "soapOperation")
                .soap();
          }
        };

    builder.configure();

    TestCase test = builder.getTestCase();
    Assert.assertEquals(test.getActionCount(), 1);
    Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);

    SendMessageAction action = ((SendMessageAction) test.getActions().get(0));
    Assert.assertEquals(action.getName(), "send");
    Assert.assertEquals(action.getEndpointUri(), "httpClient");
    Assert.assertEquals(action.getMessageType(), MessageType.XML.name());
  }
コード例 #3
0
 @Override
 public boolean supportsMessageType(String messageType, Message message) {
   return messageType.equalsIgnoreCase(MessageType.XML.toString());
 }