@Test void detachChildEnvironmentSuccess() { ChildEnvironment childEnvironment = new ChildEnvironment(); when(repository.findByParentAndChildEnvironmentCrns(ENVIRONMENT_CRN, CHILD_ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.of(childEnvironment)); DetachChildEnvironmentRequest request = new DetachChildEnvironmentRequest(); request.setParentEnvironmentCrn(ENVIRONMENT_CRN); request.setChildEnvironmentCrn(CHILD_ENVIRONMENT_CRN); underTest.detachChildEnvironment(request, ACCOUNT_ID); verify(repository).delete(childEnvironment); }
public void detachChildEnvironment(DetachChildEnvironmentRequest request, String accountId) { ChildEnvironment childEnvironment = repository.findByParentAndChildEnvironmentCrns( request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn(), accountId) .orElseThrow(() -> new NotFoundException(String.format("ChildEnvironment by parent environment crn [%s] and child environment crn [%s] not found", request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn()))); MDCBuilder.buildMdcContext(childEnvironment.getStack()); LOGGER.info("Detaching child env: {}", childEnvironment); repository.delete(childEnvironment); }
ChildEnvironmentService { public void detachChildEnvironment(DetachChildEnvironmentRequest request, String accountId) { ChildEnvironment childEnvironment = repository.findByParentAndChildEnvironmentCrns( request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn(), accountId) .orElseThrow(() -> new NotFoundException(String.format("ChildEnvironment by parent environment crn [%s] and child environment crn [%s] not found", request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn()))); MDCBuilder.buildMdcContext(childEnvironment.getStack()); LOGGER.info("Detaching child env: {}", childEnvironment); repository.delete(childEnvironment); } }
ChildEnvironmentService { public void detachChildEnvironment(DetachChildEnvironmentRequest request, String accountId) { ChildEnvironment childEnvironment = repository.findByParentAndChildEnvironmentCrns( request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn(), accountId) .orElseThrow(() -> new NotFoundException(String.format("ChildEnvironment by parent environment crn [%s] and child environment crn [%s] not found", request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn()))); MDCBuilder.buildMdcContext(childEnvironment.getStack()); LOGGER.info("Detaching child env: {}", childEnvironment); repository.delete(childEnvironment); }  }
ChildEnvironmentService { public void detachChildEnvironment(DetachChildEnvironmentRequest request, String accountId) { ChildEnvironment childEnvironment = repository.findByParentAndChildEnvironmentCrns( request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn(), accountId) .orElseThrow(() -> new NotFoundException(String.format("ChildEnvironment by parent environment crn [%s] and child environment crn [%s] not found", request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn()))); MDCBuilder.buildMdcContext(childEnvironment.getStack()); LOGGER.info("Detaching child env: {}", childEnvironment); repository.delete(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 detachChildEnvironment(DetachChildEnvironmentRequest request, String accountId) { ChildEnvironment childEnvironment = repository.findByParentAndChildEnvironmentCrns( request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn(), accountId) .orElseThrow(() -> new NotFoundException(String.format("ChildEnvironment by parent environment crn [%s] and child environment crn [%s] not found", request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn()))); MDCBuilder.buildMdcContext(childEnvironment.getStack()); LOGGER.info("Detaching child env: {}", childEnvironment); repository.delete(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);  }