ServiceResourceProvider extends AbstractControllerResourceProvider { @Override public Set<String> checkPropertyIds(Set<String> propertyIds) { propertyIds = super.checkPropertyIds(propertyIds); if (propertyIds.isEmpty()) { return propertyIds; } Set<String> unsupportedProperties = new HashSet<String>(); for (String propertyId : propertyIds) { if (!propertyId.equals("config")) { String propertyCategory = PropertyHelper.getPropertyCategory(propertyId); if (propertyCategory == null || !propertyCategory.equals("config")) { unsupportedProperties.add(propertyId); } } } return unsupportedProperties; } @AssistedInject  ServiceResourceProvider(@Assisted Set<String> propertyIds,
                          @Assisted Map<Resource.Type, String> keyPropertyIds,
                          @Assisted AmbariManagementController managementController,
                          MaintenanceStateHelper maintenanceStateHelper); @Override Set<String> checkPropertyIds(Set<String> propertyIds); void createServices(Set<ServiceRequest> requests); static final String SERVICE_CLUSTER_NAME_PROPERTY_ID; static final String SERVICE_SERVICE_NAME_PROPERTY_ID; static final String SERVICE_SERVICE_STATE_PROPERTY_ID; static final String SERVICE_MAINTENANCE_STATE_PROPERTY_ID; static final String SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID; static final String SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID; static final String SERVICE_ATTRIBUTES_PROPERTY_ID; }
@Test public void testCheckPropertyIds() throws Exception { Set<String> propertyIds = new HashSet<String>(); propertyIds.add("foo"); propertyIds.add("cat1/foo"); propertyIds.add("cat2/bar"); propertyIds.add("cat2/baz"); propertyIds.add("cat3/sub1/bam"); propertyIds.add("cat4/sub2/sub3/bat"); propertyIds.add("cat5/subcat5/map"); Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>(); AmbariManagementController managementController = createMock(AmbariManagementController.class); MaintenanceStateHelper maintenanceStateHelperMock = createNiceMock(MaintenanceStateHelper.class); AbstractResourceProvider provider = new ServiceResourceProvider(propertyIds, keyPropertyIds, managementController, maintenanceStateHelperMock); Set<String> unsupported = provider.checkPropertyIds(Collections.singleton("foo")); Assert.assertTrue(unsupported.isEmpty()); Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat5/subcat5/map/key")).isEmpty()); unsupported = provider.checkPropertyIds(Collections.singleton("bar")); Assert.assertEquals(1, unsupported.size()); Assert.assertTrue(unsupported.contains("bar")); unsupported = provider.checkPropertyIds(Collections.singleton("cat1/foo")); Assert.assertTrue(unsupported.isEmpty()); unsupported = provider.checkPropertyIds(Collections.singleton("cat1")); Assert.assertTrue(unsupported.isEmpty()); unsupported = provider.checkPropertyIds(Collections.singleton("config")); Assert.assertTrue(unsupported.isEmpty()); unsupported = provider.checkPropertyIds(Collections.singleton("config/unknown_property")); Assert.assertTrue(unsupported.isEmpty()); }