/** 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 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 handler routing by node content */
  @Test
  public void testRouteMessageByElementTextContent() throws Exception {
    XPathPayloadMappingKeyExtractor mappingNameExtractor = new XPathPayloadMappingKeyExtractor();
    mappingNameExtractor.setXpathExpression("//Test/@name");
    endpointAdapter.setMappingKeyExtractor(mappingNameExtractor);

    Message response =
        endpointAdapter.handleMessage(new DefaultMessage("<Test name=\"FooTest\"></Test>"));

    Assert.assertEquals(
        response.getPayload(String.class).trim(), "<Test name=\"FooTest\">OK</Test>");

    response = endpointAdapter.handleMessage(new DefaultMessage("<Test name=\"BarTest\"></Test>"));

    Assert.assertEquals(
        response.getPayload(String.class).trim(), "<Test name=\"BarTest\">OK</Test>");
  }