use of com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn 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.dto.NameOrCrn 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.dto.NameOrCrn 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.dto.NameOrCrn in project cloudbreak by hortonworks.
the class StackOperationsTest method testGetWhenNameOrCrnNameFilledThenProperGetCalled.
@Test
public void testGetWhenNameOrCrnNameFilledThenProperGetCalled() {
StackV4Response expected = stackResponse();
NameOrCrn nameOrCrn = NameOrCrn.ofName(stack.getName());
when(stackCommonService.findStackByNameOrCrnAndWorkspaceId(nameOrCrn, stack.getWorkspace().getId(), STACK_ENTRIES, STACK_TYPE)).thenReturn(expected);
StackV4Response result = underTest.get(nameOrCrn, stack.getWorkspace().getId(), STACK_ENTRIES, STACK_TYPE);
assertEquals(expected, result);
verify(stackCommonService, times(1)).findStackByNameOrCrnAndWorkspaceId(nameOrCrn, stack.getWorkspace().getId(), STACK_ENTRIES, STACK_TYPE);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn in project cloudbreak by hortonworks.
the class StackOperationsTest method testChangeImageCatalogFlowNotInProgress.
@Test
public void testChangeImageCatalogFlowNotInProgress() {
NameOrCrn nameOrCrn = NameOrCrn.ofName(stack.getName());
when(stackService.getByNameOrCrnInWorkspace(nameOrCrn, stack.getWorkspace().getId())).thenReturn(stack);
when(flowLogService.isOtherFlowRunning(stack.getId())).thenReturn(false);
underTest.changeImageCatalog(nameOrCrn, stack.getWorkspace().getId(), IMAGE_CATALOG);
verify(stackImageService).changeImageCatalog(stack, IMAGE_CATALOG);
}
Aggregations