private void createResourcesTest(Authentication authentication, Set<Map<String, Object>> resourceProperties) throws Exception {
    Injector injector = createInjector();
    UserDAO userDAO = injector.getInstance(UserDAO.class);
    Capture<? extends UserEntity> userEntityCapture = newCapture(CaptureType.ALL);

    Map<String, Map<String, Object>> expectedUsers = new HashMap<>();

    for (Map<String, Object> properties : resourceProperties) {
      String username = (String) properties.get(UserResourceProvider.USER_USERNAME_PROPERTY_ID);

      if (!StringUtils.isEmpty(username)) {
        Assert.assertFalse("User names must be unique for this test case", expectedUsers.containsKey(username.toLowerCase()));

        expect(userDAO.findUserByName(username)).andReturn(null).times(2);
        userDAO.create(capture(userEntityCapture));
        expectLastCall().once();

        PrincipalTypeEntity principalTypeEntity = createMock(PrincipalTypeEntity.class);

        PrincipalTypeDAO principalTypeDAO = injector.getInstance(PrincipalTypeDAO.class);
        expect(principalTypeDAO.findById(PrincipalTypeEntity.USER_PRINCIPAL_TYPE)).andReturn(principalTypeEntity).once();

        PrincipalDAO principalDAO = injector.getInstance(PrincipalDAO.class);
        principalDAO.create(anyObject(PrincipalEntity.class));
        expectLastCall().andAnswer(new IAnswer<Object>() {
          @Override
          public Object answer() throws Throwable {
            Object[] args = getCurrentArguments();

            ((PrincipalEntity) args[0]).setId(1L);
            return null;
          }
        }).once();


        HookContextFactory hookContextFactory = injector.getInstance(HookContextFactory.class);
        expect(hookContextFactory.createUserHookContext(username)).andReturn(null).once();

        HookService hookService = injector.getInstance(HookService.class);
        expect(hookService.execute(anyObject(HookContext.class))).andReturn(true).once();


        if (properties.get(UserResourceProvider.USER_PASSWORD_PROPERTY_ID) != null) {
          ResourceProviderFactory factory = createMock(ResourceProviderFactory.class);
          ResourceProvider resourceProvider = createMock(ResourceProvider.class);
          RequestStatus status = createMock(RequestStatus.class);
          expect(resourceProvider.createResources(anyObject(Request.class))).andReturn(status).once();
          expect(factory.getUserAuthenticationSourceResourceProvider()).andReturn(resourceProvider).once();

          AbstractControllerResourceProvider.init(factory);
        }

        if (properties.get(UserResourceProvider.USER_ADMIN_PROPERTY_ID) != null) {
          Boolean isAdmin = Boolean.TRUE.equals(properties.get(UserResourceProvider.USER_ADMIN_PROPERTY_ID));

          if (isAdmin) {
            PermissionEntity permissionEntity = createMock(PermissionEntity.class);
            PermissionDAO permissionDAO = injector.getInstance(PermissionDAO.class);
            expect(permissionDAO.findAmbariAdminPermission()).andReturn(permissionEntity).once();

            ResourceEntity resourceEntity = createMock(ResourceEntity.class);
            ResourceDAO resourceDAO = injector.getInstance(ResourceDAO.class);
            expect(resourceDAO.findAmbariResource()).andReturn(resourceEntity).once();

            PrivilegeDAO privilegeDAO = injector.getInstance(PrivilegeDAO.class);
            privilegeDAO.create(anyObject(PrivilegeEntity.class));
            expectLastCall().andAnswer(new IAnswer<Object>() {
              @Override
              public Object answer() throws Throwable {
                Object[] args = getCurrentArguments();

                ((PrivilegeEntity) args[0]).setId(1);
                return null;
              }
            }).once();

            expect(principalDAO.merge(anyObject(PrincipalEntity.class))).andReturn(null).once();

            expect(userDAO.merge(anyObject(UserEntity.class))).andReturn(null).once();
          }
        }

        expectedUsers.put(username.toLowerCase(), properties);
      }
    }

    // replay
    replayAll();

    SecurityContextHolder.getContext().setAuthentication(authentication);

    AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
    ambariMetaInfo.init();

    ResourceProvider provider = getResourceProvider(injector);

    // create the request
    Request request = PropertyHelper.getCreateRequest(resourceProperties, null);

    provider.createResources(request);

    // verify
    verifyAll();

    List<? extends UserEntity> capturedUserEntities = userEntityCapture.getValues();
    Assert.assertEquals(expectedUsers.size(), capturedUserEntities.size());

    for (UserEntity userEntity : capturedUserEntities) {
      String userName = userEntity.getUserName();
      Map<String, Object> userProperties = expectedUsers.get(userName);

      Assert.assertNotNull(userProperties);

      String username = (String) userProperties.get(UserResourceProvider.USER_USERNAME_PROPERTY_ID);
      String displayName = (String) userProperties.get(UserResourceProvider.USER_DISPLAY_NAME_PROPERTY_ID);
      String localUsername = (String) userProperties.get(UserResourceProvider.USER_LOCAL_USERNAME_PROPERTY_ID);
      Boolean isActive = (userProperties.containsKey(UserResourceProvider.USER_ACTIVE_PROPERTY_ID))
          ? !Boolean.FALSE.equals(userProperties.get(UserResourceProvider.USER_ACTIVE_PROPERTY_ID))
          : Boolean.TRUE;

      Assert.assertEquals(username.toLowerCase(), userEntity.getUserName());
      Assert.assertEquals(StringUtils.defaultIfEmpty(localUsername, username), userEntity.getLocalUsername());
      Assert.assertEquals(StringUtils.defaultIfEmpty(displayName, username), userEntity.getDisplayName());
      Assert.assertEquals(isActive, userEntity.getActive());
    }
  }
Test give a user Ambari administrative rights by assigning the user to the AMBARI.ADMINISTRATOR role
when creating the account. This is for backward compatibility to maintain the REST API V1 contract.
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java