Search in sources :

Example 11 with EnvironmentView

use of com.sequenceiq.environment.environment.domain.EnvironmentView in project cloudbreak by hortonworks.

the class EnvironmentResourceDeletionServiceTest method setup.

@BeforeEach
void setup() {
    environment = new EnvironmentView();
    environment.setId(1L);
    environment.setName(ENVIRONMENT_NAME);
    environment.setResourceCrn(ENVIRONMENT_CRN);
}
Also used : EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with EnvironmentView

use of com.sequenceiq.environment.environment.domain.EnvironmentView in project cloudbreak by hortonworks.

the class DataLakeClustersDeleteHandlerTest method accept.

@Test
void accept() {
    EnvironmentView environment = new EnvironmentView();
    when(environmentViewService.getById(ENV_ID)).thenReturn(environment);
    underTest.accept(environmentDtoEvent);
    verify(sdxDeleteService).deleteSdxClustersForEnvironment(any(PollingConfig.class), eq(environment), eq(false));
    verify(eventSender).sendEvent(any(EnvDeleteEvent.class), eq(headers));
    verify(eventSender, never()).sendEvent(any(EnvClusterDeleteFailedEvent.class), any());
    EnvDeleteEvent capturedDeleteEvent = (EnvDeleteEvent) baseNamedFlowEvent.getValue();
    assertThat(capturedDeleteEvent.getResourceName()).isEqualTo(ENV_NAME);
    assertThat(capturedDeleteEvent.getResourceId()).isEqualTo(ENV_ID);
    assertThat(capturedDeleteEvent.getResourceCrn()).isEqualTo(RESOURCE_CRN);
    assertThat(capturedDeleteEvent.selector()).isEqualTo("FINISH_ENV_CLUSTERS_DELETE_EVENT");
}
Also used : EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) PollingConfig(com.sequenceiq.environment.util.PollingConfig) Test(org.junit.jupiter.api.Test)

Example 13 with EnvironmentView

use of com.sequenceiq.environment.environment.domain.EnvironmentView in project cloudbreak by hortonworks.

the class SdxDeleteServiceTest method deleteSdxClustersForEnvironmentWhenSdxIsEmptyButDatalakeNot.

@Test
void deleteSdxClustersForEnvironmentWhenSdxIsEmptyButDatalakeNot() {
    PollingConfig pollingConfig = getPollingConfig();
    EnvironmentView environment = getEnvironmentView();
    when(environmentResourceDeletionService.getAttachedSdxClusterCrns(environment)).thenReturn(emptySet());
    when(environmentResourceDeletionService.getDatalakeClusterNames(environment)).thenReturn(Set.of("name"));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(stackV4Endpoint.list(anyLong(), anyString(), anyBoolean())).thenReturn(new StackViewV4Responses());
    underTest.deleteSdxClustersForEnvironment(pollingConfig, environment, true);
    verify(stackV4Endpoint).deleteInternal(eq(0L), eq("name"), eq(true), nullable(String.class));
}
Also used : EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses) PollingConfig(com.sequenceiq.environment.util.PollingConfig) Test(org.junit.jupiter.api.Test)

Example 14 with EnvironmentView

use of com.sequenceiq.environment.environment.domain.EnvironmentView in project cloudbreak by hortonworks.

the class SdxDeleteServiceTest method deleteSdxClustersForEnvironment.

@Test
void deleteSdxClustersForEnvironment() {
    PollingConfig pollingConfig = getPollingConfig();
    EnvironmentView environment = getEnvironmentView();
    String sdxCrn1 = "crn:cdp:datalake:us-west-1:tenant:datalake:crn1";
    String sdxCrn2 = "crn:cdp:sdxsvc:us-west-1:tenant:instance:crn2";
    when(environmentResourceDeletionService.getAttachedSdxClusterCrns(environment)).thenReturn(Set.of(sdxCrn1, sdxCrn2));
    when(platformAwareSdxConnector.getAttemptResultForDeletion(any(), any(), any())).thenReturn(AttemptResults.finishWith(null));
    underTest.deleteSdxClustersForEnvironment(pollingConfig, environment, true);
    verify(platformAwareSdxConnector).delete(eq(sdxCrn1), eq(true));
    verify(platformAwareSdxConnector).delete(eq(sdxCrn2), eq(true));
    verifyNoMoreInteractions(platformAwareSdxConnector);
}
Also used : EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PollingConfig(com.sequenceiq.environment.util.PollingConfig) Test(org.junit.jupiter.api.Test)

Example 15 with EnvironmentView

use of com.sequenceiq.environment.environment.domain.EnvironmentView in project cloudbreak by hortonworks.

the class EnvironmentDeletionServiceTest method deleteMultipleByNames.

@Test
public void deleteMultipleByNames() {
    Set<String> names = Set.of("name1", "name2");
    EnvironmentView e1 = new EnvironmentView();
    e1.setId(0L);
    EnvironmentView e2 = new EnvironmentView();
    e2.setId(1L);
    Set<EnvironmentView> envs = Set.of(e1, e2);
    int expected = envs.size();
    EnvironmentDeletionService environmentDeletionServiceWired = spy(environmentDeletionService);
    when(environmentService.findByNamesInAccount(eq(names), eq(ACCOUNT_ID))).thenReturn(envs);
    assertEquals(expected, environmentDeletionServiceWired.deleteMultipleByNames(names, ACCOUNT_ID, USER, false, false).size());
    verify(environmentDeletionServiceWired, times(expected)).delete(any(), eq(USER), anyBoolean(), anyBoolean());
}
Also used : EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

EnvironmentView (com.sequenceiq.environment.environment.domain.EnvironmentView)19 Test (org.junit.jupiter.api.Test)12 PollingConfig (com.sequenceiq.environment.util.PollingConfig)6 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 EnvClusterDeleteFailedEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent)2 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 UserBreakException (com.dyngr.exception.UserBreakException)1 StackViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 ExceptionResponse (com.sequenceiq.cloudbreak.common.exception.ExceptionResponse)1 Environment (com.sequenceiq.environment.environment.domain.Environment)1 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 EnvironmentViewDto (com.sequenceiq.environment.environment.dto.EnvironmentViewDto)1 EnvironmentTestData.newTestEnvironment (com.sequenceiq.environment.environment.service.EnvironmentTestData.newTestEnvironment)1