|
@@ -101,7 +101,7 @@ public class JsonSerializerTest {
|
|
|
|
|
|
|
|
|
TreeNode<Resource> resourcesNode = tree.addChild(null, "resources");
|
|
|
-
|
|
|
+
|
|
|
|
|
|
resourcesNode.addChild(resource, "resource1");
|
|
|
|
|
@@ -145,4 +145,68 @@ public class JsonSerializerTest {
|
|
|
|
|
|
verify(uriInfo, resource);
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testSerializeResourcesAsArray() throws Exception {
|
|
|
+ UriInfo uriInfo = createMock(UriInfo.class);
|
|
|
+ Resource resource = createMock(Resource.class);
|
|
|
+ //Resource resource2 = createMock(Resource.class);
|
|
|
+
|
|
|
+ Result result = new ResultImpl(true);
|
|
|
+ result.setResultStatus(new ResultStatus(ResultStatus.STATUS.OK));
|
|
|
+ TreeNode<Resource> tree = result.getResultTree();
|
|
|
+ //tree.setName("items");
|
|
|
+ TreeNode<Resource> child = tree.addChild(resource, "resource1");
|
|
|
+ child.setProperty("href", "this is an href");
|
|
|
+ tree.addChild(resource, "resource2");
|
|
|
+ //child.addChild(resource2, "sub-resource");
|
|
|
+
|
|
|
+ // resource properties
|
|
|
+ HashMap<String, Object> mapRootProps = new HashMap<String, Object>();
|
|
|
+ mapRootProps.put("prop1", "value1");
|
|
|
+ mapRootProps.put("prop2", "value2");
|
|
|
+
|
|
|
+ HashMap<String, Object> mapCategoryProps = new HashMap<String, Object>();
|
|
|
+ mapCategoryProps.put("catProp1", "catValue1");
|
|
|
+ mapCategoryProps.put("catProp2", "catValue2");
|
|
|
+
|
|
|
+ Map<String, Map<String, Object>> propertyMap = new HashMap<String, Map<String, Object>>();
|
|
|
+
|
|
|
+ propertyMap.put(null, mapRootProps);
|
|
|
+ propertyMap.put("category", mapCategoryProps);
|
|
|
+
|
|
|
+ //expectations
|
|
|
+ expect(resource.getPropertiesMap()).andReturn(propertyMap).anyTimes();
|
|
|
+ expect(resource.getType()).andReturn(Resource.Type.Cluster).anyTimes();
|
|
|
+
|
|
|
+ replay(uriInfo, resource/*, resource2*/);
|
|
|
+
|
|
|
+ //execute test
|
|
|
+ Object o = new JsonSerializer().serialize(result);
|
|
|
+ String expected = "[\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"href\" : \"this is an href\",\n" +
|
|
|
+ " \"prop2\" : \"value2\",\n" +
|
|
|
+ " \"prop1\" : \"value1\",\n" +
|
|
|
+ " \"category\" : {\n" +
|
|
|
+ " \"catProp1\" : \"catValue1\",\n" +
|
|
|
+ " \"catProp2\" : \"catValue2\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"prop2\" : \"value2\",\n" +
|
|
|
+ " \"prop1\" : \"value1\",\n" +
|
|
|
+ " \"category\" : {\n" +
|
|
|
+ " \"catProp1\" : \"catValue1\",\n" +
|
|
|
+ " \"catProp2\" : \"catValue2\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " }\n" +
|
|
|
+ "]";
|
|
|
+
|
|
|
+ assertEquals(expected, o);
|
|
|
+
|
|
|
+ verify(uriInfo, resource/*, resource2*/);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|