verify(resource, resourceDefinition, controller, schema, serverRequest);
}
@Test
public void testCreate__MultipleResources() throws Exception {
ResourceInstance resource = createMock(ResourceInstance.class);
ResourceDefinition resourceDefinition = createMock(ResourceDefinition.class);
ClusterController controller = createMock(ClusterController.class);
Schema schema = createMock(Schema.class);
Request serverRequest = createStrictMock(Request.class);
RequestBody body = new RequestBody();
String clusterId = "clusterId";
String serviceId = "serviceId";
Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
mapResourceIds.put(Resource.Type.Cluster, "clusterId");
mapResourceIds.put(Resource.Type.Service, "serviceId");
Map<String, Object> mapResourceProps1 = new HashMap<String, Object>();
mapResourceProps1.put("componentId", "id1");
mapResourceProps1.put(PropertyHelper.getPropertyId("foo", "bar"), "value");
Map<String, Object> mapResourceProps2 = new HashMap<String, Object>();
mapResourceProps1.put("componentId", "id2");
mapResourceProps2.put(PropertyHelper.getPropertyId("foo", "bar2"), "value2");
NamedPropertySet namedPropSet1 = new NamedPropertySet("", mapResourceProps1);
NamedPropertySet namedPropSet2 = new NamedPropertySet("", mapResourceProps2);
body.addPropertySet(namedPropSet1);
body.addPropertySet(namedPropSet2);
Set<Map<String, Object>> setExpected = new HashSet<Map<String, Object>>();
Map<String, Object> mapExpected1 = new HashMap<String, Object>(mapResourceProps1);
mapExpected1.put(clusterId, "clusterId");
mapExpected1.put(serviceId, "serviceId");
setExpected.add(mapExpected1);
Map<String, Object> mapExpected2 = new HashMap<String, Object>(mapResourceProps2);
mapExpected2.put(clusterId, "clusterId");
mapExpected2.put(serviceId, "serviceId");
setExpected.add(mapExpected2);
//expectations
expect(resource.getIds()).andReturn(mapResourceIds);
expect(resource.getResourceDefinition()).andReturn(resourceDefinition);
expect(resourceDefinition.getType()).andReturn(Resource.Type.Component);
expect(controller.getSchema(Resource.Type.Component)).andReturn(schema);
expect(schema.getKeyPropertyId(Resource.Type.Cluster)).andReturn(clusterId).times(2);
expect(schema.getKeyPropertyId(Resource.Type.Service)).andReturn(serviceId).times(2);