@Test
public void testConvertRolePrincipals() throws AmbariException, SQLException {

  EasyMockSupport easyMockSupport = new EasyMockSupport();
  PrincipalEntity clusterAdministratorPrincipalEntity = easyMockSupport.createMock(PrincipalEntity.class);
  PermissionEntity clusterAdministratorPermissionEntity = easyMockSupport.createMock(PermissionEntity.class);
  expect(clusterAdministratorPermissionEntity.getPrincipal())
      .andReturn(clusterAdministratorPrincipalEntity)
      .once();
  PrincipalTypeEntity allClusterAdministratorPrincipalTypeEntity = easyMockSupport.createMock(PrincipalTypeEntity.class);
  PermissionDAO permissionDAO = easyMockSupport.createMock(PermissionDAO.class);
  expect(permissionDAO.findByName("CLUSTER.ADMINISTRATOR"))
      .andReturn(clusterAdministratorPermissionEntity)
      .once();
  expect(permissionDAO.findByName(anyString()))
      .andReturn(null)
      .anyTimes();
  PrincipalTypeDAO principalTypeDAO = easyMockSupport.createMock(PrincipalTypeDAO.class);
  expect(principalTypeDAO.findByName("ALL.CLUSTER.ADMINISTRATOR"))
      .andReturn(allClusterAdministratorPrincipalTypeEntity)
      .once();
  expect(principalTypeDAO.findByName(anyString()))
      .andReturn(null)
      .anyTimes();
  principalTypeDAO.remove(allClusterAdministratorPrincipalTypeEntity);
  expectLastCall().once();
  ResourceEntity allClusterAdministratorPrivilege1Resource = easyMockSupport.createMock(ResourceEntity.class);
  expect(allClusterAdministratorPrivilege1Resource.getId()).andReturn(1L).once();
  PrincipalEntity allClusterAdministratorPrivilege1Principal = easyMockSupport.createMock(PrincipalEntity.class);
  expect(allClusterAdministratorPrivilege1Principal.getId()).andReturn(1L).once();
  PermissionEntity allClusterAdministratorPrivilege1Permission = easyMockSupport.createMock(PermissionEntity.class);
  expect(allClusterAdministratorPrivilege1Permission.getId()).andReturn(1).once();
  PrivilegeEntity allClusterAdministratorPrivilege1  = easyMockSupport.createMock(PrivilegeEntity.class);
  expect(allClusterAdministratorPrivilege1.getId()).andReturn(1).atLeastOnce();
  expect(allClusterAdministratorPrivilege1.getResource()).andReturn(allClusterAdministratorPrivilege1Resource).once();
  expect(allClusterAdministratorPrivilege1.getPrincipal()).andReturn(allClusterAdministratorPrivilege1Principal).once();
  expect(allClusterAdministratorPrivilege1.getPermission()).andReturn(allClusterAdministratorPrivilege1Permission).once();
  allClusterAdministratorPrivilege1.setPrincipal(clusterAdministratorPrincipalEntity);
  expectLastCall().once();
  ResourceEntity allClusterAdministratorPrivilege2Resource = easyMockSupport.createMock(ResourceEntity.class);
  expect(allClusterAdministratorPrivilege2Resource.getId()).andReturn(2L).once();
  PrincipalEntity allClusterAdministratorPrivilege2Principal = easyMockSupport.createMock(PrincipalEntity.class);
  expect(allClusterAdministratorPrivilege2Principal.getId()).andReturn(2L).once();
  PermissionEntity allClusterAdministratorPrivilege2Permission = easyMockSupport.createMock(PermissionEntity.class);
  expect(allClusterAdministratorPrivilege2Permission.getId()).andReturn(2).once();
  PrivilegeEntity allClusterAdministratorPrivilege2  = easyMockSupport.createMock(PrivilegeEntity.class);
  expect(allClusterAdministratorPrivilege2.getId()).andReturn(2).atLeastOnce();
  expect(allClusterAdministratorPrivilege2.getResource()).andReturn(allClusterAdministratorPrivilege2Resource).once();
  expect(allClusterAdministratorPrivilege2.getPrincipal()).andReturn(allClusterAdministratorPrivilege2Principal).once();
  expect(allClusterAdministratorPrivilege2.getPermission()).andReturn(allClusterAdministratorPrivilege2Permission).once();
  allClusterAdministratorPrivilege2.setPrincipal(clusterAdministratorPrincipalEntity);
  expectLastCall().once();
  Set<PrivilegeEntity> allClusterAdministratorPrivileges = new HashSet<PrivilegeEntity>();
  allClusterAdministratorPrivileges.add(allClusterAdministratorPrivilege1);
  allClusterAdministratorPrivileges.add(allClusterAdministratorPrivilege2);
  PrincipalEntity allClusterAdministratorPrincipalEntity = easyMockSupport.createMock(PrincipalEntity.class);
  expect(allClusterAdministratorPrincipalEntity.getPrivileges())
      .andReturn(allClusterAdministratorPrivileges)
      .once();
  List<PrincipalEntity> allClusterAdministratorPrincipals = new ArrayList<PrincipalEntity>();
  allClusterAdministratorPrincipals.add(allClusterAdministratorPrincipalEntity);
  PrincipalDAO principalDAO = easyMockSupport.createMock(PrincipalDAO.class);
  expect(principalDAO.findByPrincipalType("ALL.CLUSTER.ADMINISTRATOR"))
      .andReturn(allClusterAdministratorPrincipals)
      .once();
  principalDAO.remove(allClusterAdministratorPrincipalEntity);
  expectLastCall().once();
  PrivilegeDAO privilegeDAO = easyMockSupport.createMock(PrivilegeDAO.class);
  expect(privilegeDAO.merge(allClusterAdministratorPrivilege1))
      .andReturn(allClusterAdministratorPrivilege1)
      .once();
  expect(privilegeDAO.merge(allClusterAdministratorPrivilege2))
      .andReturn(allClusterAdministratorPrivilege2)
      .once();
  Injector injector = easyMockSupport.createNiceMock(Injector.class);
  expect(injector.getInstance(PrincipalTypeDAO.class)).andReturn(principalTypeDAO).atLeastOnce();
  expect(injector.getInstance(PrincipalDAO.class)).andReturn(principalDAO).atLeastOnce();
  expect(injector.getInstance(PermissionDAO.class)).andReturn(permissionDAO).atLeastOnce();
  expect(injector.getInstance(PrivilegeDAO.class)).andReturn(privilegeDAO).atLeastOnce();
  easyMockSupport.replayAll();
  UpgradeCatalog242 upgradeCatalog = new UpgradeCatalog242(injector);
  injector.injectMembers(upgradeCatalog);
  upgradeCatalog.convertRolePrincipals();
  easyMockSupport.verifyAll();
}