TenantSetSecurityGroupsStepCmd extends StepCommand { @Override protected void execute() throws ExternalException { List<TenantEntity> tenantList = step.getTransientResourceEntities(null); checkArgument(tenantList.size() == 1); TenantEntity tenantEntity = tenantList.get(0); logger.info("Updating the security groups of tenant {}", tenantEntity.getId()); tenantBackend.setSecurityGroups(tenantEntity.getId(), SecurityGroupUtils.toApiRepresentation(tenantEntity.getSecurityGroups())); } TenantSetSecurityGroupsStepCmd(TaskCommand taskCommand, StepBackend stepBackend,
                                        StepEntity stepEntity, TenantBackend tenantBackend);   }
@Test public void testExecuteSuccess() throws Exception { TenantEntity tenantEntity = new TenantEntity(); List<TenantEntity> tenantEntityList = new ArrayList<>(); tenantEntityList.add(tenantEntity); doReturn(tenantEntityList).when(stepEntity).getTransientResourceEntities(null); TenantSetSecurityGroupsStepCmd cmd = new TenantSetSecurityGroupsStepCmd(taskCommand, stepBackend, stepEntity, tenantBackend); cmd.execute(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testCheckArgumentFailed() throws Exception { doReturn(new ArrayList<TenantEntity>()).when(stepEntity).getTransientResourceEntities(null); TenantSetSecurityGroupsStepCmd cmd = new TenantSetSecurityGroupsStepCmd(taskCommand, stepBackend, stepEntity, tenantBackend); cmd.execute(); }
@Test(expectedExceptions = ExternalException.class, expectedExceptionsMessageRegExp = "Failed to change security groups") public void testThrowExternalException() throws Exception { TenantEntity tenantEntity = new TenantEntity(); List<TenantEntity> tenantEntityList = new ArrayList<>(); tenantEntityList.add(tenantEntity); doReturn(tenantEntityList).when(stepEntity).getTransientResourceEntities(null); doThrow(new ExternalException("Failed to change security groups")) .when(tenantBackend) .setSecurityGroups(anyString(), anyObject()); TenantSetSecurityGroupsStepCmd cmd = new TenantSetSecurityGroupsStepCmd(taskCommand, stepBackend, stepEntity, tenantBackend); cmd.execute(); }