BlueprintResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus deleteResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> setResources = getResources( new RequestImpl(null, null, null, null), predicate); for (final Resource resource : setResources) { final String blueprintName = (String) resource.getPropertyValue(BLUEPRINT_NAME_PROPERTY_ID); LOG.info("Deleting Blueprint, name = " + blueprintName); modifyResources(new Command<Void>() { @Override public Void invoke() throws AmbariException { blueprintDAO.removeByName(blueprintName); return null; } }); } notifyDelete(Resource.Type.Blueprint, predicate); return getRequestStatus(null); } BlueprintResourceProvider(Set<String> propertyIds,
                            Map<Resource.Type, String> keyPropertyIds,
                            AmbariManagementController controller); static void init(BlueprintFactory factory, BlueprintDAO dao, SecurityConfigurationFactory
    securityFactory, Gson gson, AmbariMetaInfo metaInfo); @Override RequestStatus createResources(Request request); @Override //todo: continue to use dao/entity directly or use blueprint factory? Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static List<Map<String, Object>> populateSettingList(
          Collection<? extends BlueprintSettingEntity> settings); static final String BLUEPRINT_NAME_PROPERTY_ID; static final String STACK_NAME_PROPERTY_ID; static final String STACK_VERSION_PROPERTY_ID; static final String BLUEPRINT_SECURITY_PROPERTY_ID; static final String BLUEPRINTS_PROPERTY_ID; static final String HOST_GROUP_PROPERTY_ID; static final String HOST_GROUP_NAME_PROPERTY_ID; static final String HOST_GROUP_CARDINALITY_PROPERTY_ID; static final String COMPONENT_PROPERTY_ID; static final String COMPONENT_NAME_PROPERTY_ID; static final String COMPONENT_PROVISION_ACTION_PROPERTY_ID; static final String CONFIGURATION_PROPERTY_ID; static final String SETTING_PROPERTY_ID; static final String PROPERTIES_PROPERTY_ID; static final String PROPERTIES_ATTRIBUTES_PROPERTY_ID; static final String SCHEMA_IS_NOT_SUPPORTED_MESSAGE; static final String REQUEST_BODY_EMPTY_ERROR_MESSAGE; static final String CONFIGURATION_LIST_CHECK_ERROR_MESSAGE; static final String CONFIGURATION_MAP_CHECK_ERROR_MESSAGE; static final String CONFIGURATION_MAP_SIZE_CHECK_ERROR_MESSAGE; }
@Test public void testDeleteResources() throws SystemException, UnsupportedPropertyException, NoSuchParentResourceException, NoSuchResourceException { BlueprintEntity blueprintEntity = createEntity(getBlueprintTestProperties().iterator().next()); expect(dao.findByName(BLUEPRINT_NAME)).andReturn(blueprintEntity); dao.removeByName(blueprintEntity.getBlueprintName()); expectLastCall(); replay(dao); Predicate predicate = new EqualsPredicate<String>( BlueprintResourceProvider.BLUEPRINT_NAME_PROPERTY_ID, BLUEPRINT_NAME); AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver(); provider.addObserver(observer); provider.deleteResources(new RequestImpl(null, null, null, null), predicate); ResourceProviderEvent lastEvent = observer.getLastEvent(); assertNotNull(lastEvent); assertEquals(Resource.Type.Blueprint, lastEvent.getResourceType()); assertEquals(ResourceProviderEvent.Type.Delete, lastEvent.getType()); assertNotNull(lastEvent.getPredicate()); verify(dao); }