AbstractControllerResourceProvider extends AbstractAuthorizedResourceProvider { public static ResourceProvider getResourceProvider(Resource.Type type, Set<String> propertyIds, Map<Resource.Type, String> keyPropertyIds, AmbariManagementController managementController) { switch (type.getInternalType()) { case Cluster: return new ClusterResourceProvider(managementController); case Service: return resourceProviderFactory.getServiceResourceProvider(propertyIds, keyPropertyIds, managementController); case Component: return resourceProviderFactory.getComponentResourceProvider(propertyIds, keyPropertyIds, managementController); case Host: return resourceProviderFactory.getHostResourceProvider(propertyIds, keyPropertyIds, managementController); case HostComponent: return resourceProviderFactory.getHostComponentResourceProvider(propertyIds, keyPropertyIds, managementController); case Configuration: return new ConfigurationResourceProvider(managementController); case ServiceConfigVersion: return new ServiceConfigVersionResourceProvider(managementController); case Action: return new ActionResourceProvider(propertyIds, keyPropertyIds, managementController); case Request: return new RequestResourceProvider(propertyIds, keyPropertyIds, managementController); case Task: return new TaskResourceProvider(propertyIds, keyPropertyIds, managementController); case User: return new UserResourceProvider(propertyIds, keyPropertyIds, managementController); case Group: return new GroupResourceProvider(propertyIds, keyPropertyIds, managementController); case Member: return resourceProviderFactory.getMemberResourceProvider(propertyIds, keyPropertyIds, managementController); case Upgrade: return resourceProviderFactory.getUpgradeResourceProvider(managementController); case Stack: return new StackResourceProvider(propertyIds, keyPropertyIds, managementController); case StackVersion: return new StackVersionResourceProvider(propertyIds, keyPropertyIds, managementController); case ClusterStackVersion: return new ClusterStackVersionResourceProvider(managementController); case HostStackVersion: return new HostStackVersionResourceProvider(managementController); case StackService: return new StackServiceResourceProvider(propertyIds, keyPropertyIds, managementController); case StackServiceComponent: return new StackServiceComponentResourceProvider(propertyIds, keyPropertyIds, managementController); case StackConfiguration: return new StackConfigurationResourceProvider(propertyIds, keyPropertyIds, managementController); case StackConfigurationDependency: return new StackConfigurationDependencyResourceProvider(propertyIds, keyPropertyIds, managementController); case StackLevelConfiguration: return new StackLevelConfigurationResourceProvider(propertyIds, keyPropertyIds, managementController); case ExtensionLink: return new ExtensionLinkResourceProvider(propertyIds, keyPropertyIds, managementController); case Extension: return new ExtensionResourceProvider(propertyIds, keyPropertyIds, managementController); case ExtensionVersion: return new ExtensionVersionResourceProvider(propertyIds, keyPropertyIds, managementController); case RootService: return new RootServiceResourceProvider(propertyIds, keyPropertyIds, managementController); case RootServiceComponent: return new RootServiceComponentResourceProvider(propertyIds, keyPropertyIds, managementController); case RootServiceHostComponent: return new RootServiceHostComponentResourceProvider(propertyIds, keyPropertyIds, managementController); case ConfigGroup: return new ConfigGroupResourceProvider(propertyIds, keyPropertyIds, managementController); case RequestSchedule: return new RequestScheduleResourceProvider(propertyIds, keyPropertyIds, managementController); case HostComponentProcess: return new HostComponentProcessResourceProvider(propertyIds, keyPropertyIds, managementController); case Blueprint: return new BlueprintResourceProvider(propertyIds, keyPropertyIds, managementController); case KerberosDescriptor: return resourceProviderFactory.getKerberosDescriptorResourceProvider(managementController, propertyIds, keyPropertyIds); case Recommendation: return new RecommendationResourceProvider(propertyIds, keyPropertyIds, managementController); case Validation: return new ValidationResourceProvider(propertyIds, keyPropertyIds, managementController); case ClientConfig: return new ClientConfigResourceProvider(propertyIds, keyPropertyIds, managementController); case RepositoryVersion: return resourceProviderFactory.getRepositoryVersionResourceProvider(); case CompatibleRepositoryVersion: return new CompatibleRepositoryVersionResourceProvider(managementController); case StackArtifact: return new StackArtifactResourceProvider(managementController); case Theme: return new ThemeArtifactResourceProvider(managementController); case QuickLink: return new QuickLinkArtifactResourceProvider(managementController); case ActiveWidgetLayout: return new ActiveWidgetLayoutResourceProvider(managementController); case WidgetLayout: return new WidgetLayoutResourceProvider(managementController); case Widget: return new WidgetResourceProvider(managementController); case HostKerberosIdentity: return resourceProviderFactory.getHostKerberosIdentityResourceProvider(managementController); case Credential: return resourceProviderFactory.getCredentialResourceProvider(managementController); case RoleAuthorization: return new RoleAuthorizationResourceProvider(managementController); case UserAuthorization: return new UserAuthorizationResourceProvider(managementController); case VersionDefinition: return new VersionDefinitionResourceProvider(); case ClusterKerberosDescriptor: return new ClusterKerberosDescriptorResourceProvider(managementController); case LoggingQuery: return new LoggingResourceProvider(propertyIds, keyPropertyIds, managementController); default: throw new IllegalArgumentException("Unknown type " + type); } } protected  AbstractControllerResourceProvider(Set<String> propertyIds,
                                               Map<Resource.Type, String> keyPropertyIds,
                                               AmbariManagementController managementController); static void init(ResourceProviderFactory factory); static ResourceProvider getResourceProvider(Resource.Type type,
                                                     Set<String> propertyIds,
                                                     Map<Resource.Type, String> keyPropertyIds,
                                                     AmbariManagementController managementController);  }
@Test public void testGetResourceProvider() 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); ResourceProviderFactory factory = createMock(ResourceProviderFactory.class); MaintenanceStateHelper maintenanceStateHelper = createNiceMock(MaintenanceStateHelper.class); ResourceProvider serviceResourceProvider = new ServiceResourceProvider(propertyIds, keyPropertyIds, managementController, maintenanceStateHelper); expect(factory.getServiceResourceProvider(propertyIds, keyPropertyIds, managementController)).andReturn(serviceResourceProvider); AbstractControllerResourceProvider.init(factory); replay(managementController, factory, maintenanceStateHelper); AbstractResourceProvider provider = (AbstractResourceProvider) AbstractControllerResourceProvider.getResourceProvider( Resource.Type.Service, propertyIds, keyPropertyIds, managementController); Assert.assertTrue(provider instanceof ServiceResourceProvider); }
@Test public void testGetStackArtifactResourceProvider() { AmbariManagementController managementController = createMock(AmbariManagementController.class); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( Resource.Type.StackArtifact, null, null, managementController); assertEquals(StackArtifactResourceProvider.class, provider.getClass()); }
@Test public void testGetRoleAuthorizationResourceProvider() { AmbariManagementController managementController = createMock(AmbariManagementController.class); replay(managementController); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( Resource.Type.RoleAuthorization, null, null, managementController); verify(managementController); assertEquals(RoleAuthorizationResourceProvider.class, provider.getClass()); }
@Test public void testGetUserAuthorizationResourceProvider() { AmbariManagementController managementController = createMock(AmbariManagementController.class); replay(managementController); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( Resource.Type.UserAuthorization, null, null, managementController); verify(managementController); assertEquals(UserAuthorizationResourceProvider.class, provider.getClass()); }
@Test public void testGetClusterKerberosDescriptorResourceProvider() { AmbariManagementController managementController = createMock(AmbariManagementController.class); replay(managementController); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( Resource.Type.ClusterKerberosDescriptor, null, null, managementController); verify(managementController); assertEquals(ClusterKerberosDescriptorResourceProvider.class, provider.getClass()); }