コード例 #1
0
  @Test
  @SuppressWarnings("rawtypes")
  public void testSoapMessageWithAttachmentDataTest() throws Exception {
    SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();
    soapMessageAction.setMessageSender(messageSender);

    PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();
    messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");

    soapMessageAction.setMessageBuilder(messageBuilder);

    soapMessageAction.setContentId("myAttachment");
    soapMessageAction.setContentType("text/xml");
    soapMessageAction.setAttachmentData(
        "<TestAttachment><Message>Hello World!</Message></TestAttachment>");
    soapMessageAction.setCharsetName("UTF-16");

    reset(messageSender);

    messageSender.send((Message) anyObject(), (Attachment) anyObject());
    expectLastCall()
        .andAnswer(
            new IAnswer<Object>() {
              public Object answer() throws Throwable {
                SoapAttachment constructedAttachment =
                    (SoapAttachment) EasyMock.getCurrentArguments()[1];
                Assert.assertEquals(constructedAttachment.getContentId(), "myAttachment");
                Assert.assertEquals(constructedAttachment.getContentType(), "text/xml");
                Assert.assertEquals(
                    constructedAttachment.getContent(),
                    "<TestAttachment><Message>Hello World!</Message></TestAttachment>");
                Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-16");

                return null;
              }
            })
        .once();

    replay(messageSender);

    soapMessageAction.execute(context);

    verify(messageSender);
  }
コード例 #2
0
  @Test
  @SuppressWarnings("rawtypes")
  public void testSoapMessageWithHeaderResourceVariableSupportTest() throws Exception {
    SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();
    soapMessageAction.setMessageSender(messageSender);

    PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();
    messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");

    context.setVariable("operation", "soapOperation");

    messageBuilder.setMessageHeaderResource(
        new ClassPathResource(
            "test-header-resource-with-variables.xml", SendSoapMessageActionTest.class));

    soapMessageAction.setMessageBuilder(messageBuilder);

    reset(messageSender);

    messageSender.send((Message) anyObject());
    expectLastCall()
        .andAnswer(
            new IAnswer<Object>() {
              public Object answer() throws Throwable {
                Message constructedMessage = (Message) EasyMock.getCurrentArguments()[0];

                Assert.assertNotNull(
                    constructedMessage.getHeaders().get(CitrusMessageHeaders.HEADER_CONTENT));
                Assert.assertEquals(
                    constructedMessage.getHeaders().get(CitrusMessageHeaders.HEADER_CONTENT),
                    "<TestHeader><operation>soapOperation</operation></TestHeader>");

                return null;
              }
            })
        .once();

    replay(messageSender);

    soapMessageAction.execute(context);

    verify(messageSender);
  }
コード例 #3
0
  @Test
  @SuppressWarnings("rawtypes")
  public void testSoapMessageWithEmptyAttachmentContentTest() throws Exception {
    SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();
    soapMessageAction.setMessageSender(messageSender);

    PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();
    messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");

    soapMessageAction.setMessageBuilder(messageBuilder);

    reset(messageSender);

    messageSender.send((Message) anyObject());
    expectLastCall().once();

    replay(messageSender);

    soapMessageAction.execute(context);

    verify(messageSender);
  }
コード例 #4
0
  @Test
  public void testWrongMessageSenderImplementationTest() throws Exception {
    SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();
    MessageSender jmsMessageSender = new JmsMessageSender();
    soapMessageAction.setMessageSender(jmsMessageSender);

    PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();
    messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");

    soapMessageAction.setMessageBuilder(messageBuilder);

    try {
      soapMessageAction.execute(context);
    } catch (CitrusRuntimeException e) {
      Assert.assertEquals(
          e.getMessage(),
          "Sending SOAP messages requires a "
              + "'com.consol.citrus.ws.message.WebServiceMessageSender' but was 'com.consol.citrus.jms.JmsMessageSender'");
      return;
    }

    Assert.fail("Missing exception because of unsupported MessageSender implementation");
  }