JsonPayloadMappingKeyExtractor extends AbstractMappingKeyExtractor { public void setJsonPathExpression(String jsonPathExpression) { this.jsonPathExpression = jsonPathExpression; }  @Override String getMappingKey(Message request); void setJsonPathExpression(String jsonPathExpression);  }
@Test public void testExtractMappingKey() throws Exception { JsonPayloadMappingKeyExtractor extractor = new JsonPayloadMappingKeyExtractor(); extractor.setJsonPathExpression("$.person.name"); Assert.assertEquals(extractor.extractMappingKey(new DefaultMessage( "{ \"person\": {\"name\": \"Penny\"} }")), "Penny"); Assert.assertEquals(extractor.extractMappingKey(new DefaultMessage( "{ \"person\": {\"name\": \"Leonard\"} }")), "Leonard"); }
@Test public void testRouteMessageWithBadJsonPathExpression() throws Exception { JsonPayloadMappingKeyExtractor extractor = new JsonPayloadMappingKeyExtractor(); extractor.setJsonPathExpression("$.I_DO_NOT_EXIST"); try { extractor.extractMappingKey(new DefaultMessage( "{ \"person\": {\"name\": \"Penny\"} }")); Assert.fail("Missing exception due to bad Json expression"); } catch (CitrusRuntimeException e) { Assert.assertEquals(e.getMessage(), "Failed to evaluate JSON path expression: $.I_DO_NOT_EXIST"); } }