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

        /* add a new user */
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "abcd");
    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);

        /* try with uppercase version of an existing user */
    requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "ABCD");
    request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null);
    try {
      requestStatus = userResourceProvider.createResources(request);
      assertTrue("Should fail with user exists", false);
    } catch (Exception ex) {
      assertTrue(ex.getMessage().contains("already exists"));
    }

    // delete the created username
    Predicate predicate = new PredicateBuilder()
        .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals("abcd").toPredicate();
    requestStatus = userResourceProvider.deleteResources(request, predicate);
    assertNotNull(requestStatus);

    // verify that the username was deleted
    Request getRequest = PropertyHelper.getReadRequest(new HashSet<>(Arrays.asList("Users")));
    Set<Resource> resources = userResourceProvider.getResources(getRequest, null);
    assertEquals(resources.size(), 0);
  }
Creates a username in all lowercase. Attempt to add another user whose username differs only
by case to the previously added user. Verifies that the user cannot be added.

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