@Test void testPrepareEnvironmentsAndCredentialWithoutNameAndCrnWhenNameProvidedThenShouldCallGetEnvironmentList() { SimpleEnvironmentResponses simpleEnvironmentResponses = new SimpleEnvironmentResponses(); SimpleEnvironmentResponse simpleEnvironmentResponse = new SimpleEnvironmentResponse(); CredentialViewResponse credentialViewResponse = new CredentialViewResponse(); NameOrCrn nameOrCrn = mock(NameOrCrn.class); StackViewV4Response stackViewV4Response = new StackViewV4Response(); stackViewV4Response.setEnvironmentCrn("env-crn"); Set<StackViewV4Response> stackViewResponses = Set.of(stackViewV4Response); when(nameOrCrn.hasCrn()).thenReturn(false); when(nameOrCrn.hasName()).thenReturn(false); credentialViewResponse.setName("credential-name"); simpleEnvironmentResponse.setCredential(credentialViewResponse); simpleEnvironmentResponse.setName("env-name"); simpleEnvironmentResponse.setCrn("env-crn"); simpleEnvironmentResponses.setResponses(Set.of(simpleEnvironmentResponse)); when(environmentClientService.list()).thenReturn(simpleEnvironmentResponses); underTest.prepareEnvironmentsAndCredentialName(stackViewResponses, nameOrCrn); verify(environmentClientService, times(1)).list(); 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);  }