@Test public void containsJSONAssertionTest() { // Test for Contains assertion with a valid JSON structure StringBuffer jsonData = new StringBuffer(); jsonData.append("{"); jsonData.append("\"id\": \"0001\","); jsonData.append("\"type\": \"donut\","); jsonData.append("\"name\": \"Cake\","); jsonData.append("\"ppu\": 0.55,"); jsonData.append("\"batters\": {"); jsonData.append("\"batter\": ["); jsonData.append("{ \"id\": \"1001\", \"type\": \"Regular\" },"); jsonData.append("{ \"id\": \"1002\", \"type\": \"Chocolate\" },"); jsonData.append("{ \"id\": \"1003\", \"type\": \"Blueberry\" },"); jsonData.append("{ \"id\": \"1004\", \"type\": \"Devil's Food\" }"); jsonData.append("]"); jsonData.append("}, \"topping\": ["); jsonData.append("{ \"id\": \"5001\", \"type\": \"None\" },"); jsonData.append("{ \"id\": \"5002\", \"type\": \"Glazed\" },"); jsonData.append("{ \"id\": \"5005\", \"type\": \"Sugar\" },"); jsonData.append("{ \"id\": \"5007\", \"type\": \"Powdered Sugar\" },"); jsonData.append("{ \"id\": \"5006\", \"type\": \"Chocolate with Sprinkles\" },"); jsonData.append("{ \"id\": \"5003\", \"type\": \"Chocolate\" },"); jsonData.append("{ \"id\": \"5004\", \"type\": \"Maple\" }"); jsonData.append("]"); jsonData.append("}"); AssertionEngine engine = new AssertionEngineImpl(); OutMessage originalMessage = new OutMessage(); OutMessage replayedMessage = new OutMessage(); MessageContent originalContent = new MessageContent(); MessageContent replayedContent = new MessageContent(); ContainsAssertion containsAssertion = new ContainsAssertion("containsAssertion"); originalContent.setRawContent(jsonData.toString()); replayedContent.setRawContent(jsonData.toString()); assertEquals(ContentType.JSON, originalContent.getContentType()); originalMessage.setMessageContent(originalContent); replayedMessage.setMessageContent(replayedContent); AssertionResult result = engine.executeAssertion("batters", containsAssertion, originalMessage, replayedMessage); assertEquals(AssertionResultStatus.OK, result.getResultStatus()); // assertEquals("5", result.getMetrics()); }
@Test public void containsXMLAssertionTest() { // Test for Contains assertion with a valid XML structure StringBuffer xmlData = new StringBuffer(); xmlData.append( "<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body><content>Don't forget me this weekend!</content></body></note>"); AssertionEngine engine = new AssertionEngineImpl(); OutMessage originalMessage = new OutMessage(); OutMessage replayedMessage = new OutMessage(); MessageContent originalContent = new MessageContent(); MessageContent replayedContent = new MessageContent(); ContainsAssertion containsAssertion = new ContainsAssertion("containsAssertion"); originalContent.setRawContent(xmlData.toString()); replayedContent.setRawContent(xmlData.toString()); assertEquals(ContentType.XML, originalContent.getContentType()); originalMessage.setMessageContent(originalContent); replayedMessage.setMessageContent(replayedContent); AssertionResult result = engine.executeAssertion("body", containsAssertion, originalMessage, replayedMessage); assertEquals(AssertionResultStatus.OK, result.getResultStatus()); }