private void deleteResourcesTest(Authentication authentication, String requestedUsername) throws Exception {
    Injector injector = createInjector();

    UserEntity userEntity = createMockUserEntity(requestedUsername);

    List<PrincipalEntity> adminPrincipals = Collections.singletonList(createMock(PrincipalEntity.class));

    List<UserEntity> adminUserEntities = new ArrayList<>();
    adminUserEntities.add(createMockUserEntity("some admin"));
    if ("admin".equals(requestedUsername)) {
      adminUserEntities.add(userEntity);
    }

    UserDAO userDAO = injector.getInstance(UserDAO.class);
    expect(userDAO.findUserByName(requestedUsername)).andReturn(userEntity).once();
    (expect(userDAO.findUsersByPrincipal(adminPrincipals))).andReturn(adminUserEntities).once();
    userDAO.remove(userEntity);
    expectLastCall().atLeastOnce();

    PrincipalDAO principalDAO = injector.getInstance(PrincipalDAO.class);
    expect(principalDAO.findByPermissionId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION)).andReturn(adminPrincipals).once();

    // replay
    replayAll();

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

    SecurityContextHolder.getContext().setAuthentication(authentication);

    ResourceProvider provider = getResourceProvider(injector);

    provider.deleteResources(new RequestImpl(null, null, null, null), createPredicate(requestedUsername));

    // verify
    verifyAll();
  }
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