Search in sources :

Example 11 with ClusterTemplateView

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()));
}
Also used : ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) Supplier(java.util.function.Supplier) ClusterTemplateViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with ClusterTemplateView

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);
}
Also used : ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with ClusterTemplateView

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());
}
Also used : ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with ClusterTemplateView

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());
}
Also used : ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ClusterTemplateView (com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView)14 Test (org.junit.jupiter.api.Test)10 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)6 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)6 ClusterTemplateViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response)2 HashSet (java.util.HashSet)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)1 Supplier (java.util.function.Supplier)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1