use of com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView in project cloudbreak by hortonworks.
the class ClusterTemplateServiceFilterTest method testListInWorkspaceAndCleanUpInvalidsWhenFilteringByCloudPlatform.
@ParameterizedTest(name = "{0}")
@MethodSource("listInWorkspaceAndCleanUpInvalidsDataProvider")
void testListInWorkspaceAndCleanUpInvalidsWhenFilteringByCloudPlatform(String testCaseName, boolean awsEnabled, boolean azureEnabled, Set<ClusterTemplateViewV4Response> expectedResult) throws TransactionService.TransactionExecutionException {
Set<ClusterTemplateView> views = Set.of(new ClusterTemplateView(), new ClusterTemplateView());
List<ClusterTemplateViewV4Response> responses = List.of(CLUSTER_TEMPLATE_VIEW_V4_RESPONSE_AWS, CLUSTER_TEMPLATE_VIEW_V4_RESPONSE_AZURE);
when(entitlementService.internalTenant(anyString())).thenReturn(true);
when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
when(clusterTemplateViewService.findAllActive(WORKSPACE_ID, true)).thenReturn(views);
int index = 0;
for (ClusterTemplateView view : views) {
when(clusterTemplateViewToClusterTemplateViewV4ResponseConverter.convert(view)).thenReturn(responses.get(index++));
}
when(cloudPlatformValidator.isClusterTemplateCloudPlatformValid(AWS, ACCOUNT_ID)).thenReturn(awsEnabled);
when(cloudPlatformValidator.isClusterTemplateCloudPlatformValid(AZURE, ACCOUNT_ID)).thenReturn(azureEnabled);
Set<ClusterTemplateViewV4Response> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.listInWorkspaceAndCleanUpInvalids(WORKSPACE_ID, "accountId"));
assertThat(result).isEqualTo(expectedResult);
verify(environmentServiceDecorator).prepareEnvironments(responses.stream().collect(Collectors.toSet()));
}
use of com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView in project cloudbreak by hortonworks.
the class ClusterTemplateViewServiceTest method testFindAllUserManagedAndDefaultByEnvironmentCrnWhenRepositoryCanFindClusterTemplatesThenNonEmptySetShouldReturn.
@ParameterizedTest
@EnumSource(CloudPlatform.class)
public void testFindAllUserManagedAndDefaultByEnvironmentCrnWhenRepositoryCanFindClusterTemplatesThenNonEmptySetShouldReturn(CloudPlatform cloudPlatform) {
ClusterTemplateView match = new ClusterTemplateView();
Set<ClusterTemplateView> expectedNonEmptyResultSet = Set.of(match);
when(repository.findAllUserManagedAndDefaultByEnvironmentCrn(any(), any(), any(), any())).thenReturn(expectedNonEmptyResultSet);
when(internalClusterTemplateValidator.shouldPopulate(match, false)).thenReturn(true);
Set<ClusterTemplateView> result = underTest.findAllUserManagedAndDefaultByEnvironmentCrn(WORKSPACE_ID, TEST_ENV_CRN, cloudPlatform.name(), TEST_RUNTIME, false);
assertEquals(expectedNonEmptyResultSet, result);
assertEquals(expectedNonEmptyResultSet.size(), result.size());
assertEquals(match, result.stream().findFirst().get());
verify(repository, ONCE).findAllUserManagedAndDefaultByEnvironmentCrn(any(), any(), any(), any());
verify(repository, ONCE).findAllUserManagedAndDefaultByEnvironmentCrn(WORKSPACE_ID, TEST_ENV_CRN, cloudPlatform.name(), TEST_RUNTIME);
}
use of com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView in project cloudbreak by hortonworks.
the class ClusterTemplateViewServiceTest method testPrepareDeletion.
@Test
public void testPrepareDeletion() {
BadRequestException expectedException = assertThrows(BadRequestException.class, () -> underTest.prepareDeletion(new ClusterTemplateView()));
assertEquals("Cluster template deletion is not supported from ClusterTemplateViewService", expectedException.getMessage());
}
use of com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView in project cloudbreak by hortonworks.
the class ClusterTemplateViewServiceTest method testWhenFindAllAvailableViewInWorkspaceIsCalledThenItsResultSetShouldBeNotReturned.
@Test
public void testWhenFindAllAvailableViewInWorkspaceIsCalledThenItsResultSetShouldBeNotReturned() {
ClusterTemplateView repositoryResult = new ClusterTemplateView();
Set<ClusterTemplateView> resultSetFromRepository = Set.of(repositoryResult);
when(repository.findAllActive(WORKSPACE_ID)).thenReturn(resultSetFromRepository);
when(internalClusterTemplateValidator.shouldPopulate(repositoryResult, false)).thenReturn(false);
Set<ClusterTemplateView> result = underTest.findAllActive(WORKSPACE_ID, false);
assertNotNull(result);
assertEquals(0, result.size());
}
Aggregations