@Test
public void testGetResources_collection() throws Exception {

  Set<String> propertyIds = new HashSet<String>();
  TreeMap<String, String> foreignKeys = new TreeMap<String, String>();
  foreignKeys.put("cluster", "500");
  List<ArtifactEntity> entities = new ArrayList<ArtifactEntity>();
  entities.add(entity);
  entities.add(entity2);
  Map<String, Object> artifact_data = Collections.<String, Object>singletonMap("foo", "bar");
  Map<String, Object> artifact_data2 = Collections.<String, Object>singletonMap("foo2", "bar2");
  Map<String, String> responseForeignKeys = new HashMap<String, String>();
  responseForeignKeys.put("cluster", "500");
  // expectations
  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();
  expect(request.getPropertyIds()).andReturn(propertyIds).anyTimes();
  expect(dao.findByForeignKeys(eq(foreignKeys))).andReturn(entities).anyTimes();
  expect(entity.getArtifactName()).andReturn("test-artifact").anyTimes();
  expect(entity.getForeignKeys()).andReturn(responseForeignKeys).anyTimes();
  expect(entity.getArtifactData()).andReturn(artifact_data).anyTimes();
  expect(entity2.getArtifactName()).andReturn("test-artifact2").anyTimes();
  expect(entity2.getForeignKeys()).andReturn(responseForeignKeys).anyTimes();
  expect(entity2.getArtifactData()).andReturn(artifact_data2).anyTimes();
  // end of expectation setting
  replay(dao, em, controller, request, clusters, cluster, entity, entity2);
  // test
  PredicateBuilder pb = new PredicateBuilder();
  Predicate predicate = pb.begin().property("Artifacts/cluster_name").equals("test-cluster").end().toPredicate();
  Set<Resource> response = resourceProvider.getResources(request, predicate);
  assertEquals(2, response.size());
  boolean artifact1Returned = false;
  boolean artifact2Returned = false;
  for (Resource resource : response) {
    if (resource.getPropertyValue("Artifacts/artifact_name").equals("test-artifact")) {
      artifact1Returned = true;
      assertEquals("bar", resource.getPropertyValue("artifact_data/foo"));
      assertEquals("test-cluster", resource.getPropertyValue("Artifacts/cluster_name"));
    } else if (resource.getPropertyValue("Artifacts/artifact_name").equals("test-artifact2")) {
      artifact2Returned = true;
      assertEquals("bar2", resource.getPropertyValue("artifact_data/foo2"));
      assertEquals("test-cluster", resource.getPropertyValue("Artifacts/cluster_name"));
    } else {
      fail("unexpected artifact name");
    }
  }
  assertTrue(artifact1Returned);
  assertTrue(artifact2Returned);
}