@Test
public void testCreateResource() throws Exception {

  Capture<ArtifactEntity> createEntityCapture = newCapture();
  Map<String, Object> outerMap = new TreeMap<String, Object>();
  Map<String, Object> childMap = new TreeMap<String, Object>();
  outerMap.put("child", childMap);
  childMap.put("childKey", "childValue");
  Map<String, Object> child2Map = new TreeMap<String, Object>();
  childMap.put("child2", child2Map);
  child2Map.put("child2Key", "child2Value");
  Map<String, Object> child3Map = new TreeMap<String, Object>();
  child2Map.put("child3", child3Map);
  Map<String, Object> child4Map = new TreeMap<String, Object>();
  child3Map.put("child4", child4Map);
  child4Map.put("child4Key", "child4Value");
  Set<Map<String, Object>> propertySet = new HashSet<Map<String, Object>>();
  propertySet.add(outerMap);
  propertySet.add(child4Map);
  Map<String, Object> artifact_data = new TreeMap<String, Object>();
  artifact_data.put("foo", "bar");
  artifact_data.put("child", childMap);
  artifact_data.put("collection", propertySet);
  TreeMap<String, String> foreignKeys = new TreeMap<String, String>();
  foreignKeys.put("cluster", "500");
  Map<String, String> requestInfoProps = new HashMap<String, String>();
  requestInfoProps.put(Request.REQUEST_INFO_BODY_PROPERTY, bodyJson);
  // map with flattened properties
  Map<String, Object> properties = new HashMap<String, Object>();
  properties.put("Artifacts/artifact_name", "test-artifact");
  properties.put("Artifacts/cluster_name", "test-cluster");
  properties.put("artifact_data/foo", "bar");
  properties.put("artifact_data/child/childKey", "childValue");
  properties.put("artifact_data/child/child2/child2Key", "child2Value");
  properties.put("artifact_data/child/child2/child3/child4/child4Key", "child4Value");
  Collection<Object> collectionProperties = new HashSet<Object>();
  properties.put("artifact_data/collection", collectionProperties);
  // collection with maps of flattened properties
  Map<String, Object> map1 = new TreeMap<String, Object>();
  collectionProperties.add(map1);
  map1.put("foo", "bar");
  map1.put("child/childKey", "childValue");
  map1.put("child/child2/child2Key", "child2Value");
  map1.put("child/child2/child3/child4/child4Key", "child4Value");
  Map<String, Object> map2 = new TreeMap<String, Object>();
  collectionProperties.add(map2);
  map2.put("child4Key", "child4Value");
  Set<Map<String, Object>> requestProperties = Collections.singleton(properties);
  // expectations
  expect(request.getRequestInfoProperties()).andReturn(requestInfoProps).anyTimes();
  expect(request.getProperties()).andReturn(requestProperties).anyTimes();
  expect(controller.getClusters()).andReturn(clusters).anyTimes();
  expect(clusters.getCluster("test-cluster")).andReturn(cluster).anyTimes();
  expect(clusters.getClusterById(500L)).andReturn(cluster).anyTimes();
  expect(cluster.getClusterId()).andReturn(500L).anyTimes();
  expect(cluster.getClusterName()).andReturn("test-cluster").anyTimes();
  // check to see if entity already exists
  expect(dao.findByNameAndForeignKeys(eq("test-artifact"), eq(foreignKeys))).andReturn(null).once();
  // create
  dao.create(capture(createEntityCapture));
  // end of expectation setting
  replay(dao, em, controller, request, clusters, cluster, entity, entity2);
  resourceProvider.createResources(request);
  ArtifactEntity createEntity = createEntityCapture.getValue();
  assertEquals("test-artifact", createEntity.getArtifactName());
  Map<String, Object> actualArtifactData = createEntity.getArtifactData();
  // need to decompose actualArtifactData because actualArtifactData.get("collection") returns a set
  // implementation that does not equal an identical(same elements) HashSet instance
  assertEquals(artifact_data.size(), actualArtifactData.size());
  assertEquals(artifact_data.get("foo"), actualArtifactData.get("foo"));
  assertEquals(artifact_data.get("child"), actualArtifactData.get("child"));
  assertEquals(artifact_data.get("collection"), new HashSet(((Collection) actualArtifactData.get("collection"))));
  assertEquals(foreignKeys, createEntity.getForeignKeys());
}