@Test void testPrepareEnvironmentsAndCredentialNameWhenEnvironmentCrnProvidedThenShouldCallGetEnvironmentByCrn() { DetailedEnvironmentResponse detailedEnvironmentResponse = mock(DetailedEnvironmentResponse.class); CredentialResponse credentialResponse = mock(CredentialResponse.class); NameOrCrn nameOrCrn = mock(NameOrCrn.class); Set<StackViewV4Response> stackViewResponses = Set.of( new StackViewV4Response()); when(nameOrCrn.hasCrn()).thenReturn(true); when(nameOrCrn.getCrn()).thenReturn("crn"); when(detailedEnvironmentResponse.getCredential()).thenReturn(credentialResponse); when(credentialResponse.getName()).thenReturn("credential-name"); when(detailedEnvironmentResponse.getName()).thenReturn("env-name"); when(environmentClientService.getByCrn(any())).thenReturn(detailedEnvironmentResponse); underTest.prepareEnvironmentsAndCredentialName(stackViewResponses, nameOrCrn); verify(environmentClientService, times(1)).getByCrn(any()); assertEquals(stackViewResponses.iterator().next().getEnvironmentName(), "env-name"); assertEquals(stackViewResponses.iterator().next().getCredentialName(), "credential-name"); }
public void prepareEnvironmentsAndCredentialName(Set<StackViewV4Response> stackViewResponses, NameOrCrn nameOrCrn) { if (nameOrCrn.hasCrn()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByCrn(nameOrCrn.getCrn())); } else if (nameOrCrn.hasName()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByName(nameOrCrn.getName())); } else { Collection<SimpleEnvironmentResponse> responses = environmentClientService.list().getResponses(); for (StackViewV4Response stackViewResponse : stackViewResponses) { Optional<SimpleEnvironmentResponse> first = responses.stream() .filter(x -> x.getCrn().equals(stackViewResponse.getEnvironmentCrn())) .findFirst(); if (first.isPresent()) { stackViewResponse.setCredentialName(first.get().getCredential().getName()); stackViewResponse.setEnvironmentName(first.get().getName()); } } } }
EnvironmentServiceDecorator { public void prepareEnvironmentsAndCredentialName(Set<StackViewV4Response> stackViewResponses, NameOrCrn nameOrCrn) { if (nameOrCrn.hasCrn()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByCrn(nameOrCrn.getCrn())); } else if (nameOrCrn.hasName()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByName(nameOrCrn.getName())); } else { Collection<SimpleEnvironmentResponse> responses = environmentClientService.list().getResponses(); for (StackViewV4Response stackViewResponse : stackViewResponses) { Optional<SimpleEnvironmentResponse> first = responses.stream() .filter(x -> x.getCrn().equals(stackViewResponse.getEnvironmentCrn())) .findFirst(); if (first.isPresent()) { stackViewResponse.setCredentialName(first.get().getCredential().getName()); stackViewResponse.setEnvironmentName(first.get().getName()); } } } } }
EnvironmentServiceDecorator { public void prepareEnvironmentsAndCredentialName(Set<StackViewV4Response> stackViewResponses, NameOrCrn nameOrCrn) { if (nameOrCrn.hasCrn()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByCrn(nameOrCrn.getCrn())); } else if (nameOrCrn.hasName()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByName(nameOrCrn.getName())); } else { Collection<SimpleEnvironmentResponse> responses = environmentClientService.list().getResponses(); for (StackViewV4Response stackViewResponse : stackViewResponses) { Optional<SimpleEnvironmentResponse> first = responses.stream() .filter(x -> x.getCrn().equals(stackViewResponse.getEnvironmentCrn())) .findFirst(); if (first.isPresent()) { stackViewResponse.setCredentialName(first.get().getCredential().getName()); stackViewResponse.setEnvironmentName(first.get().getName()); } } } }  }
EnvironmentServiceDecorator { public void prepareEnvironmentsAndCredentialName(Set<StackViewV4Response> stackViewResponses, NameOrCrn nameOrCrn) { if (nameOrCrn.hasCrn()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByCrn(nameOrCrn.getCrn())); } else if (nameOrCrn.hasName()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByName(nameOrCrn.getName())); } else { Collection<SimpleEnvironmentResponse> responses = environmentClientService.list().getResponses(); for (StackViewV4Response stackViewResponse : stackViewResponses) { Optional<SimpleEnvironmentResponse> first = responses.stream() .filter(x -> x.getCrn().equals(stackViewResponse.getEnvironmentCrn())) .findFirst(); if (first.isPresent()) { stackViewResponse.setCredentialName(first.get().getCredential().getName()); stackViewResponse.setEnvironmentName(first.get().getName()); } } } }  void prepareEnvironmentsAndCredentialName(Set<StackViewV4Response> stackViewResponses, NameOrCrn nameOrCrn); void prepareEnvironmentAndCredential(Set<StackViewV4Response> stackViewResponses,
        DetailedEnvironmentResponse detailedEnvironmentResponse); void prepareEnvironmentAndCredentialName(StackV4Response stackResponse); void prepareEnvironments(Set<ClusterTemplateViewV4Response> clusterTemplateViewV4Responses); void prepareEnvironment(ClusterTemplateV4Response clusterTemplateV4Response); void prepareEnvironment(StackViewV4Response stackViewResponse); }
EnvironmentServiceDecorator { public void prepareEnvironmentsAndCredentialName(Set<StackViewV4Response> stackViewResponses, NameOrCrn nameOrCrn) { if (nameOrCrn.hasCrn()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByCrn(nameOrCrn.getCrn())); } else if (nameOrCrn.hasName()) { prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByName(nameOrCrn.getName())); } else { Collection<SimpleEnvironmentResponse> responses = environmentClientService.list().getResponses(); for (StackViewV4Response stackViewResponse : stackViewResponses) { Optional<SimpleEnvironmentResponse> first = responses.stream() .filter(x -> x.getCrn().equals(stackViewResponse.getEnvironmentCrn())) .findFirst(); if (first.isPresent()) { stackViewResponse.setCredentialName(first.get().getCredential().getName()); stackViewResponse.setEnvironmentName(first.get().getName()); } } } }  void prepareEnvironmentsAndCredentialName(Set<StackViewV4Response> stackViewResponses, NameOrCrn nameOrCrn); void prepareEnvironmentAndCredential(Set<StackViewV4Response> stackViewResponses,
        DetailedEnvironmentResponse detailedEnvironmentResponse); void prepareEnvironmentAndCredentialName(StackV4Response stackResponse); void prepareEnvironments(Set<ClusterTemplateViewV4Response> clusterTemplateViewV4Responses); void prepareEnvironment(ClusterTemplateV4Response clusterTemplateV4Response); void prepareEnvironment(StackViewV4Response stackViewResponse);  }