Search in sources :

Example 21 with StackViewV4Response

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);
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test)

Example 22 with StackViewV4Response

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);
}
Also used : CredentialViewResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialViewResponse) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) SimpleEnvironmentResponses(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponses) SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test)

Example 23 with StackViewV4Response

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);
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test)

Example 24 with StackViewV4Response

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));
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) StackApiView(com.sequenceiq.cloudbreak.domain.view.StackApiView) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) Test(org.junit.Test)

Example 25 with StackViewV4Response

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());
        }
    }
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)

Aggregations

StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)32 StackViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)18 Test (org.junit.jupiter.api.Test)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)10 Test (org.junit.Test)8 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)6 UpgradeOptionV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)3 RepairValidation (com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation)3 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)3 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)3 DistroXMultiDeleteV1Request (com.sequenceiq.distrox.api.v1.distrox.model.cluster.DistroXMultiDeleteV1Request)3 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ClusterViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.views.ClusterViewV4Response)2 StackApiView (com.sequenceiq.cloudbreak.domain.view.StackApiView)2