@Test public void testExecuteDMLUpdates() throws Exception { final DBAccessor dbAccessor = injector.getInstance(DBAccessor.class); UpgradeCatalog230 upgradeCatalog = injector.getInstance(UpgradeCatalog230.class); final ResourceTypeEntity ambariResourceTypeEntity = createMock(ResourceTypeEntity.class); expect(ambariResourceTypeEntity.getId()).andReturn(1).anyTimes(); final ResourceTypeEntity clusterResourceTypeEntity = createMock(ResourceTypeEntity.class); expect(clusterResourceTypeEntity.getId()).andReturn(2).anyTimes(); final ResourceTypeEntity viewResourceTypeEntity = createMock(ResourceTypeEntity.class); expect(viewResourceTypeEntity.getId()).andReturn(3).anyTimes(); final ResourceTypeDAO resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class); expect(resourceTypeDAO.findByName("AMBARI")).andReturn(ambariResourceTypeEntity).anyTimes(); expect(resourceTypeDAO.findByName("CLUSTER")).andReturn(clusterResourceTypeEntity).anyTimes(); expect(resourceTypeDAO.findByName("VIEW")).andReturn(viewResourceTypeEntity).anyTimes(); final PermissionEntity viewUserPermissionEntity = createMock(PermissionEntity.class); expect(viewUserPermissionEntity.getId()).andReturn(1).anyTimes(); final PermissionEntity ambariAdministratorPermissionEntity = createMock(PermissionEntity.class); expect(ambariAdministratorPermissionEntity.getId()).andReturn(2).anyTimes(); final PermissionEntity clusterUserPermissionEntity = createMock(PermissionEntity.class); expect(clusterUserPermissionEntity.getId()).andReturn(3).anyTimes(); final PermissionEntity clusterOperatorPermissionEntity = createMock(PermissionEntity.class); expect(clusterOperatorPermissionEntity.getId()).andReturn(4).anyTimes(); final PermissionEntity clusterAdministratorPermissionEntity = createMock(PermissionEntity.class); expect(clusterAdministratorPermissionEntity.getId()).andReturn(5).anyTimes(); final PermissionEntity serviceAdministratorPermissionEntity = createMock(PermissionEntity.class); expect(serviceAdministratorPermissionEntity.getId()).andReturn(6).anyTimes(); final PermissionEntity serviceOperatorPermissionEntity = createMock(PermissionEntity.class); expect(serviceOperatorPermissionEntity.getId()).andReturn(7).anyTimes(); final PermissionDAO permissionDAO = injector.getInstance(PermissionDAO.class); expect(permissionDAO.findPermissionByNameAndType("VIEW.USER", viewResourceTypeEntity)) .andReturn(viewUserPermissionEntity) .anyTimes(); expect(permissionDAO.findPermissionByNameAndType("AMBARI.ADMINISTRATOR", ambariResourceTypeEntity)) .andReturn(ambariAdministratorPermissionEntity) .anyTimes(); expect(permissionDAO.findPermissionByNameAndType("CLUSTER.USER", clusterResourceTypeEntity)) .andReturn(clusterUserPermissionEntity) .anyTimes(); expect(permissionDAO.findPermissionByNameAndType("CLUSTER.OPERATOR", clusterResourceTypeEntity)) .andReturn(clusterOperatorPermissionEntity) .anyTimes(); expect(permissionDAO.findPermissionByNameAndType("CLUSTER.ADMINISTRATOR", clusterResourceTypeEntity)) .andReturn(clusterAdministratorPermissionEntity) .anyTimes(); expect(permissionDAO.findPermissionByNameAndType("SERVICE.ADMINISTRATOR", clusterResourceTypeEntity)) .andReturn(serviceAdministratorPermissionEntity) .anyTimes(); expect(permissionDAO.findPermissionByNameAndType("SERVICE.OPERATOR", clusterResourceTypeEntity)) .andReturn(serviceOperatorPermissionEntity) .anyTimes(); String updateQueryPattern; updateQueryPattern = "UPDATE adminpermission SET permission_label='%s' WHERE permission_id=%d"; expect(dbAccessor.executeUpdate(String.format(updateQueryPattern, "Ambari Administrator", PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION))) .andReturn(1).once(); expect(dbAccessor.executeUpdate(String.format(updateQueryPattern, "Cluster User", PermissionEntity.CLUSTER_USER_PERMISSION))) .andReturn(1).once(); expect(dbAccessor.executeUpdate(String.format(updateQueryPattern, "Cluster Administrator", PermissionEntity.CLUSTER_ADMINISTRATOR_PERMISSION))) .andReturn(1).once(); expect(dbAccessor.executeUpdate(String.format(updateQueryPattern, "View User", PermissionEntity.VIEW_USER_PERMISSION))) .andReturn(1).once(); updateQueryPattern = "UPDATE adminpermission SET permission_name='%s' WHERE permission_id=%d"; expect(dbAccessor.executeUpdate(String.format(updateQueryPattern, PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION_NAME, PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION))) .andReturn(1).once(); expect(dbAccessor.executeUpdate(String.format(updateQueryPattern, PermissionEntity.CLUSTER_USER_PERMISSION_NAME, PermissionEntity.CLUSTER_USER_PERMISSION))) .andReturn(1).once(); expect(dbAccessor.executeUpdate(String.format(updateQueryPattern, PermissionEntity.CLUSTER_ADMINISTRATOR_PERMISSION_NAME, PermissionEntity.CLUSTER_ADMINISTRATOR_PERMISSION))) .andReturn(1).once(); expect(dbAccessor.executeUpdate(String.format(updateQueryPattern, PermissionEntity.VIEW_USER_PERMISSION_NAME, PermissionEntity.VIEW_USER_PERMISSION))) .andReturn(1).once(); RoleAuthorizationEntity roleAuthorization = createMock(RoleAuthorizationEntity.class); RoleAuthorizationDAO roleAuthorizationDAO = injector.getInstance(RoleAuthorizationDAO.class); expect(roleAuthorizationDAO.findById(anyString())).andReturn(roleAuthorization).anyTimes(); Collection<RoleAuthorizationEntity> authorizations = new ArrayList<RoleAuthorizationEntity>(); expect(ambariAdministratorPermissionEntity.getAuthorizations()).andReturn(authorizations).atLeastOnce(); expect(clusterAdministratorPermissionEntity.getAuthorizations()).andReturn(authorizations).atLeastOnce(); expect(clusterOperatorPermissionEntity.getAuthorizations()).andReturn(authorizations).atLeastOnce(); expect(serviceAdministratorPermissionEntity.getAuthorizations()).andReturn(authorizations).atLeastOnce(); expect(serviceOperatorPermissionEntity.getAuthorizations()).andReturn(authorizations).atLeastOnce(); expect(clusterUserPermissionEntity.getAuthorizations()).andReturn(authorizations).atLeastOnce(); expect(viewUserPermissionEntity.getAuthorizations()).andReturn(authorizations).atLeastOnce(); expect(permissionDAO.merge(ambariAdministratorPermissionEntity)).andReturn(ambariAdministratorPermissionEntity).atLeastOnce(); expect(permissionDAO.merge(clusterAdministratorPermissionEntity)).andReturn(clusterAdministratorPermissionEntity).atLeastOnce(); expect(permissionDAO.merge(clusterOperatorPermissionEntity)).andReturn(clusterOperatorPermissionEntity).atLeastOnce(); expect(permissionDAO.merge(serviceAdministratorPermissionEntity)).andReturn(serviceAdministratorPermissionEntity).atLeastOnce(); expect(permissionDAO.merge(serviceOperatorPermissionEntity)).andReturn(serviceOperatorPermissionEntity).atLeastOnce(); expect(permissionDAO.merge(clusterUserPermissionEntity)).andReturn(clusterUserPermissionEntity).atLeastOnce(); expect(permissionDAO.merge(viewUserPermissionEntity)).andReturn(viewUserPermissionEntity).atLeastOnce(); replayAll(); upgradeCatalog.executeDMLUpdates(); verifyAll(); }
@Override protected void executeDMLUpdates() throws AmbariException, SQLException { setPermissionLabels(); updatePermissionNames(); addNewPermissions(); createRoleAuthorizations(); createPermissionRoleAuthorizationMap(); }
UpgradeCatalog230 extends AbstractUpgradeCatalog { @Override protected void executeDMLUpdates() throws AmbariException, SQLException { setPermissionLabels(); updatePermissionNames(); addNewPermissions(); createRoleAuthorizations(); createPermissionRoleAuthorizationMap(); } }
UpgradeCatalog230 extends AbstractUpgradeCatalog { @Override protected void executeDMLUpdates() throws AmbariException, SQLException { setPermissionLabels(); updatePermissionNames(); addNewPermissions(); createRoleAuthorizations(); createPermissionRoleAuthorizationMap(); } @Inject  UpgradeCatalog230(Injector injector); }
UpgradeCatalog230 extends AbstractUpgradeCatalog { @Override protected void executeDMLUpdates() throws AmbariException, SQLException { setPermissionLabels(); updatePermissionNames(); addNewPermissions(); createRoleAuthorizations(); createPermissionRoleAuthorizationMap(); } @Inject  UpgradeCatalog230(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion(); }
UpgradeCatalog230 extends AbstractUpgradeCatalog { @Override protected void executeDMLUpdates() throws AmbariException, SQLException { setPermissionLabels(); updatePermissionNames(); addNewPermissions(); createRoleAuthorizations(); createPermissionRoleAuthorizationMap(); } @Inject  UpgradeCatalog230(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion();  }