use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response in project cloudbreak by hortonworks.
the class EnvironmentServiceDecoratorTest method testPrepareEnvironmentsAndCredentialNameWhenEnvironmentCrnProvidedThenShouldCallGetEnvironmentByCrn.
@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");
assertEquals(stackViewResponses.iterator().next().isGovCloud(), false);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response in project cloudbreak by hortonworks.
the class EnvironmentServiceDecoratorTest method testPrepareEnvironmentsAndCredentialWithoutNameAndCrnWhenNameProvidedThenShouldCallGetEnvironmentList.
@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");
assertEquals(stackViewResponses.iterator().next().isGovCloud(), false);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response in project cloudbreak by hortonworks.
the class EnvironmentServiceDecoratorTest method testPrepareEnvironmentsAndCredentialEnvironmentNameWhenNameProvidedThenShouldCallGetEnvironmentByName.
@Test
void testPrepareEnvironmentsAndCredentialEnvironmentNameWhenNameProvidedThenShouldCallGetEnvironmentByName() {
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(false);
when(nameOrCrn.hasName()).thenReturn(true);
when(nameOrCrn.getName()).thenReturn("name");
when(detailedEnvironmentResponse.getCredential()).thenReturn(credentialResponse);
when(credentialResponse.getName()).thenReturn("credential-name");
when(detailedEnvironmentResponse.getName()).thenReturn("env-name");
when(environmentClientService.getByName(any())).thenReturn(detailedEnvironmentResponse);
underTest.prepareEnvironmentsAndCredentialName(stackViewResponses, nameOrCrn);
verify(environmentClientService, times(1)).getByName(any());
assertEquals(stackViewResponses.iterator().next().getEnvironmentName(), "env-name");
assertEquals(stackViewResponses.iterator().next().getCredentialName(), "credential-name");
assertEquals(stackViewResponses.iterator().next().isGovCloud(), false);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response in project cloudbreak by hortonworks.
the class StackOperationsTest method testGetForInternalCrn.
@Test
public void testGetForInternalCrn() {
when(cloudbreakUser.getUserCrn()).thenReturn("crn:altus:iam:us-west-1:altus:user:__internal__actor__");
when(stackApiViewService.retrieveStackByCrnAndType(anyString(), any(StackType.class))).thenReturn(new StackApiView());
when(stackApiViewToStackViewV4ResponseConverter.convert(any(StackApiView.class))).thenReturn(new StackViewV4Response());
doNothing().when(environmentServiceDecorator).prepareEnvironment(any(StackViewV4Response.class));
StackViewV4Response response = underTest.getForInternalCrn(NameOrCrn.ofCrn("myCrn"), STACK_TYPE);
assertNotNull(response);
verify(stackApiViewService, times(1)).retrieveStackByCrnAndType(anyString(), any(StackType.class));
verify(stackApiViewToStackViewV4ResponseConverter, times(1)).convert(any(StackApiView.class));
verify(environmentServiceDecorator, times(1)).prepareEnvironment(any(StackViewV4Response.class));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response in project cloudbreak by hortonworks.
the class EnvironmentServiceDecorator method prepareEnvironmentAndCredential.
public void prepareEnvironmentAndCredential(Set<StackViewV4Response> stackViewResponses, DetailedEnvironmentResponse detailedEnvironmentResponse) {
for (StackViewV4Response stackViewResponse : stackViewResponses) {
if (detailedEnvironmentResponse != null) {
CredentialResponse credential = detailedEnvironmentResponse.getCredential();
stackViewResponse.setGovCloud(credential.getGovCloud() == null ? false : credential.getGovCloud());
stackViewResponse.setCredentialName(credential.getName());
stackViewResponse.setEnvironmentName(detailedEnvironmentResponse.getName());
}
}
}
Aggregations