### Question:
ClusterControllerImpl implements ClusterController { @Override public RequestStatus deleteResources(Type type, Request request, Predicate predicate) throws UnsupportedPropertyException, SystemException, NoSuchResourceException, NoSuchParentResourceException { ResourceProvider provider = ensureResourceProvider(type); if (provider != null) { if (!checkProperties(type, null, predicate)) { predicate = resolvePredicate(type, predicate); if (predicate == null) { return null; } } return provider.deleteResources(request, predicate); } return null; } ClusterControllerImpl(ProviderModule providerModule); @Override Predicate getAmendedPredicate(Type type, Predicate predicate); @Override QueryResponse getResources(Type type, Request request, Predicate predicate); @Override Set<Resource> populateResources(Type type,
                                         Set<Resource> resources,
                                         Request request,
                                         Predicate predicate); @Override Iterable<Resource> getIterable(Type type, QueryResponse queryResponse,
                                        Request request, Predicate predicate,
                                        PageRequest pageRequest,
                                        SortRequest sortRequest); @Override PageResponse getPage(Type type, QueryResponse queryResponse,
                              Request request, Predicate predicate,
                              PageRequest pageRequest, SortRequest sortRequest); @Override Schema getSchema(Type type); @Override RequestStatus createResources(Type type, Request request); @Override RequestStatus updateResources(Type type, Request request, Predicate predicate); @Override RequestStatus deleteResources(Type type, Request request, Predicate predicate); @Override ResourceProvider ensureResourceProvider(Type type);  }### Answer:
@Test public void testDeleteResources() throws Exception{ TestProviderModule providerModule = new TestProviderModule(); TestHostResourceProvider resourceProvider = (TestHostResourceProvider) providerModule.getResourceProvider(Resource.Type.Host); ClusterController controller = new ClusterControllerImpl(providerModule); Predicate predicate = new PredicateBuilder().property("c1/p2").equals(1).toPredicate(); controller.deleteResources(Resource.Type.Host, new RequestImpl(null, null, null, null), predicate); Assert.assertEquals(TestHostResourceProvider.Action.Delete, resourceProvider.getLastAction()); Assert.assertNull(resourceProvider.getLastRequest()); Assert.assertSame(predicate, resourceProvider.getLastPredicate()); }
@Test public void testDeleteResourcesWithUnsupportedProperty() throws Exception{ TestProviderModule providerModule = new TestProviderModule(); ClusterController controller = new ClusterControllerImpl(providerModule); Predicate predicate = new PredicateBuilder().property(UNSUPPORTED_PROPERTY).equals(1).toPredicate(); try { controller.deleteResources(Resource.Type.Host, new RequestImpl(null, null, null, null), predicate); Assert.fail("Expected an UnsupportedPropertyException for the unsupported properties."); } catch (UnsupportedPropertyException e) { } }
@Test public void testDeleteResourcesResolvePredicate() throws Exception{ TestProviderModule providerModule = new TestProviderModule(); TestHostResourceProvider resourceProvider = (TestHostResourceProvider) providerModule.getResourceProvider(Resource.Type.Host); ClusterController controller = new ClusterControllerImpl(providerModule); Predicate predicate = new PredicateBuilder().property("c3/p6").equals(1).toPredicate(); controller.deleteResources(Resource.Type.Host, new RequestImpl(null, null, null, null), predicate); Assert.assertEquals(TestHostResourceProvider.Action.Delete, resourceProvider.getLastAction()); Assert.assertNull(resourceProvider.getLastRequest()); Predicate lastPredicate = resourceProvider.getLastPredicate(); Assert.assertFalse(predicate.equals(lastPredicate)); Set<String> predicatePropertyIds = PredicateHelper.getPropertyIds(lastPredicate); Collection<String> keyPropertyIds = resourceProvider.getKeyPropertyIds().values(); Assert.assertEquals(predicatePropertyIds.size(), keyPropertyIds.size()); Assert.assertTrue(keyPropertyIds.containsAll(predicatePropertyIds)); }