@Test void attachChildEnvironment() { AttachChildEnvironmentRequest request = new AttachChildEnvironmentRequest(); request.setParentEnvironmentCrn(ENVIRONMENT_CRN); request.setChildEnvironmentCrn(CHILD_ENVIRONMENT_CRN); Stack stack = new Stack(); when(stackService.getByOwnEnvironmentCrnAndAccountIdWithLists(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack); underTest.attachChildEnvironment(request, ACCOUNT_ID); ArgumentCaptor<ChildEnvironment> childEnvironmentArgumentCaptor = ArgumentCaptor.forClass(ChildEnvironment.class); verify(repository).save(childEnvironmentArgumentCaptor.capture()); ChildEnvironment childEnvironment = childEnvironmentArgumentCaptor.getValue(); Assertions.assertThat(childEnvironment) .returns(CHILD_ENVIRONMENT_CRN, ChildEnvironment::getEnvironmentCrn) .returns(stack, ChildEnvironment::getStack); }
public void attachChildEnvironment(AttachChildEnvironmentRequest request, String accountId) { Stack stack = stackService.getByOwnEnvironmentCrnAndAccountIdWithLists(request.getParentEnvironmentCrn(), accountId); MDCBuilder.buildMdcContext(stack); LOGGER.info("Attaching child [{}] environment to parent env [{}]", request.getChildEnvironmentCrn(), request.getParentEnvironmentCrn()); ChildEnvironment childEnvironment = new ChildEnvironment(); childEnvironment.setEnvironmentCrn(request.getChildEnvironmentCrn()); childEnvironment.setStack(stack); repository.save(childEnvironment); }
ChildEnvironmentService { public void attachChildEnvironment(AttachChildEnvironmentRequest request, String accountId) { Stack stack = stackService.getByOwnEnvironmentCrnAndAccountIdWithLists(request.getParentEnvironmentCrn(), accountId); MDCBuilder.buildMdcContext(stack); LOGGER.info("Attaching child [{}] environment to parent env [{}]", request.getChildEnvironmentCrn(), request.getParentEnvironmentCrn()); ChildEnvironment childEnvironment = new ChildEnvironment(); childEnvironment.setEnvironmentCrn(request.getChildEnvironmentCrn()); childEnvironment.setStack(stack); repository.save(childEnvironment); } }
ChildEnvironmentService { public void attachChildEnvironment(AttachChildEnvironmentRequest request, String accountId) { Stack stack = stackService.getByOwnEnvironmentCrnAndAccountIdWithLists(request.getParentEnvironmentCrn(), accountId); MDCBuilder.buildMdcContext(stack); LOGGER.info("Attaching child [{}] environment to parent env [{}]", request.getChildEnvironmentCrn(), request.getParentEnvironmentCrn()); ChildEnvironment childEnvironment = new ChildEnvironment(); childEnvironment.setEnvironmentCrn(request.getChildEnvironmentCrn()); childEnvironment.setStack(stack); repository.save(childEnvironment); }  }
ChildEnvironmentService { public void attachChildEnvironment(AttachChildEnvironmentRequest request, String accountId) { Stack stack = stackService.getByOwnEnvironmentCrnAndAccountIdWithLists(request.getParentEnvironmentCrn(), accountId); MDCBuilder.buildMdcContext(stack); LOGGER.info("Attaching child [{}] environment to parent env [{}]", request.getChildEnvironmentCrn(), request.getParentEnvironmentCrn()); ChildEnvironment childEnvironment = new ChildEnvironment(); childEnvironment.setEnvironmentCrn(request.getChildEnvironmentCrn()); childEnvironment.setStack(stack); repository.save(childEnvironment); }  boolean isChildEnvironment(String environmentCrn, String accountId); Optional<Stack> findParentByEnvironmentCrnAndAccountId(String environmentCrn, String accountId); List<ChildEnvironment> findChildEnvironments(Stack stack, String accountId); void attachChildEnvironment(AttachChildEnvironmentRequest request, String accountId); void detachChildEnvironment(DetachChildEnvironmentRequest request, String accountId); }
ChildEnvironmentService { public void attachChildEnvironment(AttachChildEnvironmentRequest request, String accountId) { Stack stack = stackService.getByOwnEnvironmentCrnAndAccountIdWithLists(request.getParentEnvironmentCrn(), accountId); MDCBuilder.buildMdcContext(stack); LOGGER.info("Attaching child [{}] environment to parent env [{}]", request.getChildEnvironmentCrn(), request.getParentEnvironmentCrn()); ChildEnvironment childEnvironment = new ChildEnvironment(); childEnvironment.setEnvironmentCrn(request.getChildEnvironmentCrn()); childEnvironment.setStack(stack); repository.save(childEnvironment); }  boolean isChildEnvironment(String environmentCrn, String accountId); Optional<Stack> findParentByEnvironmentCrnAndAccountId(String environmentCrn, String accountId); List<ChildEnvironment> findChildEnvironments(Stack stack, String accountId); void attachChildEnvironment(AttachChildEnvironmentRequest request, String accountId); void detachChildEnvironment(DetachChildEnvironmentRequest request, String accountId);  }