/** Test for correct xpath, but no handler bean is found --> shall raise exc */
  @Test
  public void testRouteMessageWithBadHandlerConfiguration() throws Exception {
    XPathPayloadMappingKeyExtractor mappingNameExtractor = new XPathPayloadMappingKeyExtractor();
    mappingNameExtractor.setXpathExpression("//Test/@name");
    endpointAdapter.setMappingKeyExtractor(mappingNameExtractor);

    try {
      endpointAdapter.handleMessage(new DefaultMessage("<Test name=\"UNKNOWN_TEST\"></Test>"));
      Assert.fail("Missing exception due to unknown endpoint adapter");
    } catch (CitrusRuntimeException e) {
      Assert.assertEquals(e.getMessage(), "Failed to load test case");
    }
  }
  /** Test for Xpath which is not found --> shall raise exception */
  @Test
  public void testRouteMessageWithBadXpathExpression() throws Exception {
    XPathPayloadMappingKeyExtractor mappingNameExtractor = new XPathPayloadMappingKeyExtractor();
    mappingNameExtractor.setXpathExpression("//I_DO_NOT_EXIST");
    endpointAdapter.setMappingKeyExtractor(mappingNameExtractor);

    try {
      endpointAdapter.handleMessage(new DefaultMessage("<FooTest>foo test please</FooTest>"));
      Assert.fail("Missing exception due to bad XPath expression");
    } catch (CitrusRuntimeException e) {
      Assert.assertEquals(e.getMessage(), "No result for XPath expression: '//I_DO_NOT_EXIST'");
    }
  }
  @Test
  public void testInvalidEndpointUri() throws Exception {
    JmsEndpointComponent component = new JmsEndpointComponent();

    reset(applicationContext);
    replay(applicationContext);

    try {
      component.createEndpoint("jms:queuename?param1=&param2=value2", context);
      Assert.fail("Missing exception due to invalid endpoint uri");
    } catch (CitrusRuntimeException e) {
      Assert.assertTrue(e.getMessage().startsWith("Invalid parameter"));
      verify(applicationContext);
    }
  }
Example #4
0
  @Test
  public void testInvalidScriptTemplate() {
    GroovyAction bean = new GroovyAction();

    bean.setScriptTemplateResource(
        new ClassPathResource("invalid-script-template.groovy", GroovyActionTest.class));

    bean.setScript("println 'This should not work!'");

    try {
      bean.execute(context);
    } catch (CitrusRuntimeException e) {
      Assert.assertTrue(e.getMessage().startsWith("Invalid script template"));
      return;
    }

    Assert.fail("Missing exception because of invalid script template");
  }
  @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");
  }