@Test public void testCreateFlowContext() { when(dbStackService.findById(Long.valueOf(1L))).thenReturn(Optional.of(dbStack)); when(credentialService.getCredentialByEnvCrn("myenv")).thenReturn(credential); when(credentialConverter.convert(credential)).thenReturn(cloudCredential); when(databaseStackConverter.convert(dbStack)).thenReturn(databaseStack); RedbeamsContext ctx = underTest.createFlowContext(flowParameters, stateContext, new RedbeamsEvent(1L)); assertEquals(dbStack.getId(), ctx.getCloudContext().getId()); assertEquals(dbStack.getName(), ctx.getCloudContext().getName()); assertEquals(Platform.platform(dbStack.getCloudPlatform()), ctx.getCloudContext().getPlatform()); assertEquals(Variant.variant(dbStack.getPlatformVariant()), ctx.getCloudContext().getVariant()); assertEquals(Location.location(Region.region(dbStack.getRegion()), AvailabilityZone.availabilityZone(dbStack.getAvailabilityZone())), ctx.getCloudContext().getLocation()); assertEquals(dbStack.getOwnerCrn().getUserId(), ctx.getCloudContext().getUserId()); assertEquals(dbStack.getOwnerCrn().getAccountId(), ctx.getCloudContext().getAccountId()); assertEquals(cloudCredential, ctx.getCloudCredential()); assertEquals(databaseStack, ctx.getDatabaseStack()); }
@Override protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, P payload) { Optional<DBStack> optionalDBStack = dbStackService.findById(payload.getResourceId()); CloudContext cloudContext = null; CloudCredential cloudCredential = null; DatabaseStack databaseStack = null; DBStack dbStack = null; dbStack = optionalDBStack.get(); MDCBuilder.buildMdcContext(dbStack); Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone())); String userName = dbStack.getOwnerCrn().getUserId(); String accountId = dbStack.getOwnerCrn().getAccountId(); cloudContext = new CloudContext(dbStack.getId(), dbStack.getName(), dbStack.getCloudPlatform(), dbStack.getPlatformVariant(), location, userName, accountId); if (optionalDBStack.isPresent()) { try { Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId()); cloudCredential = credentialConverter.convert(credential); } catch (Exception ex) { LOGGER.warn("Could not detect credential for environment: {}", dbStack.getEnvironmentId()); } databaseStack = databaseStackConverter.convert(dbStack); } return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack); }
AbstractRedbeamsTerminationAction extends AbstractAction<RedbeamsTerminationState, RedbeamsTerminationEvent, RedbeamsContext, P> { @Override protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, P payload) { Optional<DBStack> optionalDBStack = dbStackService.findById(payload.getResourceId()); CloudContext cloudContext = null; CloudCredential cloudCredential = null; DatabaseStack databaseStack = null; DBStack dbStack = null; dbStack = optionalDBStack.get(); MDCBuilder.buildMdcContext(dbStack); Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone())); String userName = dbStack.getOwnerCrn().getUserId(); String accountId = dbStack.getOwnerCrn().getAccountId(); cloudContext = new CloudContext(dbStack.getId(), dbStack.getName(), dbStack.getCloudPlatform(), dbStack.getPlatformVariant(), location, userName, accountId); if (optionalDBStack.isPresent()) { try { Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId()); cloudCredential = credentialConverter.convert(credential); } catch (Exception ex) { LOGGER.warn("Could not detect credential for environment: {}", dbStack.getEnvironmentId()); } databaseStack = databaseStackConverter.convert(dbStack); } return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack); } }
AbstractRedbeamsTerminationAction extends AbstractAction<RedbeamsTerminationState, RedbeamsTerminationEvent, RedbeamsContext, P> { @Override protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, P payload) { Optional<DBStack> optionalDBStack = dbStackService.findById(payload.getResourceId()); CloudContext cloudContext = null; CloudCredential cloudCredential = null; DatabaseStack databaseStack = null; DBStack dbStack = null; dbStack = optionalDBStack.get(); MDCBuilder.buildMdcContext(dbStack); Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone())); String userName = dbStack.getOwnerCrn().getUserId(); String accountId = dbStack.getOwnerCrn().getAccountId(); cloudContext = new CloudContext(dbStack.getId(), dbStack.getName(), dbStack.getCloudPlatform(), dbStack.getPlatformVariant(), location, userName, accountId); if (optionalDBStack.isPresent()) { try { Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId()); cloudCredential = credentialConverter.convert(credential); } catch (Exception ex) { LOGGER.warn("Could not detect credential for environment: {}", dbStack.getEnvironmentId()); } databaseStack = databaseStackConverter.convert(dbStack); } return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack); } protected  AbstractRedbeamsTerminationAction(Class<P> payloadClass); }
AbstractRedbeamsTerminationAction extends AbstractAction<RedbeamsTerminationState, RedbeamsTerminationEvent, RedbeamsContext, P> { @Override protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, P payload) { Optional<DBStack> optionalDBStack = dbStackService.findById(payload.getResourceId()); CloudContext cloudContext = null; CloudCredential cloudCredential = null; DatabaseStack databaseStack = null; DBStack dbStack = null; dbStack = optionalDBStack.get(); MDCBuilder.buildMdcContext(dbStack); Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone())); String userName = dbStack.getOwnerCrn().getUserId(); String accountId = dbStack.getOwnerCrn().getAccountId(); cloudContext = new CloudContext(dbStack.getId(), dbStack.getName(), dbStack.getCloudPlatform(), dbStack.getPlatformVariant(), location, userName, accountId); if (optionalDBStack.isPresent()) { try { Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId()); cloudCredential = credentialConverter.convert(credential); } catch (Exception ex) { LOGGER.warn("Could not detect credential for environment: {}", dbStack.getEnvironmentId()); } databaseStack = databaseStackConverter.convert(dbStack); } return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack); } protected  AbstractRedbeamsTerminationAction(Class<P> payloadClass); @PostConstruct void init(); }
AbstractRedbeamsTerminationAction extends AbstractAction<RedbeamsTerminationState, RedbeamsTerminationEvent, RedbeamsContext, P> { @Override protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, P payload) { Optional<DBStack> optionalDBStack = dbStackService.findById(payload.getResourceId()); CloudContext cloudContext = null; CloudCredential cloudCredential = null; DatabaseStack databaseStack = null; DBStack dbStack = null; dbStack = optionalDBStack.get(); MDCBuilder.buildMdcContext(dbStack); Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone())); String userName = dbStack.getOwnerCrn().getUserId(); String accountId = dbStack.getOwnerCrn().getAccountId(); cloudContext = new CloudContext(dbStack.getId(), dbStack.getName(), dbStack.getCloudPlatform(), dbStack.getPlatformVariant(), location, userName, accountId); if (optionalDBStack.isPresent()) { try { Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId()); cloudCredential = credentialConverter.convert(credential); } catch (Exception ex) { LOGGER.warn("Could not detect credential for environment: {}", dbStack.getEnvironmentId()); } databaseStack = databaseStackConverter.convert(dbStack); } return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack); } protected  AbstractRedbeamsTerminationAction(Class<P> payloadClass); @PostConstruct void init();  }