ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [02/14] ambari git commit: AMBARI-18483. Revert db optimization in UT.(vbrodetskyi)
Date Thu, 29 Sep 2016 17:25:47 GMT
AMBARI-18483. Revert db optimization in UT.(vbrodetskyi)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/392a752d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/392a752d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/392a752d

Branch: refs/heads/branch-feature-AMBARI-18456
Commit: 392a752d27ce3d0dd7e044ce8c4ab5e9d10f6e74
Parents: 06282e0
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Wed Sep 28 14:02:38 2016 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Wed Sep 28 14:03:08 2016 +0300

----------------------------------------------------------------------
 .../server/agent/TestHeartbeatMonitor.java      |  32 +-
 ...ThreadPoolExecutorCompletionServiceTest.java |   2 +-
 .../apache/ambari/server/orm/OrmTestHelper.java |  12 +-
 .../apache/ambari/server/orm/TestOrmImpl.java   |  94 ++---
 .../server/orm/dao/AlertDispatchDAOTest.java    | 419 ++++++-------------
 .../security/authorization/TestUsers.java       | 369 ++++++----------
 .../upgrades/ConfigureActionTest.java           | 104 ++---
 .../upgrades/UpgradeActionTest.java             | 150 ++-----
 .../apache/ambari/server/state/ServiceTest.java | 106 ++---
 .../svccomphost/ServiceComponentHostTest.java   | 167 +++-----
 .../server/upgrade/UpgradeCatalog210Test.java   |  34 +-
 11 files changed, 456 insertions(+), 1033 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
index 63460a2..d121fcb 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
@@ -57,9 +57,7 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEve
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceededEvent;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartedEvent;
 import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.slf4j.Logger;
@@ -68,7 +66,6 @@ import org.slf4j.LoggerFactory;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.persist.PersistService;
-import com.google.inject.persist.UnitOfWork;
 
 public class TestHeartbeatMonitor {
 
@@ -86,44 +83,19 @@ public class TestHeartbeatMonitor {
   private static final Logger LOG =
           LoggerFactory.getLogger(TestHeartbeatMonitor.class);
 
-  @BeforeClass
-  public static void classSetUp() {
+  @Before
+  public void setup() throws Exception {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
     helper = injector.getInstance(OrmTestHelper.class);
     ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
   }
 
-  @Before
-  public void setup() throws Exception {
-    cleanup();
-    injector.getInstance(UnitOfWork.class).begin();
-  }
-
   @After
   public void teardown() {
-    injector.getInstance(UnitOfWork.class).end();
-  }
-
-  @AfterClass
-  public static void afterClass() throws Exception {
     injector.getInstance(PersistService.class).stop();
   }
 
-  private void cleanup() throws AmbariException {
-    Clusters clusters = injector.getInstance(Clusters.class);
-    Map<String, Cluster> clusterMap = clusters.getClusters();
-
-
-    for (String clusterName : clusterMap.keySet()) {
-      clusters.deleteCluster(clusterName);
-    }
-
-    for (Host host : clusters.getHosts()) {
-      clusters.deleteHost(host.getHostName());
-    }
-  }
-
   private void setOsFamily(Host host, String osFamily, String osVersion) {
     Map<String, String> hostAttributes = new HashMap<String, String>();
     hostAttributes.put("os_family", osFamily);

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java
index ec99ab0..50ed33b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java
@@ -31,7 +31,7 @@ import org.junit.Test;
 public class BufferedThreadPoolExecutorCompletionServiceTest {
 
   private void longOp() throws InterruptedException {
-    Thread.sleep(1000);
+    Thread.sleep(700);
     System.out.println("Completed " + Thread.currentThread());
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
index 1bfcfb9..de2d292 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
@@ -18,6 +18,8 @@
 
 package org.apache.ambari.server.orm;
 
+import javax.persistence.EntityManager;
+import junit.framework.Assert;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -33,8 +35,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
-import javax.persistence.EntityManager;
-
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
@@ -96,8 +96,6 @@ import com.google.inject.Provider;
 import com.google.inject.Singleton;
 import com.google.inject.persist.Transactional;
 
-import junit.framework.Assert;
-
 @Singleton
 public class OrmTestHelper {
 
@@ -501,7 +499,7 @@ public class OrmTestHelper {
     target.setTargetName("Target Name " + System.currentTimeMillis());
 
     alertDispatchDAO.create(target);
-    return alertDispatchDAO.findTargetById(target.getTargetId());
+    return target;
   }
 
   /**
@@ -518,7 +516,7 @@ public class OrmTestHelper {
     target.setGlobal(true);
 
     alertDispatchDAO.create(target);
-    return alertDispatchDAO.findTargetById(target.getTargetId());
+    return target;
   }
 
   /**
@@ -563,7 +561,7 @@ public class OrmTestHelper {
     group.setAlertTargets(targets);
 
     alertDispatchDAO.create(group);
-    return alertDispatchDAO.findGroupById(group.getGroupId());
+    return group;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java
index e72692a..0f6d2e2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java
@@ -48,98 +48,57 @@ import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.orm.entities.StageEntity;
 import org.apache.ambari.server.security.authorization.ResourceType;
 import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.inject.Guice;
+import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.persist.PersistService;
-import com.google.inject.persist.UnitOfWork;
 
 public class TestOrmImpl extends Assert {
   private static final Logger log = LoggerFactory.getLogger(TestOrmImpl.class);
+  @Inject
+  private Injector injector;
+  @Inject
+  private StackDAO stackDAO;
+  @Inject
+  private ResourceTypeDAO resourceTypeDAO;
+  @Inject
+  private ClusterDAO clusterDAO;
+  @Inject
+  private OrmTestHelper ormTestHelper;
+  @Inject
+  private ClusterServiceDAO clusterServiceDAO;
+  @Inject
+  private HostRoleCommandDAO hostRoleCommandDAO;
+  @Inject
+  private HostDAO hostDAO;
+  @Inject
+  private StageDAO stageDAO;
+  @Inject
+  private EntityManager entityManager;
+  @Inject
+  private RequestDAO requestDAO;
 
-  private static Injector injector;
-  private static StackDAO stackDAO;
-  private static ResourceTypeDAO resourceTypeDAO;
-  private static ClusterDAO clusterDAO;
-  private static OrmTestHelper ormTestHelper;
-  private static ClusterServiceDAO clusterServiceDAO;
-  private static HostRoleCommandDAO hostRoleCommandDAO;
-  private static HostDAO hostDAO;
-  private static StageDAO stageDAO;
-  private static EntityManager entityManager;
-  private static RequestDAO requestDAO;
-
-  @BeforeClass
-  public static void classSetUp() throws Exception {
+  @Before
+  public void setup() {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
-
+    injector.injectMembers(this);
     // required to load stack information into the DB
     injector.getInstance(AmbariMetaInfo.class);
-    stackDAO = injector.getInstance(StackDAO.class);
-    resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class);
-    clusterDAO = injector.getInstance(ClusterDAO.class);
-    ormTestHelper = injector.getInstance(OrmTestHelper.class);
-    clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
-    hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
-    hostDAO = injector.getInstance(HostDAO.class);
-    stageDAO = injector.getInstance(StageDAO.class);
-    entityManager = injector.getInstance(EntityManager.class);
-    requestDAO = injector.getInstance(RequestDAO.class);
-
     ormTestHelper.createDefaultData();
-    injector.getInstance(UnitOfWork.class).end();
-  }
-
-  @Before
-  public void setup() {
-    injector.getInstance(UnitOfWork.class).begin();
   }
 
   @After
   public void teardown() {
-    injector.getInstance(UnitOfWork.class).end();
-    cleanup();
-  }
-
-  @AfterClass
-  public static void afterClass() throws Exception {
     injector.getInstance(PersistService.class).stop();
   }
 
-  private void cleanup() {
-
-
-    List<HostRoleCommandEntity> hostRoleCommandEntities = hostRoleCommandDAO.findAll();
-    if (hostRoleCommandEntities != null) {
-      for (HostRoleCommandEntity hostRoleCommandEntity : hostRoleCommandEntities) {
-        hostRoleCommandDAO.remove(hostRoleCommandEntity);
-      }
-    }
-
-    List<StageEntity> stageEntities = stageDAO.findAll();
-    if (stageEntities != null) {
-      for (StageEntity stageEntity : stageEntities) {
-        stageDAO.remove(stageEntity);
-      }
-    }
-
-    List<RequestEntity> requestEntities = requestDAO.findAll();
-    if (requestEntities != null) {
-      for (RequestEntity requestEntity : requestEntities) {
-        requestDAO.remove(requestEntity);
-      }
-    }
-  }
-
   /**
    * persistence provider is responsible for returning empty collection if relation doesn't exists
    */
@@ -333,7 +292,6 @@ public class TestOrmImpl extends Assert {
     assertEquals(1L, stageDAO.getLastRequestId());
   }
 
-  @Ignore
   @Test
   public void testConcurrentModification() throws InterruptedException {
     final StackEntity stackEntity = stackDAO.find("HDP", "2.2.0");

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
index 5697ba0..87afb38 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
@@ -52,12 +52,9 @@ import org.apache.ambari.server.orm.entities.AlertGroupEntity;
 import org.apache.ambari.server.orm.entities.AlertHistoryEntity;
 import org.apache.ambari.server.orm.entities.AlertNoticeEntity;
 import org.apache.ambari.server.orm.entities.AlertTargetEntity;
-import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
-import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
 import org.apache.ambari.server.state.AlertState;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.NotificationState;
 import org.apache.ambari.server.state.ServiceComponentFactory;
 import org.apache.ambari.server.state.ServiceComponentHostFactory;
@@ -66,9 +63,7 @@ import org.apache.ambari.server.state.alert.Scope;
 import org.apache.ambari.server.state.alert.SourceType;
 import org.apache.ambari.server.utils.EventBusSynchronizer;
 import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.inject.Guice;
@@ -83,25 +78,30 @@ public class AlertDispatchDAOTest {
 
   private final static String HOSTNAME = "c6401.ambari.apache.org";
 
-  private static Clusters m_clusters;
-  private static Cluster m_cluster;
-  private static Injector m_injector;
-  private static AlertDispatchDAO m_dao;
-  private static AlertDefinitionDAO m_definitionDao;
-  private static AlertsDAO m_alertsDao;
-  private static OrmTestHelper m_helper;
-  private static HostComponentDesiredStateDAO hostComponentDesiredStateDAO;
-  private static HostComponentStateDAO hostComponentStateDAO;
-
-  private static ServiceFactory m_serviceFactory;
-  private static ServiceComponentFactory m_componentFactory;
-  private static ServiceComponentHostFactory m_schFactory;
-  private static AlertDaoHelper m_alertHelper;
-
-  @BeforeClass
-  public static void classSetUp() throws Exception {
+  private Clusters m_clusters;
+  private Cluster m_cluster;
+  private Injector m_injector;
+  private AlertDispatchDAO m_dao;
+  private AlertDefinitionDAO m_definitionDao;
+  private AlertsDAO m_alertsDao;
+  private OrmTestHelper m_helper;
+  private HostComponentDesiredStateDAO hostComponentDesiredStateDAO;
+  private HostComponentStateDAO hostComponentStateDAO;
+
+  private ServiceFactory m_serviceFactory;
+  private ServiceComponentFactory m_componentFactory;
+  private ServiceComponentHostFactory m_schFactory;
+  private AlertDaoHelper m_alertHelper;
+
+  /**
+   *
+   */
+  @Before
+  public void setup() throws Exception {
     m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
     m_injector.getInstance(GuiceJpaInitializer.class);
+    m_injector.getInstance(UnitOfWork.class).begin();
+
 
     m_dao = m_injector.getInstance(AlertDispatchDAO.class);
     m_alertsDao = m_injector.getInstance(AlertsDAO.class);
@@ -112,8 +112,7 @@ public class AlertDispatchDAOTest {
     m_schFactory = m_injector.getInstance(ServiceComponentHostFactory.class);
     m_clusters = m_injector.getInstance(Clusters.class);
     m_alertHelper = m_injector.getInstance(AlertDaoHelper.class);
-    hostComponentDesiredStateDAO = m_injector.getInstance(HostComponentDesiredStateDAO.class);
-    hostComponentStateDAO = m_injector.getInstance(HostComponentStateDAO.class);
+
 
     // !!! need a synchronous op for testing
     EventBusSynchronizer.synchronizeAmbariEventPublisher(m_injector);
@@ -123,77 +122,18 @@ public class AlertDispatchDAOTest {
   }
 
   /**
-   *
-   */
-  @Before
-  public void setup() throws Exception {
-    m_injector.getInstance(UnitOfWork.class).begin();
-  }
-
-  /**
    * @throws Exception
    */
   @After
   public void teardown() throws Exception {
     m_injector.getInstance(UnitOfWork.class).end();
-    cleanup();
-  }
-
-  @AfterClass
-  public static void afterClass() throws Exception {
     m_injector.getInstance(PersistService.class).stop();
   }
 
-  private void cleanup() throws AmbariException {
-    List<AlertGroupEntity> alertGroupEntities = m_dao.findAllGroups();
-    if (alertGroupEntities != null) {
-      for (AlertGroupEntity alertGroupEntity : alertGroupEntities) {
-        m_dao.remove(alertGroupEntity);
-      }
-    }
-
-    List<AlertTargetEntity> alertTargetEntities = m_dao.findAllTargets();
-    if (alertTargetEntities != null) {
-      for (AlertTargetEntity alertTargetEntity : alertTargetEntities) {
-        m_dao.remove(alertTargetEntity);
-      }
-    }
-
-    List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findAll();
-    if (hostComponentDesiredStateEntities != null) {
-      for (HostComponentDesiredStateEntity hcdse : hostComponentDesiredStateEntities) {
-        hostComponentDesiredStateDAO.remove(hcdse);
-      }
-    }
-
-    List<HostComponentStateEntity> hostComponentStateEntities = hostComponentStateDAO.findAll();
-    if (hostComponentStateEntities != null) {
-      for (HostComponentStateEntity hcse : hostComponentStateEntities) {
-        hostComponentStateDAO.remove(hcse);
-      }
-    }
-
-    List<AlertDefinitionEntity> alertDefinitionEntities = m_definitionDao.findAll();
-    if (alertDefinitionEntities != null) {
-      for (AlertDefinitionEntity alertDefinitionEntity : alertDefinitionEntities) {
-        m_definitionDao.remove(alertDefinitionEntity);
-      }
-    }
-
-    m_cluster.deleteAllServices();
-
-    List<Host> hosts = m_clusters.getHosts();
-    if (hosts != null) {
-      for (Host host : hosts) {
-        m_clusters.deleteHost(host.getHostName());
-      }
-    }
-  }
-
   private void initTestData() throws Exception {
     Set<AlertTargetEntity> targets = createTargets();
 
-    for (int i = 0; i < 10; i++) {
+    for (int i = 0; i < 2; i++) {
       AlertGroupEntity group = new AlertGroupEntity();
       group.setDefault(false);
       group.setGroupName("Group Name " + i);
@@ -210,28 +150,26 @@ public class AlertDispatchDAOTest {
    *
    */
   @Test
-  public void testFindAllTargets() throws Exception {
+  public void testFindTargets() throws Exception {
     initTestData();
+    // find all targets
     List<AlertTargetEntity> targets = m_dao.findAllTargets();
     assertNotNull(targets);
-    assertEquals(5, targets.size());
-  }
-
-  /**
-   * @throws Exception
-   */
-  public void testFindTargetsByIds() throws Exception {
-    List<AlertTargetEntity> targets = m_dao.findAllTargets();
-    assertNotNull(targets);
-    assertEquals(5, targets.size());
+    assertEquals(1, targets.size());
 
+    // find by ids
     List<Long> ids = new ArrayList<Long>();
     ids.add(targets.get(0).getTargetId());
-    ids.add(targets.get(1).getTargetId());
     ids.add(99999L);
 
     targets = m_dao.findTargetsById(ids);
-    assertEquals(2, targets.size());
+    assertEquals(1, targets.size());
+
+    //find by name
+    AlertTargetEntity target = targets.get(0);
+
+    AlertTargetEntity actual = m_dao.findTargetByName(target.getTargetName());
+    assertEquals(target, actual);
   }
 
   /**
@@ -259,53 +197,22 @@ public class AlertDispatchDAOTest {
    *
    */
   @Test
-  public void testFindTargetByName() throws Exception {
-    initTestData();
-    List<AlertTargetEntity> targets = m_dao.findAllTargets();
-    assertNotNull(targets);
-    AlertTargetEntity target = targets.get(3);
-
-    AlertTargetEntity actual = m_dao.findTargetByName(target.getTargetName());
-    assertEquals(target, actual);
-  }
-
-  /**
-   *
-   */
-  @Test
-  public void testFindAllGroups() throws Exception {
+  public void testFindGroups() throws Exception {
     initTestData();
+    // find all
     List<AlertGroupEntity> groups = m_dao.findAllGroups();
     assertNotNull(groups);
-    assertEquals(10, groups.size());
-  }
+    assertEquals(2, groups.size());
 
-  /**
-   *
-   */
-  @Test
-  public void testFindGroupByName() throws Exception {
-    initTestData();
-    List<AlertGroupEntity> groups = m_dao.findAllGroups();
-    assertNotNull(groups);
-    AlertGroupEntity group = groups.get(3);
+    //find by name
+    AlertGroupEntity group = groups.get(1);
 
     AlertGroupEntity actual = m_dao.findGroupByName(group.getClusterId(),
-        group.getGroupName());
+            group.getGroupName());
 
     assertEquals(group, actual);
-  }
-
-  /**
-   * @throws Exception
-   */
-  @Test
-  public void testFindGroupsByIds() throws Exception {
-    initTestData();
-    List<AlertGroupEntity> groups = m_dao.findAllGroups();
-    assertNotNull(groups);
-    assertEquals(10, groups.size());
 
+    //find by id
     List<Long> ids = new ArrayList<Long>();
     ids.add(groups.get(0).getGroupId());
     ids.add(groups.get(1).getGroupId());
@@ -313,13 +220,28 @@ public class AlertDispatchDAOTest {
 
     groups = m_dao.findGroupsById(ids);
     assertEquals(2, groups.size());
+
+    // find default group
+    for (AlertGroupEntity alertGroupEntity : groups) {
+      assertFalse(alertGroupEntity.isDefault());
+    }
+
+    Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
+            m_componentFactory, m_schFactory, HOSTNAME);
+
+    AlertGroupEntity hdfsGroup = m_dao.findDefaultServiceGroup(
+            cluster.getClusterId(), "HDFS");
+
+    assertNotNull(hdfsGroup);
+    assertTrue(hdfsGroup.isDefault());
   }
 
   /**
    *
    */
   @Test
-  public void testCreateGroup() throws Exception {
+  public void testCreateUpdateRemoveGroup() throws Exception {
+    // create group
     AlertTargetEntity target = m_helper.createAlertTarget();
     Set<AlertTargetEntity> targets = new HashSet<AlertTargetEntity>();
     targets.add(target);
@@ -333,15 +255,47 @@ public class AlertDispatchDAOTest {
     assertEquals(group.isDefault(), actual.isDefault());
     assertEquals(group.getAlertTargets(), actual.getAlertTargets());
     assertEquals(group.getAlertDefinitions(), actual.getAlertDefinitions());
-  }
 
+    // update group
+    AlertGroupEntity group1 = m_helper.createAlertGroup(
+            m_cluster.getClusterId(), null);
+
+    String groupName = group1.getGroupName();
+
+    group1 = m_dao.findGroupById(group1.getGroupId());
+    group1.setGroupName(groupName + "FOO");
+    group1.setDefault(true);
+
+    m_dao.merge(group1);
+    group = m_dao.findGroupById(group1.getGroupId());
+
+    assertEquals(groupName + "FOO", group1.getGroupName());
+    assertEquals(true, group1.isDefault());
+    assertEquals(0, group1.getAlertDefinitions().size());
+    assertEquals(0, group1.getAlertTargets().size());
+
+    group1.addAlertTarget(target);
+    m_dao.merge(group);
+
+    group1 = m_dao.findGroupById(group1.getGroupId());
+    assertEquals(targets, group1.getAlertTargets());
+
+    // delete group
+    m_dao.remove(group);
+    group = m_dao.findGroupById(group.getGroupId());
+    assertNull(group);
 
+    target = m_dao.findTargetById(target.getTargetId());
+    assertNotNull(target);
+    assertEquals(1, m_dao.findAllTargets().size());
+  }
 
   /**
    *
    */
   @Test
-  public void testCreateTarget() throws Exception {
+  public void testCreateAndRemoveTarget() throws Exception {
+    // create target
     int targetCount = m_dao.findAllTargets().size();
 
     AlertTargetEntity target = m_helper.createAlertTarget();
@@ -367,6 +321,13 @@ public class AlertDispatchDAOTest {
     assertEquals(group, actualGroup);
 
     assertEquals(targetCount + 1, m_dao.findAllTargets().size());
+
+    // remove target
+    m_dao.remove(target);
+
+    target = m_dao.findTargetById(target.getTargetId());
+    assertNull(target);
+
   }
 
   /**
@@ -426,57 +387,6 @@ public class AlertDispatchDAOTest {
   }
 
   /**
-   *
-   */
-  @Test
-  public void testDeleteGroup() throws Exception {
-    int targetCount = m_dao.findAllTargets().size();
-
-    AlertGroupEntity group = m_helper.createAlertGroup(
-        m_cluster.getClusterId(), null);
-    AlertTargetEntity target = m_helper.createAlertTarget();
-    assertEquals(targetCount + 1, m_dao.findAllTargets().size());
-
-    group = m_dao.findGroupById(group.getGroupId());
-    assertNotNull(group);
-    assertNotNull(group.getAlertTargets());
-    assertEquals(0, group.getAlertTargets().size());
-
-    group.addAlertTarget(target);
-    m_dao.merge(group);
-
-    group = m_dao.findGroupById(group.getGroupId());
-    assertNotNull(group);
-    assertNotNull(group.getAlertTargets());
-    assertEquals(1, group.getAlertTargets().size());
-
-    m_dao.remove(group);
-    group = m_dao.findGroupById(group.getGroupId());
-    assertNull(group);
-
-    target = m_dao.findTargetById(target.getTargetId());
-    assertNotNull(target);
-    assertEquals(targetCount + 1, m_dao.findAllTargets().size());
-  }
-
-  /**
-   *
-   */
-  @Test
-  public void testDeleteTarget() throws Exception {
-    AlertTargetEntity target = m_helper.createAlertTarget();
-    target = m_dao.findTargetById(target.getTargetId());
-    assertTrue(target.getAlertStates().size() > 0);
-
-    assertNotNull(target);
-
-    m_dao.remove(target);
-
-    target = m_dao.findTargetById(target.getTargetId());
-    assertNull(target);
-  }
-
-  /**
   *
   */
   @Test
@@ -544,39 +454,6 @@ public class AlertDispatchDAOTest {
   }
 
   /**
-   *
-   */
-  @Test
-  public void testUpdateGroup() throws Exception {
-    AlertTargetEntity target = m_helper.createAlertTarget();
-    Set<AlertTargetEntity> targets = new HashSet<AlertTargetEntity>();
-    targets.add(target);
-
-    String groupName = "Group Name " + System.currentTimeMillis();
-
-    AlertGroupEntity group = m_helper.createAlertGroup(
-        m_cluster.getClusterId(), null);
-
-    group = m_dao.findGroupById(group.getGroupId());
-    group.setGroupName(groupName + "FOO");
-    group.setDefault(true);
-
-    m_dao.merge(group);
-    group = m_dao.findGroupById(group.getGroupId());
-
-    assertEquals(groupName + "FOO", group.getGroupName());
-    assertEquals(true, group.isDefault());
-    assertEquals(0, group.getAlertDefinitions().size());
-    assertEquals(0, group.getAlertTargets().size());
-
-    group.addAlertTarget(target);
-    m_dao.merge(group);
-
-    group = m_dao.findGroupById(group.getGroupId());
-    assertEquals(targets, group.getAlertTargets());
-  }
-
-  /**
    * Tests finding groups by a definition ID that they are associatd with.
    *
    * @throws Exception
@@ -686,10 +563,11 @@ public class AlertDispatchDAOTest {
    */
   @Test
   public void testAlertNoticePredicate() throws Exception {
-    Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
-        m_componentFactory, m_schFactory, HOSTNAME);
+    m_helper.addHost(m_clusters, m_cluster, HOSTNAME);
+    m_helper.installHdfsService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
+    m_helper.installYarnService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
 
-    m_alertHelper.populateData(cluster);
+    m_alertHelper.populateData(m_cluster);
 
     Predicate clusterPredicate = null;
     Predicate hdfsPredicate = null;
@@ -764,10 +642,11 @@ public class AlertDispatchDAOTest {
    */
   @Test
   public void testAlertNoticePagination() throws Exception {
-    Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
-        m_componentFactory, m_schFactory, HOSTNAME);
+    m_helper.addHost(m_clusters, m_cluster, HOSTNAME);
+    m_helper.installHdfsService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
+    m_helper.installYarnService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
 
-    m_alertHelper.populateData(cluster);
+    m_alertHelper.populateData(m_cluster);
 
     AlertNoticeRequest request = new AlertNoticeRequest();
     request.Pagination = null;
@@ -805,10 +684,11 @@ public class AlertDispatchDAOTest {
    */
   @Test
   public void testAlertNoticeSorting() throws Exception {
-    Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
-        m_componentFactory, m_schFactory, HOSTNAME);
+    m_helper.addHost(m_clusters, m_cluster, HOSTNAME);
+    m_helper.installHdfsService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
+    m_helper.installYarnService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
 
-    m_alertHelper.populateData(cluster);
+    m_alertHelper.populateData(m_cluster);
 
     List<SortRequestProperty> sortProperties = new ArrayList<SortRequestProperty>();
     SortRequest sortRequest = new SortRequestImpl(sortProperties);
@@ -864,57 +744,25 @@ public class AlertDispatchDAOTest {
   }
 
   /**
-   *
-   */
-  @Test
-  public void testFindDefaultGroup() throws Exception {
-    initTestData();
-    List<AlertGroupEntity> groups = m_dao.findAllGroups();
-    assertNotNull(groups);
-    assertEquals(10, groups.size());
-
-    for (AlertGroupEntity group : groups) {
-      assertFalse(group.isDefault());
-    }
-
-    Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
-        m_componentFactory, m_schFactory, HOSTNAME);
-
-    AlertGroupEntity hdfsGroup = m_dao.findDefaultServiceGroup(
-        cluster.getClusterId(), "HDFS");
-
-    assertNotNull(hdfsGroup);
-    assertTrue(hdfsGroup.isDefault());
-  }
-
-  /**
    * Tests that when creating a new {@link AlertDefinitionEntity}, if the group
    * for its service does not exist, then it will be created.
    */
   @Test
   public void testDefaultGroupAutomaticCreation() throws Exception {
-    initTestData();
-    List<AlertGroupEntity> groups = m_dao.findAllGroups();
-    assertNotNull(groups);
-    assertEquals(10, groups.size());
-
-    for (AlertGroupEntity group : groups) {
-      assertFalse(group.isDefault());
-    }
-
-    Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
-        m_componentFactory, m_schFactory, HOSTNAME);
+    m_helper.addHost(m_clusters, m_cluster, HOSTNAME);
+    m_helper.installHdfsService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
+    //m_helper.installYarnService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
 
     AlertGroupEntity hdfsGroup = m_dao.findDefaultServiceGroup(
-        cluster.getClusterId(), "HDFS");
+            m_cluster.getClusterId(), "HDFS");
 
     // remove the HDFS default group
     m_dao.remove(hdfsGroup);
-    hdfsGroup = m_dao.findDefaultServiceGroup(cluster.getClusterId(), "HDFS");
+    hdfsGroup = m_dao.findDefaultServiceGroup(m_cluster.getClusterId(), "HDFS");
     assertNull(hdfsGroup);
 
     AlertDefinitionEntity datanodeProcess = new AlertDefinitionEntity();
-    datanodeProcess.setClusterId(cluster.getClusterId());
+    datanodeProcess.setClusterId(m_cluster.getClusterId());
     datanodeProcess.setDefinitionName("datanode_process");
     datanodeProcess.setServiceName("HDFS");
     datanodeProcess.setComponentName("DATANODE");
@@ -926,7 +774,7 @@ public class AlertDispatchDAOTest {
     m_definitionDao.create(datanodeProcess);
 
     // the group should be created and should be default
-    hdfsGroup = m_dao.findDefaultServiceGroup(cluster.getClusterId(), "HDFS");
+    hdfsGroup = m_dao.findDefaultServiceGroup(m_cluster.getClusterId(), "HDFS");
     assertNotNull(hdfsGroup);
     assertTrue(hdfsGroup.isDefault());
   }
@@ -939,22 +787,15 @@ public class AlertDispatchDAOTest {
   @Test(expected = AmbariException.class)
   public void testDefaultGroupInvalidServiceNoCreation() throws Exception {
     initTestData();
-    List<AlertGroupEntity> groups = m_dao.findAllGroups();
-    assertNotNull(groups);
-    assertEquals(10, groups.size());
-
-    for (AlertGroupEntity group : groups) {
-      assertFalse(group.isDefault());
-    }
-
-    Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
-        m_componentFactory, m_schFactory, HOSTNAME);
+    m_helper.addHost(m_clusters, m_cluster, HOSTNAME);
+    m_helper.installHdfsService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
+    //m_helper.installYarnService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME);
 
-    assertEquals(12, m_dao.findAllGroups().size());
+    assertEquals(3, m_dao.findAllGroups().size());
 
     // create a definition with an invalid service
     AlertDefinitionEntity datanodeProcess = new AlertDefinitionEntity();
-    datanodeProcess.setClusterId(cluster.getClusterId());
+    datanodeProcess.setClusterId(m_cluster.getClusterId());
     datanodeProcess.setDefinitionName("datanode_process");
     datanodeProcess.setServiceName("INVALID");
     datanodeProcess.setComponentName("DATANODE");
@@ -968,8 +809,7 @@ public class AlertDispatchDAOTest {
       m_definitionDao.create(datanodeProcess);
     } finally {
       // assert no group was added
-      assertEquals(12, m_dao.findAllGroups().size());
-      teardown();
+      assertEquals(3, m_dao.findAllGroups().size());
     }
   }
 
@@ -985,7 +825,9 @@ public class AlertDispatchDAOTest {
     m_helper.installYarnService(m_cluster, m_serviceFactory,
         m_componentFactory, m_schFactory, HOSTNAME);
 
-    for (int i = 0; i < 8; i++) {
+    List<AlertDefinitionEntity> alertDefinitionEntities = new ArrayList<>();
+
+    for (int i = 0; i < 2; i++) {
       AlertDefinitionEntity definition = new AlertDefinitionEntity();
       definition.setDefinitionName("Alert Definition " + i);
       definition.setServiceName("YARN");
@@ -997,11 +839,10 @@ public class AlertDispatchDAOTest {
       definition.setSource("{\"type\" : \"SCRIPT\"}");
       definition.setSourceType(SourceType.SCRIPT);
       m_definitionDao.create(definition);
+      alertDefinitionEntities.add(definition);
     }
 
-    List<AlertDefinitionEntity> alertDefinitions = m_definitionDao.findAll();
-    assertEquals(8, alertDefinitions.size());
-    return alertDefinitions;
+    return alertDefinitionEntities;
   }
 
   /**
@@ -1010,7 +851,7 @@ public class AlertDispatchDAOTest {
    */
   private Set<AlertTargetEntity> createTargets() throws Exception {
     Set<AlertTargetEntity> targets = new HashSet<AlertTargetEntity>();
-    for (int i = 0; i < 5; i++) {
+    for (int i = 0; i < 1; i++) {
       AlertTargetEntity target = new AlertTargetEntity();
       target.setDescription("Target Description " + i);
       target.setNotificationType("EMAIL");

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
index a80cd03..f54ac5c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
@@ -43,9 +43,7 @@ import org.apache.ambari.server.orm.entities.ResourceEntity;
 import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
 import org.apache.ambari.server.orm.entities.UserEntity;
 import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -55,102 +53,77 @@ import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.crypto.password.PasswordEncoder;
 
 import com.google.inject.Guice;
+import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.persist.PersistService;
 
 public class TestUsers {
-  private static Injector injector;
-
-
-  protected static Users users;
-  protected static UserDAO userDAO;
-  protected static GroupDAO groupDAO;
-  protected static PermissionDAO permissionDAO;
-  protected static ResourceDAO resourceDAO;
-  protected static ResourceTypeDAO resourceTypeDAO;
-  protected static PrincipalTypeDAO principalTypeDAO;
-  protected static PrincipalDAO principalDAO;
-  protected static PasswordEncoder passwordEncoder;
-
-
-  @BeforeClass
-  public static void classSetUp() {
-    injector = Guice.createInjector(new InMemoryDefaultTestModule());
-    injector.getInstance(GuiceJpaInitializer.class);
-    users = injector.getInstance(Users.class);
-    userDAO = injector.getInstance(UserDAO.class);
-    groupDAO = injector.getInstance(GroupDAO.class);
-    permissionDAO = injector.getInstance(PermissionDAO.class);
-    resourceDAO = injector.getInstance(ResourceDAO.class);
-    resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class);
-    principalTypeDAO = injector.getInstance(PrincipalTypeDAO.class);
-    principalDAO = injector.getInstance(PrincipalDAO.class);
-    passwordEncoder = injector.getInstance(PasswordEncoder.class);
-  }
+  private Injector injector;
+
+  @Inject
+  protected Users users;
+  @Inject
+  protected UserDAO userDAO;
+  @Inject
+  protected GroupDAO groupDAO;
+  @Inject
+  protected PermissionDAO permissionDAO;
+  @Inject
+  protected ResourceDAO resourceDAO;
+  @Inject
+  protected ResourceTypeDAO resourceTypeDAO;
+  @Inject
+  protected PrincipalTypeDAO principalTypeDAO;
+  @Inject
+  protected PrincipalDAO principalDAO;
+  @Inject
+  protected PasswordEncoder passwordEncoder;
 
   @Before
   public void setup() throws AmbariException {
-    //injector.injectMembers(this);
+    InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
+    injector = Guice.createInjector(module);
+    injector.getInstance(GuiceJpaInitializer.class);
+    injector.injectMembers(this);
     Authentication auth = new UsernamePasswordAuthenticationToken("admin", null);
     SecurityContextHolder.getContext().setAuthentication(auth);
 
-    if (resourceTypeDAO.findByName(ResourceType.AMBARI.name()) == null) {
-      // create admin permission
-      ResourceTypeEntity resourceTypeEntity = new ResourceTypeEntity();
-      resourceTypeEntity.setId(ResourceType.AMBARI.getId());
-      resourceTypeEntity.setName(ResourceType.AMBARI.name());
-      resourceTypeDAO.create(resourceTypeEntity);
-
-      ResourceEntity resourceEntity = new ResourceEntity();
-      resourceEntity.setId(ResourceEntity.AMBARI_RESOURCE_ID);
-      resourceEntity.setResourceType(resourceTypeEntity);
-      resourceDAO.create(resourceEntity);
-
-      PrincipalTypeEntity principalTypeEntity = new PrincipalTypeEntity();
-      principalTypeEntity.setName("ROLE");
-      principalTypeEntity = principalTypeDAO.merge(principalTypeEntity);
-
-      PrincipalEntity principalEntity = new PrincipalEntity();
-      principalEntity.setPrincipalType(principalTypeEntity);
-      principalEntity = principalDAO.merge(principalEntity);
-
-      PermissionEntity adminPermissionEntity = new PermissionEntity();
-      adminPermissionEntity.setId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION);
-      adminPermissionEntity.setPermissionName(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION_NAME);
-      adminPermissionEntity.setPrincipal(principalEntity);
-      adminPermissionEntity.setResourceType(resourceTypeEntity);
-      permissionDAO.create(adminPermissionEntity);
-
-      users.createUser("admin", "admin", UserType.LOCAL, true, true);
-    }
-    cleanup();
-  }
+    // create admin permission
+    ResourceTypeEntity resourceTypeEntity = new ResourceTypeEntity();
+    resourceTypeEntity.setId(ResourceType.AMBARI.getId());
+    resourceTypeEntity.setName(ResourceType.AMBARI.name());
+    resourceTypeDAO.create(resourceTypeEntity);
 
-  @After
-  public void tearDown() throws AmbariException {
+    ResourceEntity resourceEntity = new ResourceEntity();
+    resourceEntity.setId(ResourceEntity.AMBARI_RESOURCE_ID);
+    resourceEntity.setResourceType(resourceTypeEntity);
+    resourceDAO.create(resourceEntity);
+
+    PrincipalTypeEntity principalTypeEntity = new PrincipalTypeEntity();
+    principalTypeEntity.setName("ROLE");
+    principalTypeEntity = principalTypeDAO.merge(principalTypeEntity);
+
+    PrincipalEntity principalEntity = new PrincipalEntity();
+    principalEntity.setPrincipalType(principalTypeEntity);
+    principalEntity = principalDAO.merge(principalEntity);
 
+    PermissionEntity adminPermissionEntity = new PermissionEntity();
+    adminPermissionEntity.setId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION);
+    adminPermissionEntity.setPermissionName(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION_NAME);
+    adminPermissionEntity.setPrincipal(principalEntity);
+    adminPermissionEntity.setResourceType(resourceTypeEntity);
+    permissionDAO.create(adminPermissionEntity);
   }
 
-  @AfterClass
-  public static void afterClass() throws Exception {
+  @After
+  public void tearDown() throws AmbariException {
     injector.getInstance(PersistService.class).stop();
   }
 
-  private void cleanup() throws AmbariException {
-    for (User user : users.getAllUsers()) {
-      if (!user.getUserName().equals("admin")) {
-        users.removeUser(user);
-      }
-    }
-
-    for (Group group : users.getAllGroups()) {
-      users.removeGroup(group);
-    }
-  }
 
   @Test
   public void testIsUserCanBeRemoved() throws Exception {
-    //users.createUser("admin", "admin", UserType.LOCAL, true, true);
+    users.createUser("admin", "admin", UserType.LOCAL, true, true);
     users.createUser("admin222", "admin222", UserType.LOCAL, true, true);
 
     Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin")));
@@ -168,19 +141,8 @@ public class TestUsers {
   }
 
   @Test
-  public void testGetUserIfUnique() throws Exception {
-    users.createUser("user333", "user333", UserType.LOCAL, true, false);
-
-    Assert.assertNotNull(users.getUserIfUnique("user333"));
-
-    users.createUser("user333", "user333", UserType.LDAP, true, false);
-
-    Assert.assertNull(users.getUserIfUnique("user333"));
-  }
-
-  @Test
   public void testModifyPassword_UserByAdmin() throws Exception {
-    users.createUser("new_admin", "new_admin", UserType.LOCAL, true, true);
+    users.createUser("admin", "admin", UserType.LOCAL, true, true);
     users.createUser("user", "user");
 
     UserEntity userEntity = userDAO.findUserByName("user");
@@ -213,80 +175,81 @@ public class TestUsers {
   }
 
   @Test
-  public void testGetGroupMembers() throws Exception {
-    final String groupNameTwoMembers = "engineering";
-    final String groupNameZeroMembers = "management";
-    users.createGroup(groupNameTwoMembers);
-    users.createGroup(groupNameZeroMembers);
+  public void testCreateGetRemoveUser() throws Exception {
     users.createUser("user1", "user1");
-    users.createUser("user2", "user2");
-    users.addMemberToGroup(groupNameTwoMembers, "user1");
-    users.addMemberToGroup(groupNameTwoMembers, "user2");
-
-    assertEquals(users.getGroupMembers(groupNameTwoMembers).size(), 2);
-    assertEquals(users.getGroupMembers(groupNameZeroMembers).size(), 0);
-  }
+    users.createUser("user", "user", UserType.LOCAL, false, false);
+    users.createUser("user_ldap", "user_ldap", UserType.LDAP, true, true);
+    User createdUser = users.getUser("user", UserType.LOCAL);
+    User createdUser1 = users.getAnyUser("user1");
+    User createdLdapUser = users.getUser("user_ldap", UserType.LDAP);
 
-  @Test
-  public void testGetAllUsers() throws Exception {
-    Authentication auth = new UsernamePasswordAuthenticationToken("user", null);
-    SecurityContextHolder.getContext().setAuthentication(auth);
+    Assert.assertEquals("user1", createdUser1.getUserName());
+    Assert.assertEquals(true, createdUser1.isActive());
+    Assert.assertEquals(false, createdUser1.isLdapUser());
+    Assert.assertEquals(false, createdUser1.isAdmin());
 
-    users.createUser("user", "user");
+    Assert.assertEquals("user", createdUser.getUserName());
+    Assert.assertEquals(false, createdUser.isActive());
+    Assert.assertEquals(false, createdUser.isLdapUser());
+    Assert.assertEquals(false, createdUser.isAdmin());
 
-    List<User> userList = users.getAllUsers();
+    Assert.assertEquals("user_ldap", createdLdapUser.getUserName());
+    Assert.assertEquals(true, createdLdapUser.isActive());
+    Assert.assertEquals(true, createdLdapUser.isLdapUser());
+    Assert.assertEquals(true, createdLdapUser.isAdmin());
 
-    assertEquals(2, userList.size());
+    assertEquals("user", users.getAnyUser("user").getUserName());
+    assertEquals("user_ldap", users.getAnyUser("user_ldap").getUserName());
+    Assert.assertNull(users.getAnyUser("non_existing"));
 
-    for (User user : userList) {
-      assertEquals(false, user.isLdapUser());
+    // create duplicate user
+    try {
+      users.createUser("user1", "user1");
+      Assert.fail("It shouldn't be possible to create duplicate user");
+    } catch (AmbariException e) {
     }
 
-    assertEquals(2, userDAO.findAll().size());
-
-    UserEntity userEntity = userDAO.findUserByName("user");
-    assertNotNull("user", userEntity.getUserPassword());
-
-    users.modifyPassword("user", "user", "resu");
-
-    assertNotSame(userEntity.getUserPassword(), userDAO.findUserByName("user").getUserPassword());
-  }
-
-  @Test
-  public void testGetAnyUser() throws Exception {
-    users.createUser("user", "user", UserType.LOCAL, true, false);
-    users.createUser("user_ldap", "user_ldap", UserType.LDAP, true, false);
+    try {
+      users.createUser("USER1", "user1");
+      Assert.fail("It shouldn't be possible to create duplicate user");
+    } catch (AmbariException e) {
+    }
 
-    assertEquals("user", users.getAnyUser("user").getUserName());
-    assertEquals("user_ldap", users.getAnyUser("user_ldap").getUserName());
-    Assert.assertNull(users.getAnyUser("non_existing"));
-  }
+    // test get all users
+    List<User> userList = users.getAllUsers();
 
-  @Test
-  public void testGetAnyUserCaseInsensitive() throws Exception {
-    users.createUser("user", "user", UserType.LOCAL, true, false);
-    users.createUser("user_ldap", "user_ldap", UserType.LDAP, true, false);
+    Assert.assertEquals(3, userList.size());
 
+    // check get any user case insensitive
     assertEquals("user", users.getAnyUser("USER").getUserName());
     assertEquals("user_ldap", users.getAnyUser("USER_LDAP").getUserName());
     Assert.assertNull(users.getAnyUser("non_existing"));
-  }
 
-  @Test
-  public void testGetUserById() throws Exception {
-    users.createUser("user", "user", UserType.LOCAL, true, false);
-    User createdUser = users.getUser("user", UserType.LOCAL);
+    // get user by id
     User userById = users.getUser(createdUser.getUserId());
 
     assertNotNull(userById);
     assertEquals(createdUser.getUserId(), userById.getUserId());
-  }
 
-  @Test
-  public void testGetUserByInvalidId() throws Exception {
-    User userById = users.getUser(-1);
+    // get user by invalid id
+    User userByInvalidId = users.getUser(-1);
+
+    assertNull(userByInvalidId);
+
+    // get user if unique
+    Assert.assertNotNull(users.getUserIfUnique("user"));
+
+    users.createUser("user", "user", UserType.LDAP, true, false);
+
+    Assert.assertNull(users.getUserIfUnique("user"));
+
+    //remove user
+    Assert.assertEquals(4, users.getAllUsers().size());
+
+    users.removeUser(users.getAnyUser("user1"));
 
-    assertNull(userById);
+    Assert.assertNull(users.getAnyUser("user1"));
+    Assert.assertEquals(3, users.getAllUsers().size());
   }
 
   @Test
@@ -336,16 +299,11 @@ public class TestUsers {
   }
 
   @Test
-  public void testCreateGroup() throws Exception {
-    final String groupName = "engineering";
-    users.createGroup(groupName);
-    assertNotNull(groupDAO.findGroupByName(groupName));
-  }
-
-  @Test
-  public void testGetGroup() throws Exception {
-    final String groupName = "engineering";
+  public void testCreateGetRemoveGroup() throws Exception {
+    final String groupName = "engineering1";
+    final String groupName2 = "engineering2";
     users.createGroup(groupName);
+    users.createGroup(groupName2);
 
     final Group group = users.getGroup(groupName);
     assertNotNull(group);
@@ -353,71 +311,46 @@ public class TestUsers {
     assertEquals(groupName, group.getGroupName());
 
     assertNotNull(groupDAO.findGroupByName(groupName));
-  }
-
-  @Test
-  public void testGetAllGroups() throws Exception {
-    users.createGroup("one");
-    users.createGroup("two");
 
+    // get all groups
     final List<Group> groupList = users.getAllGroups();
 
     assertEquals(2, groupList.size());
     assertEquals(2, groupDAO.findAll().size());
-  }
 
-  @Test
-  public void testRemoveGroup() throws Exception {
-    final String groupName = "engineering";
-    users.createGroup(groupName);
-    final Group group = users.getGroup(groupName);
-    assertEquals(1, users.getAllGroups().size());
+    // remove group
     users.removeGroup(group);
-    assertEquals(0, users.getAllGroups().size());
-  }
-
-  @Test
-  public void testAddMemberToGroup() throws Exception {
-    final String groupName = "engineering";
-    users.createGroup(groupName);
-    users.createUser("user", "user");
-    users.addMemberToGroup(groupName, "user");
-    assertEquals(1, groupDAO.findGroupByName(groupName).getMemberEntities().size());
+    assertNull(users.getGroup(group.getGroupName()));
+    assertEquals(1, users.getAllGroups().size());
   }
 
   @Test
-  public void testGetAllMembers() throws Exception {
+  public void testMembers() throws Exception {
     final String groupName = "engineering";
+    final String groupName2 = "engineering2";
     users.createGroup(groupName);
+    users.createGroup(groupName2);
     users.createUser("user1", "user1");
     users.createUser("user2", "user2");
     users.createUser("user3", "user3");
     users.addMemberToGroup(groupName, "user1");
     users.addMemberToGroup(groupName, "user2");
     assertEquals(2, users.getAllMembers(groupName).size());
+    assertEquals(0, users.getAllMembers(groupName2).size());
 
     try {
       users.getAllMembers("non existing");
       Assert.fail("It shouldn't be possible to call getAllMembers() on non-existing group");
     } catch (Exception ex) {
     }
-  }
-
-  @Test
-  public void testRemoveMemberFromGroup() throws Exception {
-    final String groupName = "engineering";
-    users.createGroup(groupName);
-    users.createUser("user", "user");
-    users.addMemberToGroup(groupName, "user");
-    assertEquals(1, groupDAO.findGroupByName(groupName).getMemberEntities().size());
-    users.removeMemberFromGroup(groupName, "user");
-    assertEquals(0, groupDAO.findGroupByName(groupName).getMemberEntities().size());
-  }
 
+    // get members from not unexisting group
+    assertEquals(users.getGroupMembers("unexisting"), null);
 
-  @Test
-  public void testGetGroupMembersUnexistingGroup() throws Exception {
-   assertEquals(users.getGroupMembers("unexisting"), null);
+    // remove member from group
+    users.removeMemberFromGroup(groupName, "user1");
+    assertEquals(1, groupDAO.findGroupByName(groupName).getMemberEntities().size());
+    assertEquals("user2", groupDAO.findGroupByName(groupName).getMemberEntities().iterator().next().getUser().getUserName());
   }
 
   @Test
@@ -477,17 +410,6 @@ public class TestUsers {
   }
 
   @Test
-  public void testCreateUserTwoParams() throws Exception {
-    users.createUser("user", "user");
-
-    final User createdUser = users.getAnyUser("user");
-    Assert.assertEquals("user", createdUser.getUserName());
-    Assert.assertEquals(true, createdUser.isActive());
-    Assert.assertEquals(false, createdUser.isLdapUser());
-    Assert.assertEquals(false, createdUser.isAdmin());
-  }
-
-  @Test
   @Ignore // TODO @Transactional annotation breaks this test
   public void testCreateUserDefaultParams() throws Exception {
     final Users spy = Mockito.spy(users);
@@ -496,47 +418,4 @@ public class TestUsers {
   }
 
 
-  @Test(expected = AmbariException.class)
-  public void testCreateUserDuplicate() throws Exception {
-    users.createUser("user", "user");
-    users.createUser("user", "user");
-  }
-
-  @Test(expected = AmbariException.class)
-  public void testCreateUserDuplicateCaseInsensitive() throws Exception {
-    users.createUser("user", "user");
-    users.createUser("USER", "user");
-  }
-
-  @Test
-  public void testRemoveUser() throws Exception {
-    users.createUser("user1", "user1");
-    users.createUser("user2", "user2");
-    users.createUser("user3", "user3");
-    Assert.assertEquals(4, users.getAllUsers().size());
-
-    users.removeUser(users.getAnyUser("user1"));
-
-    Assert.assertNull(users.getAnyUser("user1"));
-    Assert.assertEquals(3, users.getAllUsers().size());
-  }
-
-  @Test
-  public void testCreateUserFiveParams() throws Exception {
-    users.createUser("user", "user", UserType.LOCAL, false, false);
-
-    final User createdUser = users.getAnyUser("user");
-    Assert.assertEquals("user", createdUser.getUserName());
-    Assert.assertEquals(false, createdUser.isActive());
-    Assert.assertEquals(false, createdUser.isLdapUser());
-    Assert.assertEquals(false, createdUser.isAdmin());
-
-    users.createUser("user2", "user2", UserType.LDAP, true, true);
-    final User createdUser2 = users.getAnyUser("user2");
-    Assert.assertEquals("user2", createdUser2.getUserName());
-    Assert.assertEquals(true, createdUser2.isActive());
-    Assert.assertEquals(true, createdUser2.isLdapUser());
-    Assert.assertEquals(true, createdUser2.isAdmin());
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
index bf72e0c..5462f7b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
@@ -43,9 +43,7 @@ import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.HostVersionDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
-import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.serveraction.ServerAction;
 import org.apache.ambari.server.state.Cluster;
@@ -66,13 +64,12 @@ import org.apache.ambari.server.state.stack.upgrade.PropertyKeyState;
 import org.apache.ambari.server.state.stack.upgrade.TransferCoercionType;
 import org.apache.ambari.server.state.stack.upgrade.TransferOperation;
 import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.gson.Gson;
 import com.google.inject.Guice;
+import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.persist.PersistService;
 
@@ -86,84 +83,45 @@ public class ConfigureActionTest {
   private static final StackId HDP_211_STACK = new StackId("HDP-2.1.1");
   private static final StackId HDP_220_STACK = new StackId("HDP-2.2.0");
 
-  private static Injector m_injector;
-  private static OrmTestHelper m_helper;
-  private static RepositoryVersionDAO repoVersionDAO;
-  private static HostVersionDAO hostVersionDAO;
-  private static HostRoleCommandFactory hostRoleCommandFactory;
-  private static ServiceFactory serviceFactory;
-  private static ConfigHelper m_configHelper;
-  private static Clusters clusters;
-  private static ClusterVersionDAO clusterVersionDAO;
-  private static ConfigFactory cf;
-  private static ConfigureAction action;
-  private static HostDAO hostDAO;
-
-  @BeforeClass
-  public static void classSetUp() throws Exception {
-    m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
-    m_injector.getInstance(GuiceJpaInitializer.class);
-
-    m_helper = m_injector.getInstance(OrmTestHelper.class);
-    repoVersionDAO = m_injector.getInstance(RepositoryVersionDAO.class);
-    hostVersionDAO = m_injector.getInstance(HostVersionDAO.class);
-    hostRoleCommandFactory = m_injector.getInstance(HostRoleCommandFactory.class);
-    serviceFactory = m_injector.getInstance(ServiceFactory.class);
-    m_configHelper = m_injector.getInstance(ConfigHelper.class);
-    clusters = m_injector.getInstance(Clusters.class);
-    clusterVersionDAO = m_injector.getInstance(ClusterVersionDAO.class);
-    cf = m_injector.getInstance(ConfigFactory.class);
-    action = m_injector.getInstance(ConfigureAction.class);
-    hostDAO = m_injector.getInstance(HostDAO.class);
-  }
+  @Inject
+  private Injector m_injector;
+  @Inject
+  private OrmTestHelper m_helper;
+  @Inject
+  private RepositoryVersionDAO repoVersionDAO;
+  @Inject
+  private HostVersionDAO hostVersionDAO;
+  @Inject
+  private HostRoleCommandFactory hostRoleCommandFactory;
+  @Inject
+  private ServiceFactory serviceFactory;
+  @Inject
+  private ConfigHelper m_configHelper;
+  @Inject
+  private Clusters clusters;
+  @Inject
+  private ClusterVersionDAO clusterVersionDAO;
+  @Inject
+  private ConfigFactory cf;
+  @Inject
+  private ConfigureAction action;
+  @Inject
+  private HostDAO hostDAO;
+  @Inject
+  private StackDAO stackDAO;
 
   @Before
   public void setup() throws Exception {
-
+    m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    m_injector.getInstance(GuiceJpaInitializer.class);
+    m_injector.injectMembers(this);
   }
 
   @After
   public void teardown() throws Exception {
-    cleanup();
-  }
-
-  @AfterClass
-  public static void afterClass() throws Exception {
     m_injector.getInstance(PersistService.class).stop();
   }
 
-  private void cleanup() throws AmbariException {
-    Map<String, Cluster> clusterMap = clusters.getClusters();
-
-    List<ClusterVersionEntity> clusterVersionEntities = clusterVersionDAO.findAll();
-    if (clusterVersionEntities != null) {
-      for (ClusterVersionEntity cve : clusterVersionEntities) {
-        clusterVersionDAO.remove(cve);
-      }
-    }
-
-    List<RepositoryVersionEntity> repositoryVersionEntities = repoVersionDAO.findAll();
-    if (repositoryVersionEntities != null) {
-      for (RepositoryVersionEntity rve : repositoryVersionEntities) {
-        repoVersionDAO.remove(rve);
-      }
-    }
-
-    List<HostVersionEntity> hostVersionEntities = hostVersionDAO.findAll();
-    if (clusterVersionEntities != null) {
-      for (HostVersionEntity hve : hostVersionEntities) {
-        hostVersionDAO.remove(hve);
-      }
-    }
-
-    for (String clusterName : clusterMap.keySet()) {
-      clusters.deleteCluster(clusterName);
-    }
-
-    for (Host host : clusters.getHosts()) {
-      clusters.deleteHost(host.getHostName());
-    }
-  }
 
   @Test
   public void testConfigActionUpgradeAcrossStack() throws Exception {
@@ -1703,7 +1661,7 @@ public class ConfigureActionTest {
 
     clusters.addCluster(clusterName, HDP_220_STACK);
 
-    StackDAO stackDAO = m_injector.getInstance(StackDAO.class);
+
     StackEntity stackEntity = stackDAO.find(HDP_220_STACK.getStackName(),
         HDP_220_STACK.getStackVersion());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
index f1013c2..50ce7b4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
@@ -57,8 +57,6 @@ import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.dao.UpgradeDAO;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
-import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
-import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.RequestEntity;
@@ -85,10 +83,8 @@ import org.apache.ambari.server.state.stack.UpgradePack;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.gson.Gson;
@@ -96,6 +92,7 @@ import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.inject.Guice;
+import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.persist.PersistService;
 import com.google.inject.persist.UnitOfWork;
@@ -117,122 +114,67 @@ public class UpgradeActionTest {
 
   private static final String HDP_211_CENTOS6_REPO_URL = "http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos6/2.x/BUILDS/2.1.1.0-118";
 
-  private static Injector m_injector;
-  private static AmbariManagementController amc;
-  private static OrmTestHelper m_helper;
-  private static RepositoryVersionDAO repoVersionDAO;
-  private static Clusters clusters;
-  private static ClusterVersionDAO clusterVersionDAO;
-  private static HostVersionDAO hostVersionDAO;
-  private static HostDAO hostDAO;
-  private static HostRoleCommandFactory hostRoleCommandFactory;
-  private static ServiceFactory serviceFactory;
-  private static ServiceComponentFactory serviceComponentFactory;
-  private static ServiceComponentHostFactory serviceComponentHostFactory;
-  private static RequestDAO requestDAO;
-  private static UpgradeDAO upgradeDAO;
-  private static ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO;
-  private static HostComponentDesiredStateDAO hostComponentDesiredStateDAO;
-  private static HostComponentStateDAO hostComponentStateDAO;
-  private static StackDAO stackDAO;
-  private static AmbariMetaInfo ambariMetaInfo;
-  private static FinalizeUpgradeAction finalizeUpgradeAction;
-
-  @BeforeClass
-  public static void classSetUp() throws NoSuchFieldException, IllegalAccessException {
+  private Injector m_injector;
+
+  private AmbariManagementController amc;
+  @Inject
+  private OrmTestHelper m_helper;
+  @Inject
+  private RepositoryVersionDAO repoVersionDAO;
+  @Inject
+  private Clusters clusters;
+  @Inject
+  private ClusterVersionDAO clusterVersionDAO;
+  @Inject
+  private HostVersionDAO hostVersionDAO;
+  @Inject
+  private HostDAO hostDAO;
+  @Inject
+  private HostRoleCommandFactory hostRoleCommandFactory;
+  @Inject
+  private ServiceFactory serviceFactory;
+  @Inject
+  private ServiceComponentFactory serviceComponentFactory;
+  @Inject
+  private ServiceComponentHostFactory serviceComponentHostFactory;
+  @Inject
+  private RequestDAO requestDAO;
+  @Inject
+  private UpgradeDAO upgradeDAO;
+  @Inject
+  private ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO;
+  @Inject
+  private HostComponentDesiredStateDAO hostComponentDesiredStateDAO;
+  @Inject
+  private HostComponentStateDAO hostComponentStateDAO;
+  @Inject
+  private StackDAO stackDAO;
+  @Inject
+  private AmbariMetaInfo ambariMetaInfo;
+  @Inject
+  private FinalizeUpgradeAction finalizeUpgradeAction;
+
+  @Before
+  public void setup() throws Exception {
     m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
     m_injector.getInstance(GuiceJpaInitializer.class);
+    m_injector.injectMembers(this);
+    m_injector.getInstance(UnitOfWork.class).begin();
 
-    m_helper = m_injector.getInstance(OrmTestHelper.class);
-    repoVersionDAO = m_injector.getInstance(RepositoryVersionDAO.class);
-    clusters = m_injector.getInstance(Clusters.class);
-    clusterVersionDAO = m_injector.getInstance(ClusterVersionDAO.class);
-    hostVersionDAO = m_injector.getInstance(HostVersionDAO.class);
-    hostDAO = m_injector.getInstance(HostDAO.class);
-    hostRoleCommandFactory = m_injector.getInstance(HostRoleCommandFactory.class);
-    serviceFactory = m_injector.getInstance(ServiceFactory.class);
-    serviceComponentFactory = m_injector.getInstance(ServiceComponentFactory.class);
-    serviceComponentHostFactory = m_injector.getInstance(ServiceComponentHostFactory.class);
-    requestDAO = m_injector.getInstance(RequestDAO.class);
-    upgradeDAO = m_injector.getInstance(UpgradeDAO.class);
-    serviceComponentDesiredStateDAO = m_injector.getInstance(ServiceComponentDesiredStateDAO.class);
-    hostComponentDesiredStateDAO = m_injector.getInstance(HostComponentDesiredStateDAO.class);
-    hostComponentStateDAO = m_injector.getInstance(HostComponentStateDAO.class);
+    // Initialize AmbariManagementController
     amc = m_injector.getInstance(AmbariManagementController.class);
-    stackDAO = m_injector.getInstance(StackDAO.class);
-    ambariMetaInfo = m_injector.getInstance(AmbariMetaInfo.class);
-    finalizeUpgradeAction = m_injector.getInstance(FinalizeUpgradeAction.class);
 
     Field field = AmbariServer.class.getDeclaredField("clusterController");
     field.setAccessible(true);
     field.set(null, amc);
   }
 
-  @Before
-  public void setup() throws Exception {
-    cleanup();
-    m_injector.getInstance(UnitOfWork.class).begin();
-  }
-
   @After
   public void teardown() throws Exception {
     m_injector.getInstance(UnitOfWork.class).end();
-    cleanup();
-  }
-
-  @AfterClass
-  public static void afterClass() throws Exception {
     m_injector.getInstance(PersistService.class).stop();
   }
 
-  private void cleanup() throws AmbariException {
-    Map<String, Cluster> clusterMap = clusters.getClusters();
-
-    List<ClusterVersionEntity> clusterVersionEntities = clusterVersionDAO.findAll();
-    if (clusterVersionEntities != null) {
-      for (ClusterVersionEntity cve : clusterVersionEntities) {
-        clusterVersionDAO.remove(cve);
-      }
-    }
-
-    List<RepositoryVersionEntity> repositoryVersionEntities = repoVersionDAO.findAll();
-    if (repositoryVersionEntities != null) {
-      for (RepositoryVersionEntity rve : repositoryVersionEntities) {
-        repoVersionDAO.remove(rve);
-      }
-    }
-
-    List<HostVersionEntity> hostVersionEntities = hostVersionDAO.findAll();
-    if (clusterVersionEntities != null) {
-      for (HostVersionEntity hve : hostVersionEntities) {
-        hostVersionDAO.remove(hve);
-      }
-    }
-
-    List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findAll();
-    if (hostComponentDesiredStateEntities != null) {
-      for (HostComponentDesiredStateEntity hcdse : hostComponentDesiredStateEntities) {
-        hostComponentDesiredStateDAO.remove(hcdse);
-      }
-    }
-
-    List<HostComponentStateEntity> hostComponentStateEntities = hostComponentStateDAO.findAll();
-    if (hostComponentStateEntities != null) {
-      for (HostComponentStateEntity hcse : hostComponentStateEntities) {
-        hostComponentStateDAO.remove(hcse);
-      }
-    }
-
-    for (String clusterName : clusterMap.keySet()) {
-      clusters.deleteCluster(clusterName);
-    }
-
-    for (Host host : clusters.getHosts()) {
-      clusters.deleteHost(host.getHostName());
-    }
-
-  }
-
   private void makeDowngradeCluster(StackId sourceStack, String sourceRepo, StackId targetStack, String targetRepo) throws Exception {
     String hostName = "h1";
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
index 897e955..8f00b72 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
@@ -20,8 +20,6 @@ package org.apache.ambari.server.state;
 
 import junit.framework.Assert;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.HashMap;
@@ -35,9 +33,7 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
 import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.inject.Guice;
@@ -46,17 +42,17 @@ import com.google.inject.persist.PersistService;
 
 public class ServiceTest {
 
-  private static Clusters clusters;
-  private static Cluster cluster;
-  private static String clusterName;
-  private static Injector injector;
-  private static ServiceFactory serviceFactory;
-  private static ServiceComponentFactory serviceComponentFactory;
-  private static ServiceComponentHostFactory serviceComponentHostFactory;
-  private static AmbariMetaInfo metaInfo;
-
-  @BeforeClass
-  public static void classSetUp() throws Exception {
+  private Clusters clusters;
+  private Cluster cluster;
+  private String clusterName;
+  private Injector injector;
+  private ServiceFactory serviceFactory;
+  private ServiceComponentFactory serviceComponentFactory;
+  private ServiceComponentHostFactory serviceComponentHostFactory;
+  private AmbariMetaInfo metaInfo;
+
+  @Before
+  public void setup() throws Exception {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
     clusters = injector.getInstance(Clusters.class);
@@ -72,26 +68,11 @@ public class ServiceTest {
     Assert.assertNotNull(cluster);
   }
 
-  @Before
-  public void setup() throws Exception {
-
-  }
-
   @After
   public void teardown() throws AmbariException {
-    //injector.getInstance(PersistService.class).stop();
-    cleanup();
-  }
-
-  @AfterClass
-  public static void afterClass() throws Exception {
     injector.getInstance(PersistService.class).stop();
   }
 
-  private void cleanup() throws AmbariException {
-    cluster.deleteAllServices();
-  }
-
   @Test
   public void testCanBeRemoved() throws Exception{
     Service service = cluster.addService("HDFS");
@@ -134,26 +115,6 @@ public class ServiceTest {
   }
 
   @Test
-  public void testCreateService() throws AmbariException {
-    String serviceName = "HDFS";
-    Service s = serviceFactory.createNew(cluster, serviceName);
-    cluster.addService(s);
-    s.persist();
-    Service service = cluster.getService(serviceName);
-
-    Assert.assertNotNull(service);
-    Assert.assertEquals(serviceName, service.getName());
-    Assert.assertEquals(cluster.getClusterId(),
-        service.getCluster().getClusterId());
-    Assert.assertEquals(cluster.getClusterName(),
-        service.getCluster().getClusterName());
-    Assert.assertEquals(State.INIT, service.getDesiredState());
-    Assert.assertEquals(SecurityState.UNSECURED, service.getSecurityState());
-    Assert.assertFalse(
-        service.getDesiredStackVersion().getStackId().isEmpty());
-  }
-
-  @Test
   public void testGetAndSetServiceInfo() throws AmbariException {
     String serviceName = "HDFS";
     Service s = serviceFactory.createNew(cluster, serviceName);
@@ -176,7 +137,7 @@ public class ServiceTest {
 
 
   @Test
-  public void testAddAndGetServiceComponents() throws AmbariException {
+  public void testAddGetDeleteServiceComponents() throws AmbariException {
     String serviceName = "HDFS";
     Service s = serviceFactory.createNew(cluster, serviceName);
     cluster.addService(s);
@@ -185,6 +146,15 @@ public class ServiceTest {
     Service service = cluster.getService(serviceName);
 
     Assert.assertNotNull(service);
+    Assert.assertEquals(serviceName, service.getName());
+    Assert.assertEquals(cluster.getClusterId(),
+            service.getCluster().getClusterId());
+    Assert.assertEquals(cluster.getClusterName(),
+            service.getCluster().getClusterName());
+    Assert.assertEquals(State.INIT, service.getDesiredState());
+    Assert.assertEquals(SecurityState.UNSECURED, service.getSecurityState());
+    Assert.assertFalse(
+            service.getDesiredStackVersion().getStackId().isEmpty());
 
     Assert.assertTrue(s.getServiceComponents().isEmpty());
 
@@ -240,6 +210,10 @@ public class ServiceTest {
     Assert.assertEquals(State.INSTALLING,
         s.getServiceComponent("HDFS_CLIENT").getDesiredState());
 
+    // delete service component
+    s.deleteServiceComponent("NAMENODE");
+
+    assertEquals(3, s.getServiceComponents().size());
   }
 
   @Test
@@ -289,36 +263,6 @@ public class ServiceTest {
   }
 
   @Test
-  public void testDeleteServiceComponent() throws Exception {
-    Service hdfs = cluster.addService("HDFS");
-    Service mapReduce = cluster.addService("MAPREDUCE");
-
-    hdfs.persist();
-
-    ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
-    nameNode.persist();
-    ServiceComponent jobTracker = mapReduce.addServiceComponent("JOBTRACKER");
-
-    assertEquals(2, cluster.getServices().size());
-    assertEquals(1, hdfs.getServiceComponents().size());
-    assertEquals(1, mapReduce.getServiceComponents().size());
-    assertTrue(hdfs.isPersisted());
-    assertFalse(mapReduce.isPersisted());
-
-    hdfs.deleteServiceComponent("NAMENODE");
-
-    assertEquals(0, hdfs.getServiceComponents().size());
-    assertEquals(1, mapReduce.getServiceComponents().size());
-
-    mapReduce.deleteServiceComponent("JOBTRACKER");
-
-    assertEquals(0, hdfs.getServiceComponents().size());
-    assertEquals(0, mapReduce.getServiceComponents().size());
-
-  }
-
-
-  @Test
   public void testServiceMaintenance() throws Exception {
     String serviceName = "HDFS";
     Service s = serviceFactory.createNew(cluster, serviceName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
index bf58967..243cb4f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
@@ -65,117 +65,74 @@ import org.apache.ambari.server.state.configgroup.ConfigGroup;
 import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.inject.Guice;
+import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.persist.PersistService;
 
 public class ServiceComponentHostTest {
   private static Logger LOG = LoggerFactory.getLogger(ServiceComponentHostTest.class);
-
-  private static Injector injector;
-  private static Clusters clusters;
-  private static ServiceFactory serviceFactory;
-  private static ServiceComponentFactory serviceComponentFactory;
-  private static ServiceComponentHostFactory serviceComponentHostFactory;
-  private static ConfigFactory configFactory;
-  private static ConfigGroupFactory configGroupFactory;
-  private static OrmTestHelper helper;
-  private static ClusterDAO clusterDAO;
-  private static HostDAO hostDAO;
-  private static HostComponentDesiredStateDAO hostComponentDesiredStateDAO;
-  private static HostComponentStateDAO hostComponentStateDAO;
+  @Inject
+  private Injector injector;
+  @Inject
+  private Clusters clusters;
+  @Inject
+  private ServiceFactory serviceFactory;
+  @Inject
+  private ServiceComponentFactory serviceComponentFactory;
+  @Inject
+  private ServiceComponentHostFactory serviceComponentHostFactory;
+  @Inject
+  private ConfigFactory configFactory;
+  @Inject
+  private ConfigGroupFactory configGroupFactory;
+  @Inject
+  private OrmTestHelper helper;
+  @Inject
+  private ClusterDAO clusterDAO;
+  @Inject
+  private HostDAO hostDAO;
+  @Inject
+  private HostComponentDesiredStateDAO hostComponentDesiredStateDAO;
+  @Inject
+  private HostComponentStateDAO hostComponentStateDAO;
 
   private String clusterName = "c1";
   private String hostName1 = "h1";
   private Map<String, String> hostAttributes = new HashMap<String, String>();
 
-  @BeforeClass
-  public static void classSetUp() {
-    injector = Guice.createInjector(new InMemoryDefaultTestModule());
-    injector.getInstance(GuiceJpaInitializer.class);
-    clusters = injector.getInstance(Clusters.class);
-    serviceFactory = injector.getInstance(ServiceFactory.class);
-    serviceComponentFactory = injector.getInstance(ServiceComponentFactory.class);
-    serviceComponentHostFactory = injector.getInstance(ServiceComponentHostFactory.class);
-    configFactory = injector.getInstance(ConfigFactory.class);
-    configGroupFactory = injector.getInstance(ConfigGroupFactory.class);
-    helper = injector.getInstance(OrmTestHelper.class);
-    clusterDAO = injector.getInstance(ClusterDAO.class);
-    hostDAO = injector.getInstance(HostDAO.class);
-    hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class);
-    hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class);
-  }
 
   @Before
   public void setup() throws Exception {
-    cleanup();
-
-    if (clusters.getClusters().size() == 0) {
-      StackId stackId = new StackId("HDP-0.1");
-      createCluster(stackId, clusterName);
-      hostAttributes.put("os_family", "redhat");
-      hostAttributes.put("os_release_version", "5.9");
-
-      Set<String> hostNames = new HashSet<String>();
-      hostNames.add(hostName1);
-      addHostsToCluster(clusterName, hostAttributes, hostNames);
-
-      Cluster c1 = clusters.getCluster(clusterName);
-      helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-      c1.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
-          RepositoryVersionState.INSTALLING);
-    }
-  }
-
-  @After
-  public void teardown() throws AmbariException {
-    cleanup();
-  }
-
-  @AfterClass
-  public static void afterClass() throws Exception {
-    injector.getInstance(PersistService.class).stop();
-  }
-
-  private void cleanup() throws AmbariException {
-    try {
-      Map<String, Cluster> clusterMap = clusters.getClusters();
-
-      List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findAll();
-      if (hostComponentDesiredStateEntities != null) {
-        for (HostComponentDesiredStateEntity hcdse : hostComponentDesiredStateEntities) {
-          hostComponentDesiredStateDAO.remove(hcdse);
-        }
-      }
+    injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    injector.getInstance(GuiceJpaInitializer.class);
+    injector.injectMembers(this);
 
-      List<HostComponentStateEntity> hostComponentStateEntities = hostComponentStateDAO.findAll();
-      if (hostComponentStateEntities != null) {
-        for (HostComponentStateEntity hcse : hostComponentStateEntities) {
-          hostComponentStateDAO.remove(hcse);
-        }
-      }
+    StackId stackId = new StackId("HDP-0.1");
+    createCluster(stackId, clusterName);
+    hostAttributes.put("os_family", "redhat");
+    hostAttributes.put("os_release_version", "5.9");
 
-      for (String clusterName : clusterMap.keySet()) {
-        clusters.deleteCluster(clusterName);
-      }
+    Set<String> hostNames = new HashSet<String>();
+    hostNames.add(hostName1);
+    addHostsToCluster(clusterName, hostAttributes, hostNames);
 
-      for (Host host : clusters.getHosts()) {
-        clusters.deleteHost(host.getHostName());
-      }
+    Cluster c1 = clusters.getCluster(clusterName);
+    helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
+    c1.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
+            RepositoryVersionState.INSTALLING);
+  }
 
-      for (String clusterName : clusterMap.keySet()) {
-        clusters.deleteCluster(clusterName);
-      }
-    } catch (IllegalStateException ise) {}
+  @After
+  public void teardown() {
+    injector.getInstance(PersistService.class).stop();
   }
 
   private ClusterEntity createCluster(StackId stackId, String clusterName) throws AmbariException {
@@ -263,12 +220,6 @@ public class ServiceComponentHostTest {
     return impl;
   }
 
-  @Test
-  public void testNewServiceComponentHost() throws AmbariException{
-    createNewServiceComponentHost(clusterName, "HDFS", "NAMENODE", hostName1, false);
-    createNewServiceComponentHost(clusterName, "HDFS", "HDFS_CLIENT", hostName1, true);
-  }
-
   private ServiceComponentHostEvent createEvent(ServiceComponentHostImpl impl,
       long timestamp, ServiceComponentHostEventType eventType)
       throws AmbariException {
@@ -521,6 +472,18 @@ public class ServiceComponentHostTest {
         State.WIPING_OUT,
         State.INIT);
 
+    // check can be removed
+    for (State state : State.values()) {
+      impl.setState(state);
+
+      if (state.isRemovableState()) {
+        Assert.assertTrue(impl.canBeRemoved());
+      }
+      else {
+        Assert.assertFalse(impl.canBeRemoved());
+      }
+    }
+
   }
 
   @Test
@@ -753,22 +716,6 @@ public class ServiceComponentHostTest {
     }
   }
 
-  @Test
-  public void testCanBeRemoved() throws Exception{
-    ServiceComponentHostImpl impl = (ServiceComponentHostImpl)
-        createNewServiceComponentHost(clusterName, "HDFS", "HDFS_CLIENT", hostName1, true);
-
-    for (State state : State.values()) {
-      impl.setState(state);
-
-      if (state.isRemovableState()) {
-        Assert.assertTrue(impl.canBeRemoved());
-      }
-      else {
-        Assert.assertFalse(impl.canBeRemoved());
-      }
-    }
-  }
 
   @Test
   public void testStaleConfigs() throws Exception {
@@ -1124,8 +1071,8 @@ public class ServiceComponentHostTest {
     Assert.assertNotNull(hostEntity);
 
     ServiceComponentHost sch1 = createNewServiceComponentHost(cluster, "HDFS", "NAMENODE", hostName);
-    ServiceComponentHost sch2 = createNewServiceComponentHost(cluster, "HDFS", "DATANODE", hostName);
-    ServiceComponentHost sch3 = createNewServiceComponentHost(cluster, "MAPREDUCE2", "HISTORYSERVER", hostName);
+    //ServiceComponentHost sch2 = createNewServiceComponentHost(cluster, "HDFS", "DATANODE", hostName);
+    //ServiceComponentHost sch3 = createNewServiceComponentHost(cluster, "MAPREDUCE2", "HISTORYSERVER", hostName);
 
     HostComponentDesiredStateEntityPK pk = new HostComponentDesiredStateEntityPK();
     pk.setClusterId(Long.valueOf(cluster.getClusterId()));

http://git-wip-us.apache.org/repos/asf/ambari/blob/392a752d/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
index e151d73..3bff060 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
@@ -33,7 +33,6 @@ import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
 import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
 import static org.easymock.EasyMock.verify;
 
 import java.io.File;
@@ -88,11 +87,7 @@ import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.Capture;
 import org.easymock.CaptureType;
 import org.easymock.EasyMockSupport;
-import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.inject.AbstractModule;
@@ -107,14 +102,16 @@ import com.google.inject.persist.PersistService;
  * {@link org.apache.ambari.server.upgrade.UpgradeCatalog210} unit tests.
  */
 public class UpgradeCatalog210Test {
-  private static Injector injector;
+  private Injector injector;
   private Provider<EntityManager> entityManagerProvider = createStrictMock(Provider.class);
   private EntityManager entityManager = createNiceMock(EntityManager.class);
-  private static UpgradeCatalogHelper upgradeCatalogHelper;
-  private static StackEntity desiredStackEntity;
+  private UpgradeCatalogHelper upgradeCatalogHelper;
+  private StackEntity desiredStackEntity;
 
-  @BeforeClass
-  public static void classSetUp() {
+  public void initData() {
+    //reset(entityManagerProvider);
+    //expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
+    //replay(entityManagerProvider);
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
 
@@ -126,22 +123,7 @@ public class UpgradeCatalog210Test {
     desiredStackEntity = stackDAO.find("HDP", "2.2.0");
   }
 
-  @Before
-  public void init() {
-    reset(entityManagerProvider);
-    expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
-    replay(entityManagerProvider);
-
-
-  }
-
-  @After
   public void tearDown() {
-
-  }
-
-  @AfterClass
-  public static void afterClass() throws Exception {
     injector.getInstance(PersistService.class).stop();
   }
 
@@ -821,6 +803,7 @@ public class UpgradeCatalog210Test {
 
   @Test
   public void testDeleteStormRestApiServiceComponent() throws Exception {
+    initData();
     ClusterEntity clusterEntity = upgradeCatalogHelper.createCluster(injector,
       "c1", desiredStackEntity);
     ClusterServiceEntity clusterServiceEntity = upgradeCatalogHelper.createService(
@@ -879,6 +862,7 @@ public class UpgradeCatalog210Test {
 
     Assert.assertNull(componentDesiredStateDAO.findByName(clusterEntity.getClusterId(), "STORM",
         "STORM_REST_API"));
+    tearDown();
   }
 
 


Mime
View raw message