INT-1710 ObjectToJson tests are now flexible with regard to key=value pair order

This commit is contained in:
Mark Fisher
2010-12-22 12:44:57 -05:00
parent a5a64cebb0
commit aef94f10df
2 changed files with 46 additions and 8 deletions

View File

@@ -18,6 +18,10 @@ package org.springframework.integration.json;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.codehaus.jackson.JsonGenerator.Feature;
import org.codehaus.jackson.map.ObjectMapper;
@@ -64,8 +68,16 @@ public class ObjectToJsonTransformerParserTests {
assertNotNull(reply);
assertNotNull(reply.getPayload());
assertEquals(String.class, reply.getPayload().getClass());
String expected = "{\"address\":{\"number\":123,\"street\":\"Main Street\"},\"firstName\":\"John\",\"lastName\":\"Doe\",\"age\":42}";
assertEquals(expected, reply.getPayload());
String resultString = (String) reply.getPayload();
assertTrue(resultString.contains("\"firstName\":\"John\""));
assertTrue(resultString.contains("\"lastName\":\"Doe\""));
assertTrue(resultString.contains("\"age\":42"));
Pattern addressPattern = Pattern.compile("(\"address\":\\{.*?\\})");
Matcher matcher = addressPattern.matcher(resultString);
assertTrue(matcher.find());
String addressResult = matcher.group(1);
assertTrue(addressResult.contains("\"number\":123"));
assertTrue(addressResult.contains("\"street\":\"Main Street\""));
}
@Test
@@ -85,8 +97,16 @@ public class ObjectToJsonTransformerParserTests {
assertNotNull(reply);
assertNotNull(reply.getPayload());
assertEquals(String.class, reply.getPayload().getClass());
String expected = "{address:{number:123,street:\"Main Street\"},firstName:\"John\",lastName:\"Doe\",age:42}";
assertEquals(expected, reply.getPayload());
String resultString = (String) reply.getPayload();
assertTrue(resultString.contains("firstName:\"John\""));
assertTrue(resultString.contains("lastName:\"Doe\""));
assertTrue(resultString.contains("age:42"));
Pattern addressPattern = Pattern.compile("(address:\\{.*?\\})");
Matcher matcher = addressPattern.matcher(resultString);
assertTrue(matcher.find());
String addressResult = matcher.group(1);
assertTrue(addressResult.contains("number:123"));
assertTrue(addressResult.contains("street:\"Main Street\""));
}

View File

@@ -17,6 +17,10 @@
package org.springframework.integration.json;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.codehaus.jackson.JsonGenerator.Feature;
import org.codehaus.jackson.map.ObjectMapper;
@@ -49,8 +53,15 @@ public class ObjectToJsonTransformerTests {
TestPerson person = new TestPerson("John", "Doe", 42);
person.setAddress(address);
String result = transformer.transformPayload(person);
String expected = "{\"address\":{\"number\":123,\"street\":\"Main Street\"},\"firstName\":\"John\",\"lastName\":\"Doe\",\"age\":42}";
assertEquals(expected, result);
assertTrue(result.contains("\"firstName\":\"John\""));
assertTrue(result.contains("\"lastName\":\"Doe\""));
assertTrue(result.contains("\"age\":42"));
Pattern addressPattern = Pattern.compile("(\"address\":\\{.*?\\})");
Matcher matcher = addressPattern.matcher(result);
assertTrue(matcher.find());
String addressResult = matcher.group(1);
assertTrue(addressResult.contains("\"number\":123"));
assertTrue(addressResult.contains("\"street\":\"Main Street\""));
}
@Test
@@ -61,8 +72,15 @@ public class ObjectToJsonTransformerTests {
TestPerson person = new TestPerson("John", "Doe", 42);
person.setAddress(new TestAddress(123, "Main Street"));
String result = transformer.transformPayload(person);
String expected = "{address:{number:123,street:\"Main Street\"},firstName:\"John\",lastName:\"Doe\",age:42}";
assertEquals(expected, result);
assertTrue(result.contains("firstName:\"John\""));
assertTrue(result.contains("lastName:\"Doe\""));
assertTrue(result.contains("age:42"));
Pattern addressPattern = Pattern.compile("(address:\\{.*?\\})");
Matcher matcher = addressPattern.matcher(result);
assertTrue(matcher.find());
String addressResult = matcher.group(1);
assertTrue(addressResult.contains("number:123"));
assertTrue(addressResult.contains("street:\"Main Street\""));
}