http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentConfigurationResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentConfigurationResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentConfigurationResourceProviderTest.java new file mode 100644 index 0000000..5016160 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentConfigurationResourceProviderTest.java @@ -0,0 +1,393 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.controller.internal; + +import static org.apache.ambari.server.controller.internal.RootServiceComponentConfigurationResourceProvider.CONFIGURATION_CATEGORY_PROPERTY_ID; +import static org.apache.ambari.server.controller.internal.RootServiceComponentConfigurationResourceProvider.CONFIGURATION_COMPONENT_NAME_PROPERTY_ID; +import static org.apache.ambari.server.controller.internal.RootServiceComponentConfigurationResourceProvider.CONFIGURATION_PROPERTIES_PROPERTY_ID; +import static org.apache.ambari.server.controller.internal.RootServiceComponentConfigurationResourceProvider.CONFIGURATION_SERVICE_NAME_PROPERTY_ID; +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.capture; +import static org.easymock.EasyMock.eq; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.newCapture; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +import javax.persistence.EntityManager; + +import org.apache.ambari.server.controller.RootComponent; +import org.apache.ambari.server.controller.RootService; +import org.apache.ambari.server.controller.predicate.AndPredicate; +import org.apache.ambari.server.controller.spi.Predicate; +import org.apache.ambari.server.controller.spi.Request; +import org.apache.ambari.server.controller.spi.Resource; +import org.apache.ambari.server.controller.spi.ResourceProvider; +import org.apache.ambari.server.controller.utilities.PredicateBuilder; +import org.apache.ambari.server.events.AmbariConfigurationChangedEvent; +import org.apache.ambari.server.events.publishers.AmbariEventPublisher; +import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO; +import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity; +import org.apache.ambari.server.security.TestAuthenticationFactory; +import org.apache.ambari.server.security.authorization.AuthorizationException; +import org.easymock.Capture; +import org.easymock.EasyMockSupport; +import org.junit.After; +import org.junit.Test; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; + +import junit.framework.Assert; + +public class RootServiceComponentConfigurationResourceProviderTest extends EasyMockSupport { + + private static final String CATEGORY_NAME_1 = "test-category-1"; + private static final String CATEGORY_NAME_2 = "test-category-2"; + + @After + public void clearAuthentication() { + SecurityContextHolder.getContext().setAuthentication(null); + } + + @Test + public void testCreateResources_Administrator() throws Exception { + testCreateResources(TestAuthenticationFactory.createAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testCreateResources_ClusterAdministrator() throws Exception { + testCreateResources(TestAuthenticationFactory.createClusterAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testCreateResources_ClusterOperator() throws Exception { + testCreateResources(TestAuthenticationFactory.createClusterOperator()); + } + + @Test(expected = AuthorizationException.class) + public void testCreateResources_ServiceAdministrator() throws Exception { + testCreateResources(TestAuthenticationFactory.createServiceAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testCreateResources_ServiceOperator() throws Exception { + testCreateResources(TestAuthenticationFactory.createServiceOperator()); + } + + private void testCreateResources(Authentication authentication) throws Exception { + Injector injector = createInjector(); + + ResourceProvider resourceProvider = injector.getInstance(RootServiceComponentConfigurationResourceProvider.class); + + Set<Map<String, Object>> propertySets = new HashSet<>(); + + Map<String, String> properties1 = new HashMap<>(); + properties1.put("property1a", "value1"); + properties1.put("property2a", "value2"); + propertySets.add(toRequestProperties(CATEGORY_NAME_1, properties1)); + + Map<String, String> properties2 = new HashMap<>(); + properties2.put("property1b", "value1"); + properties2.put("property2b", "value2"); + propertySets.add(toRequestProperties(CATEGORY_NAME_2, properties2)); + + Request request = createMock(Request.class); + expect(request.getProperties()).andReturn(propertySets).once(); + + Capture<Map<String, String>> capturedProperties1 = newCapture(); + Capture<Map<String, String>> capturedProperties2 = newCapture(); + + AmbariConfigurationDAO dao = injector.getInstance(AmbariConfigurationDAO.class); + expect(dao.reconcileCategory(eq(CATEGORY_NAME_1), capture(capturedProperties1), eq(true))) + .andReturn(true) + .once(); + expect(dao.reconcileCategory(eq(CATEGORY_NAME_2), capture(capturedProperties2), eq(true))) + .andReturn(true) + .once(); + + AmbariEventPublisher publisher = injector.getInstance(AmbariEventPublisher.class); + publisher.publish(anyObject(AmbariConfigurationChangedEvent.class)); + expectLastCall().times(2); + + replayAll(); + + SecurityContextHolder.getContext().setAuthentication(authentication); + + resourceProvider.createResources(request); + + verifyAll(); + + validateCapturedProperties(properties1, capturedProperties1); + validateCapturedProperties(properties2, capturedProperties2); + } + + @Test + public void testDeleteResources_Administrator() throws Exception { + testDeleteResources(TestAuthenticationFactory.createAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testDeleteResources_ClusterAdministrator() throws Exception { + testDeleteResources(TestAuthenticationFactory.createClusterAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testDeleteResources_ClusterOperator() throws Exception { + testDeleteResources(TestAuthenticationFactory.createClusterOperator()); + } + + @Test(expected = AuthorizationException.class) + public void testDeleteResources_ServiceAdministrator() throws Exception { + testDeleteResources(TestAuthenticationFactory.createServiceAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testDeleteResources_ServiceOperator() throws Exception { + testDeleteResources(TestAuthenticationFactory.createServiceOperator()); + } + + private void testDeleteResources(Authentication authentication) throws Exception { + Injector injector = createInjector(); + + ResourceProvider resourceProvider = injector.getInstance(RootServiceComponentConfigurationResourceProvider.class); + + Predicate predicate = createPredicate(RootService.AMBARI.name(), RootComponent.AMBARI_SERVER.name(), CATEGORY_NAME_1); + + Request request = createMock(Request.class); + + AmbariConfigurationDAO dao = injector.getInstance(AmbariConfigurationDAO.class); + expect(dao.removeByCategory(CATEGORY_NAME_1)).andReturn(1).once(); + + AmbariEventPublisher publisher = injector.getInstance(AmbariEventPublisher.class); + publisher.publish(anyObject(AmbariConfigurationChangedEvent.class)); + expectLastCall().once(); + + replayAll(); + + SecurityContextHolder.getContext().setAuthentication(authentication); + + resourceProvider.deleteResources(request, predicate); + + verifyAll(); + } + + @Test + public void testGetResources_Administrator() throws Exception { + testGetResources(TestAuthenticationFactory.createAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testGetResources_ClusterAdministrator() throws Exception { + testGetResources(TestAuthenticationFactory.createClusterAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testGetResources_ClusterOperator() throws Exception { + testGetResources(TestAuthenticationFactory.createClusterOperator()); + } + + @Test(expected = AuthorizationException.class) + public void testGetResources_ServiceAdministrator() throws Exception { + testGetResources(TestAuthenticationFactory.createServiceAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testGetResources_ServiceOperator() throws Exception { + testGetResources(TestAuthenticationFactory.createServiceOperator()); + } + + private void testGetResources(Authentication authentication) throws Exception { + Injector injector = createInjector(); + + ResourceProvider resourceProvider = injector.getInstance(RootServiceComponentConfigurationResourceProvider.class); + + Predicate predicate = createPredicate(RootService.AMBARI.name(), RootComponent.AMBARI_SERVER.name(), CATEGORY_NAME_1); + + Request request = createMock(Request.class); + expect(request.getPropertyIds()).andReturn(null).anyTimes(); + + Map<String, String> properties = new HashMap<>(); + properties.put("property1a", "value1"); + properties.put("property2a", "value2"); + + AmbariConfigurationDAO dao = injector.getInstance(AmbariConfigurationDAO.class); + expect(dao.findByCategory(CATEGORY_NAME_1)).andReturn(createEntities(CATEGORY_NAME_1, properties)).once(); + + replayAll(); + + SecurityContextHolder.getContext().setAuthentication(authentication); + + Set<Resource> response = resourceProvider.getResources(request, predicate); + + verifyAll(); + + Assert.assertNotNull(response); + Assert.assertEquals(1, response.size()); + + Resource resource = response.iterator().next(); + Assert.assertEquals(Resource.Type.RootServiceComponentConfiguration, resource.getType()); + + Map<String, Map<String, Object>> propertiesMap = resource.getPropertiesMap(); + Assert.assertEquals(2, propertiesMap.size()); + + Assert.assertEquals(CATEGORY_NAME_1, propertiesMap.get(RootServiceComponentConfigurationResourceProvider.RESOURCE_KEY).get("category")); + + Map<String, Object> retrievedProperties = propertiesMap.get(RootServiceComponentConfigurationResourceProvider.RESOURCE_KEY + "/properties"); + Assert.assertEquals(2, retrievedProperties.size()); + + for (Map.Entry<String, String> entry : properties.entrySet()) { + Assert.assertEquals(entry.getValue(), retrievedProperties.get(entry.getKey())); + } + } + + @Test + public void testUpdateResources_Administrator() throws Exception { + testUpdateResources(TestAuthenticationFactory.createAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testUpdateResources_ClusterAdministrator() throws Exception { + testUpdateResources(TestAuthenticationFactory.createClusterAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testUpdateResources_ClusterOperator() throws Exception { + testUpdateResources(TestAuthenticationFactory.createClusterOperator()); + } + + @Test(expected = AuthorizationException.class) + public void testUpdateResources_ServiceAdministrator() throws Exception { + testUpdateResources(TestAuthenticationFactory.createServiceAdministrator()); + } + + @Test(expected = AuthorizationException.class) + public void testUpdateResources_ServiceOperator() throws Exception { + testUpdateResources(TestAuthenticationFactory.createServiceOperator()); + } + + private void testUpdateResources(Authentication authentication) throws Exception { + Injector injector = createInjector(); + + ResourceProvider resourceProvider = injector.getInstance(RootServiceComponentConfigurationResourceProvider.class); + + Predicate predicate = createPredicate(RootService.AMBARI.name(), RootComponent.AMBARI_SERVER.name(), CATEGORY_NAME_1); + + Set<Map<String, Object>> propertySets = new HashSet<>(); + + Map<String, String> properties1 = new HashMap<>(); + properties1.put("property1a", "value1"); + properties1.put("property2a", "value2"); + propertySets.add(toRequestProperties(CATEGORY_NAME_1, properties1)); + + Request request = createMock(Request.class); + expect(request.getProperties()).andReturn(propertySets).once(); + + Capture<Map<String, String>> capturedProperties1 = newCapture(); + + AmbariConfigurationDAO dao = injector.getInstance(AmbariConfigurationDAO.class); + expect(dao.reconcileCategory(eq(CATEGORY_NAME_1), capture(capturedProperties1), eq(false))) + .andReturn(true) + .once(); + + AmbariEventPublisher publisher = injector.getInstance(AmbariEventPublisher.class); + publisher.publish(anyObject(AmbariConfigurationChangedEvent.class)); + expectLastCall().times(1); + + replayAll(); + + SecurityContextHolder.getContext().setAuthentication(authentication); + + resourceProvider.updateResources(request, predicate); + + verifyAll(); + + validateCapturedProperties(properties1, capturedProperties1); + } + + private Predicate createPredicate(String serviceName, String componentName, String categoryName) { + Predicate predicateService = new PredicateBuilder() + .property(CONFIGURATION_SERVICE_NAME_PROPERTY_ID) + .equals(serviceName) + .toPredicate(); + Predicate predicateComponent = new PredicateBuilder() + .property(CONFIGURATION_COMPONENT_NAME_PROPERTY_ID) + .equals(componentName) + .toPredicate(); + Predicate predicateCategory = new PredicateBuilder() + .property(CONFIGURATION_CATEGORY_PROPERTY_ID) + .equals(categoryName) + .toPredicate(); + return new AndPredicate(predicateService, predicateComponent, predicateCategory); + } + + private List<AmbariConfigurationEntity> createEntities(String categoryName, Map<String, String> properties) { + List<AmbariConfigurationEntity> entities = new ArrayList<>(); + + for (Map.Entry<String, String> property : properties.entrySet()) { + AmbariConfigurationEntity entity = new AmbariConfigurationEntity(); + entity.setCategoryName(categoryName); + entity.setPropertyName(property.getKey()); + entity.setPropertyValue(property.getValue()); + entities.add(entity); + } + + return entities; + } + + private Map<String, Object> toRequestProperties(String categoryName1, Map<String, String> properties) { + Map<String, Object> requestProperties = new HashMap<>(); + requestProperties.put(CONFIGURATION_SERVICE_NAME_PROPERTY_ID, "AMBARI"); + requestProperties.put(CONFIGURATION_COMPONENT_NAME_PROPERTY_ID, "AMBARI_SERVER"); + requestProperties.put(CONFIGURATION_CATEGORY_PROPERTY_ID, categoryName1); + for (Map.Entry<String, String> entry : properties.entrySet()) { + requestProperties.put(CONFIGURATION_PROPERTIES_PROPERTY_ID + "/" + entry.getKey(), entry.getValue()); + } + return requestProperties; + } + + private void validateCapturedProperties(Map<String, String> expectedProperties, Capture<Map<String, String>> capturedProperties) { + Assert.assertTrue(capturedProperties.hasCaptured()); + + Map<String, String> properties = capturedProperties.getValue(); + Assert.assertNotNull(properties); + + // Convert the Map to a TreeMap to help with comparisons + expectedProperties = new TreeMap<>(expectedProperties); + properties = new TreeMap<>(properties); + Assert.assertEquals(expectedProperties, properties); + } + + private Injector createInjector() throws Exception { + return Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class)); + bind(AmbariConfigurationDAO.class).toInstance(createMock(AmbariConfigurationDAO.class)); + bind(AmbariEventPublisher.class).toInstance(createMock(AmbariEventPublisher.class)); + } + }); + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentPropertyProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentPropertyProviderTest.java index a202516..d3f9bd1 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentPropertyProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentPropertyProviderTest.java @@ -24,7 +24,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.apache.ambari.server.controller.RootServiceResponseFactory; +import org.apache.ambari.server.controller.RootComponent; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.controller.spi.Request; import org.apache.ambari.server.controller.spi.Resource; import org.apache.ambari.server.controller.utilities.PropertyHelper; @@ -34,27 +35,27 @@ import org.junit.Test; public class RootServiceComponentPropertyProviderTest { @Test public void testPopulateResources_AmbariServer_None() throws Exception { - testPopulateResources(RootServiceResponseFactory.Components.AMBARI_SERVER.name(), false, false, false, false); + testPopulateResources(RootComponent.AMBARI_SERVER.name(), false, false, false, false); } @Test public void testPopulateResources_AmbariServer_CiphersAndJCEPolicy() throws Exception { - testPopulateResources(RootServiceResponseFactory.Components.AMBARI_SERVER.name(), true, true, true, true); + testPopulateResources(RootComponent.AMBARI_SERVER.name(), true, true, true, true); } @Test public void testPopulateResources_AmbariServer_JCEPolicy() throws Exception { - testPopulateResources(RootServiceResponseFactory.Components.AMBARI_SERVER.name(), false, true, false, true); + testPopulateResources(RootComponent.AMBARI_SERVER.name(), false, true, false, true); } @Test public void testPopulateResources_AmbariServer_Ciphers() throws Exception { - testPopulateResources(RootServiceResponseFactory.Components.AMBARI_SERVER.name(), true, false, true, false); + testPopulateResources(RootComponent.AMBARI_SERVER.name(), true, false, true, false); } @Test public void testPopulateResources_AmbariAgent_CiphersAndJCEPolicy() throws Exception { - testPopulateResources(RootServiceResponseFactory.Components.AMBARI_AGENT.name(), true, true, false, false); + testPopulateResources(RootComponent.AMBARI_AGENT.name(), true, true, false, false); } public void testPopulateResources(String componentName, @@ -64,7 +65,7 @@ public class RootServiceComponentPropertyProviderTest { Resource resource = new ResourceImpl(Resource.Type.RootService); resource.setProperty(RootServiceComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID, componentName); - resource.setProperty(RootServiceComponentResourceProvider.SERVICE_NAME_PROPERTY_ID, RootServiceResponseFactory.Services.AMBARI.name()); + resource.setProperty(RootServiceComponentResourceProvider.SERVICE_NAME_PROPERTY_ID, RootService.AMBARI.name()); HashSet<String> requestIds = new HashSet<>(); http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentResourceProviderTest.java index 222340b..4316647 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceComponentResourceProviderTest.java @@ -29,8 +29,9 @@ import java.util.Map; import java.util.Set; import org.apache.ambari.server.controller.AmbariManagementController; +import org.apache.ambari.server.controller.RootComponent; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.controller.RootServiceComponentResponse; -import org.apache.ambari.server.controller.RootServiceResponseFactory; import org.apache.ambari.server.controller.spi.Predicate; import org.apache.ambari.server.controller.spi.Request; import org.apache.ambari.server.controller.spi.Resource; @@ -50,12 +51,12 @@ public class RootServiceComponentResourceProviderTest { AmbariManagementController managementController = createMock(AmbariManagementController.class); Set<RootServiceComponentResponse> allResponse = new HashSet<>(); - String serviceName = RootServiceResponseFactory.Services.AMBARI.name(); + String serviceName = RootService.AMBARI.name(); Map<String, String> emptyMap = Collections.emptyMap(); allResponse.add(new RootServiceComponentResponse(serviceName, "component1", "1.1.1", emptyMap)); allResponse.add(new RootServiceComponentResponse(serviceName, "component2", "1.1.1", emptyMap)); allResponse.add(new RootServiceComponentResponse(serviceName, "component3", "1.1.1", emptyMap)); - allResponse.add(new RootServiceComponentResponse(serviceName, RootServiceResponseFactory.Components.AMBARI_SERVER.name(), "1.1.1", emptyMap)); + allResponse.add(new RootServiceComponentResponse(serviceName, RootComponent.AMBARI_SERVER.name(), "1.1.1", emptyMap)); Set<RootServiceComponentResponse> nameResponse = new HashSet<>(); nameResponse.add(new RootServiceComponentResponse(serviceName, "component4", "1.1.1", emptyMap)); @@ -92,7 +93,7 @@ public class RootServiceComponentResourceProviderTest { String componentName = (String) resource.getPropertyValue(RootServiceComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID); String componentVersion = (String) resource.getPropertyValue(RootServiceComponentResourceProvider.COMPONENT_VERSION_PROPERTY_ID); Long server_clock = (Long) resource.getPropertyValue(RootServiceComponentResourceProvider.SERVER_CLOCK_PROPERTY_ID); - if (componentName.equals(RootServiceResponseFactory.Components.AMBARI_SERVER.name())){ + if (componentName.equals(RootComponent.AMBARI_SERVER.name())){ Assert.assertNotNull(server_clock); } else { Assert.assertNull(server_clock); http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java index 30f5e22..3917cdf 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java @@ -125,8 +125,8 @@ public class LdapModuleFunctionalTest { return ldapPropsMap; } - private static Map<String, Object> getADProps() { - Map<String, Object> ldapPropsMap = Maps.newHashMap(); + private static Map<String, String> getADProps() { + Map<String, String> ldapPropsMap = Maps.newHashMap(); http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java index aa26498..1082250 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java @@ -23,7 +23,7 @@ import java.util.Map; public class TestAmbariLdapConfigurationFactory implements AmbariLdapConfigurationFactory { @Override - public AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration) { + public AmbariLdapConfiguration createLdapConfiguration(Map<String, String> configuration) { return new AmbariLdapConfiguration(configuration); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java index db0e5a9..97ce30e 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java @@ -163,12 +163,12 @@ public class AmbariLdapFacadeTest extends EasyMockSupport { public void testShouldLdapAttributeDetectionDelegateToTheRightServiceCalls() throws Exception { // configuration map with user attributes detected - Map<String, Object> userConfigMap = Maps.newHashMap(); + Map<String, String> userConfigMap = Maps.newHashMap(); userConfigMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), "uid"); AmbariLdapConfiguration userAttrDecoratedConfig = ambariLdapConfigurationFactory.createLdapConfiguration(userConfigMap); // configuration map with user+group attributes detected - Map<String, Object> groupConfigMap = Maps.newHashMap(userConfigMap); + Map<String, String> groupConfigMap = Maps.newHashMap(userConfigMap); groupConfigMap.put(AmbariLdapConfigKeys.GROUP_NAME_ATTRIBUTE.key(), "dn"); AmbariLdapConfiguration groupAttrDecoratedConfig = ambariLdapConfigurationFactory.createLdapConfiguration(groupConfigMap); http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java index 09dea1c..a44bf7c 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java @@ -78,7 +78,7 @@ public class DefaultLdapAttributeDetectionServiceTest extends EasyMockSupport { @SuppressWarnings("unchecked") public void shouldLdapUserAttributeDetection() throws Exception { // GIVEN - Map<String, Object> configMap = Maps.newHashMap(); + Map<String, String> configMap = Maps.newHashMap(); configMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com"); AmbariLdapConfiguration ldapConfiguration = ldapConfigurationFactory.createLdapConfiguration(configMap); @@ -109,7 +109,7 @@ public class DefaultLdapAttributeDetectionServiceTest extends EasyMockSupport { @Test(expected = AmbariLdapException.class) public void testShouldUserAttributeDetectionFailWhenLdapOerationFails() throws Exception { // GIVEN - Map<String, Object> configMap = Maps.newHashMap(); + Map<String, String> configMap = Maps.newHashMap(); configMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com"); AmbariLdapConfiguration ldapConfiguration = ldapConfigurationFactory.createLdapConfiguration(configMap); @@ -129,7 +129,7 @@ public class DefaultLdapAttributeDetectionServiceTest extends EasyMockSupport { @SuppressWarnings("unchecked") public void shouldLdapGroupAttributeDetection() throws Exception { // GIVEN - Map<String, Object> configMap = Maps.newHashMap(); + Map<String, String> configMap = Maps.newHashMap(); configMap.put(AmbariLdapConfigKeys.GROUP_SEARCH_BASE.key(), "dc=example,dc=com"); AmbariLdapConfiguration ldapConfiguration = ldapConfigurationFactory.createLdapConfiguration(configMap); @@ -160,7 +160,7 @@ public class DefaultLdapAttributeDetectionServiceTest extends EasyMockSupport { @Test(expected = AmbariLdapException.class) public void testShouldGroupAttributeDetectionFailWhenLdapOerationFails() throws Exception { // GIVEN - Map<String, Object> configMap = Maps.newHashMap(); + Map<String, String> configMap = Maps.newHashMap(); configMap.put(AmbariLdapConfigKeys.GROUP_SEARCH_BASE.key(), "dc=example,dc=com"); AmbariLdapConfiguration ldapConfiguration = ldapConfigurationFactory.createLdapConfiguration(configMap); http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java index 4d6d2a6..ec78e56 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java @@ -102,7 +102,7 @@ public class DefaultLdapConfigurationServiceTest extends EasyMockSupport { @Test public void testShouldUserAttributeConfigurationCheckSucceedWhenUserDnIsFound() throws Exception { // GIVEN - Map<String, Object> configMap = Maps.newHashMap(); + Map<String, String> configMap = Maps.newHashMap(); configMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), "person"); configMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), "uid"); @@ -126,7 +126,7 @@ public class DefaultLdapConfigurationServiceTest extends EasyMockSupport { @Test(expected = AmbariLdapException.class) public void testShouldUserAttributeConfigurationCheckFailWhenNoUsersFound() throws Exception { // GIVEN - Map<String, Object> configMap = Maps.newHashMap(); + Map<String, String> configMap = Maps.newHashMap(); configMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), "posixAccount"); configMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), "dn"); @@ -155,7 +155,7 @@ public class DefaultLdapConfigurationServiceTest extends EasyMockSupport { public void testShouldGroupAttributeConfigurationCheckSucceedWhenGroupForUserDnIsFound() throws Exception { // GIVEN - Map<String, Object> configMap = groupConfigObjectMap(); + Map<String, String> configMap = groupConfigObjectMap(); SearchRequest sr = new SearchRequestImpl(); @@ -184,7 +184,7 @@ public class DefaultLdapConfigurationServiceTest extends EasyMockSupport { public void testShouldGroupAttributeConfigurationCheckFailWhenNoGroupsForUserDnFound() throws Exception { // GIVEN - Map<String, Object> configMap = groupConfigObjectMap(); + Map<String, String> configMap = groupConfigObjectMap(); SearchRequest sr = new SearchRequestImpl(); @@ -208,8 +208,8 @@ public class DefaultLdapConfigurationServiceTest extends EasyMockSupport { } - private Map<String, Object> groupConfigObjectMap() { - Map<String, Object> configMap = Maps.newHashMap(); + private Map<String, String> groupConfigObjectMap() { + Map<String, String> configMap = Maps.newHashMap(); configMap.put(AmbariLdapConfigKeys.GROUP_OBJECT_CLASS.key(), "groupOfNames"); configMap.put(AmbariLdapConfigKeys.GROUP_SEARCH_BASE.key(), "dc=example,dc=com"); configMap.put(AmbariLdapConfigKeys.GROUP_NAME_ATTRIBUTE.key(), "uid"); http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/metadata/AgentAlertDefinitionsTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/metadata/AgentAlertDefinitionsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/metadata/AgentAlertDefinitionsTest.java index adaf236..cb234ea 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/metadata/AgentAlertDefinitionsTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/metadata/AgentAlertDefinitionsTest.java @@ -22,7 +22,7 @@ import java.util.List; import javax.persistence.EntityManager; import org.apache.ambari.server.H2DatabaseCleaner; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Components; +import org.apache.ambari.server.controller.RootComponent; import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.state.alert.AlertDefinition; @@ -63,7 +63,7 @@ public class AgentAlertDefinitionsTest { Assert.assertEquals(3, definitions.size()); for( AlertDefinition definition : definitions){ - Assert.assertEquals(Components.AMBARI_AGENT.name(), + Assert.assertEquals(RootComponent.AMBARI_AGENT.name(), definition.getComponentName()); Assert.assertEquals("AMBARI", definition.getServiceName()); @@ -80,7 +80,7 @@ public class AgentAlertDefinitionsTest { Assert.assertEquals(4, definitions.size()); for (AlertDefinition definition : definitions) { - Assert.assertEquals(Components.AMBARI_SERVER.name(), + Assert.assertEquals(RootComponent.AMBARI_SERVER.name(), definition.getComponentName()); Assert.assertEquals("AMBARI", definition.getServiceName()); http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java index d559e0c..9ebc2e5 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java @@ -31,7 +31,8 @@ import java.util.TimeZone; import java.util.UUID; import org.apache.ambari.server.H2DatabaseCleaner; -import org.apache.ambari.server.controller.RootServiceResponseFactory; +import org.apache.ambari.server.controller.RootComponent; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.orm.OrmTestHelper; @@ -148,8 +149,8 @@ public class AlertDefinitionDAOTest { for (; i < 15; i++) { AlertDefinitionEntity definition = new AlertDefinitionEntity(); definition.setDefinitionName("Alert Definition " + i); - definition.setServiceName(RootServiceResponseFactory.Services.AMBARI.name()); - definition.setComponentName(RootServiceResponseFactory.Components.AMBARI_AGENT.name()); + definition.setServiceName(RootService.AMBARI.name()); + definition.setComponentName(RootComponent.AMBARI_AGENT.name()); definition.setClusterId(clusterId); definition.setHash(UUID.randomUUID().toString()); definition.setScheduleInterval(60); http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java index 3ec6943..3056dd1 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java @@ -30,8 +30,8 @@ import javax.persistence.EntityManager; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.H2DatabaseCleaner; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Components; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Services; +import org.apache.ambari.server.controller.RootComponent; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.events.AlertReceivedEvent; import org.apache.ambari.server.events.AlertStateChangeEvent; import org.apache.ambari.server.events.listeners.alerts.AlertReceivedListener; @@ -335,8 +335,8 @@ public class AlertReceivedListenerTest { @Test public void testAgentAlertFromInvalidHost() { String definitionName = ALERT_DEFINITION + "1"; - String serviceName = Services.AMBARI.name(); - String componentName = Components.AMBARI_AGENT.name(); + String serviceName = RootService.AMBARI.name(); + String componentName = RootComponent.AMBARI_AGENT.name(); Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.OK); @@ -374,8 +374,8 @@ public class AlertReceivedListenerTest { @Test public void testAmbariServerValidAlerts() { String definitionName = ALERT_DEFINITION + "1"; - String serviceName = Services.AMBARI.name(); - String componentName = Components.AMBARI_SERVER.name(); + String serviceName = RootService.AMBARI.name(); + String componentName = RootComponent.AMBARI_SERVER.name(); Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.OK); @@ -415,8 +415,8 @@ public class AlertReceivedListenerTest { @Test public void testMissingClusterAndInvalidHost() { String definitionName = ALERT_DEFINITION + "1"; - String serviceName = Services.AMBARI.name(); - String componentName = Components.AMBARI_AGENT.name(); + String serviceName = RootService.AMBARI.name(); + String componentName = RootComponent.AMBARI_AGENT.name(); Alert alert1 = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.OK); http://git-wip-us.apache.org/repos/asf/ambari/blob/ae3b727a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java index bc8222c..c3db717 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Set; import org.apache.ambari.server.H2DatabaseCleaner; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Services; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.events.AggregateAlertRecalculateEvent; import org.apache.ambari.server.events.AlertEvent; import org.apache.ambari.server.events.AlertStateChangeEvent; @@ -501,7 +501,7 @@ public class AlertStateChangedEventTest extends EasyMockSupport { // create the definition for the AMBARI service AlertDefinitionEntity definition = createNiceMock(AlertDefinitionEntity.class); EasyMock.expect(definition.getDefinitionId()).andReturn(1L).anyTimes(); - EasyMock.expect(definition.getServiceName()).andReturn(Services.AMBARI.name()).anyTimes(); + EasyMock.expect(definition.getServiceName()).andReturn(RootService.AMBARI.name()).anyTimes(); EasyMock.expect(definition.getLabel()).andReturn("ambari-foo-alert").anyTimes(); EasyMock.expect(definition.getDescription()).andReturn("Ambari Foo Alert").anyTimes();