@Test
  public void createUserTest() throws Exception {
    Authentication authentication = TestAuthenticationFactory.createAdministrator();
    SecurityContextHolder.getContext().setAuthentication(authentication);

    // create a new user viewUser
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "viewUser");
    requestProperties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password");
    requestProperties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, false);
    requestProperties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, true);

    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null);
    RequestStatus requestStatus = userResourceProvider.createResources(request);
    assertNotNull(requestStatus);

    // verify the created username
    Request getRequest = PropertyHelper.getReadRequest(new HashSet<>(Collections.singleton("Users")));
    Predicate predicate = new PredicateBuilder()
        .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals("viewUser").toPredicate();
    Set<Resource> resources = userResourceProvider.getResources(getRequest, predicate);
    assertEquals(resources.size(), 1);
    Resource resource = resources.iterator().next();

    String userName = resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID).toString();
    assertEquals("viewuser", userName);

    // delete the created username
    requestStatus = userResourceProvider.deleteResources(request, predicate);
    assertNotNull(requestStatus);

    // verify that the username was deleted
    resources = userResourceProvider.getResources(getRequest, null);
    assertEquals(resources.size(), 0);
  }
Creates a user, retrieves it and verifies that the username matches the one that was
created. Deletes the created user and verifies that the username was deleted.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderDBTest.java