use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class NetworkCreationHandlerTest method testHandleValidationFailure.
@Test
public void testHandleValidationFailure() {
EnvironmentDto environmentDto = createEnvironmentDto();
Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto);
AwsNetwork network = createNetwork();
Environment environment = createEnvironment(network);
Optional<Environment> environmentOptional = Optional.of(environment);
Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
when(environmentService.findEnvironmentById(any())).thenReturn(environmentOptional);
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
when(networkMetadataValidationService.getEndpointGatewaySubnetMetadata(any(), any())).thenThrow(new BadRequestException("failure"));
when(environmentResourceService.createAndSetNetwork(any(), any(), any(), any(), any())).thenReturn(network);
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.accept(environmentDtoEvent));
ArgumentCaptor<Event<EnvCreationFailureEvent>> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus, times(1)).notify(any(Object.class), eventCaptor.capture());
Event<EnvCreationFailureEvent> value = eventCaptor.getValue();
assertTrue(value.getData().getException() instanceof BadRequestException);
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class PublicKeyCreationHandlerTest method verifyEnvCreationFailedEvent.
private void verifyEnvCreationFailedEvent(Exception exceptionExpected) {
// BaseNamedFlowEvent event = baseNamedFlowEvent.getValue();
Event<EnvCreationFailureEvent> value = envCreationFailureEventEventCaptor.getValue();
EnvCreationFailureEvent event = value.getData();
assertThat(event).isInstanceOf(EnvCreationFailureEvent.class);
EnvCreationFailureEvent envCreateFailedEvent = (EnvCreationFailureEvent) event;
assertThat(envCreateFailedEvent.getResourceName()).isEqualTo(ENVIRONMENT_NAME);
assertThat(envCreateFailedEvent.getResourceCrn()).isEqualTo(ENVIRONMENT_CRN);
assertThat(envCreateFailedEvent.getResourceId()).isEqualTo(ENVIRONMENT_ID);
assertThat(envCreateFailedEvent.selector()).isEqualTo(FAILED_ENV_CREATION_EVENT.selector());
assertThat(envCreateFailedEvent.getException()).isSameAs(exceptionExpected);
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class ResourceEncryptionInitializationHandlerTest method verifyEnvCreationFailedEvent.
private void verifyEnvCreationFailedEvent(Exception exceptionExpected, boolean wrappedInCloudbreakServiceException, String messageCloudbreakServiceExceptionExpected) {
Event<EnvCreationFailureEvent> event = envCreationFailureEventEventCaptor.getValue();
EnvCreationFailureEvent envCreationFailureEvent = event.getData();
assertThat(envCreationFailureEvent.getResourceName()).isEqualTo(ENVIRONMENT_NAME);
assertThat(envCreationFailureEvent.getResourceCrn()).isEqualTo(ENVIRONMENT_CRN);
assertThat(envCreationFailureEvent.getResourceId()).isEqualTo(ENVIRONMENT_ID);
assertThat(envCreationFailureEvent.selector()).isEqualTo(FAILED_ENV_CREATION_EVENT.selector());
Exception exception = envCreationFailureEvent.getException();
if (wrappedInCloudbreakServiceException) {
assertThat(exception).isInstanceOf(CloudbreakServiceException.class);
assertThat(exception).hasMessage(messageCloudbreakServiceExceptionExpected);
assertThat(exception.getCause()).isSameAs(exceptionExpected);
} else {
assertThat(exception).isSameAs(exceptionExpected);
}
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class EnvCreationActionsTest method verifyCreationActionFailureEvent.
private void verifyCreationActionFailureEvent(String selector) {
assertThat(selectorArgumentCaptor.getValue()).isEqualTo(selector);
verifyEventFactoryAndHeaders();
Object payload = payloadArgumentCaptor.getValue();
assertThat(payload).isInstanceOf(EnvCreationFailureEvent.class);
EnvCreationFailureEvent failureEvent = (EnvCreationFailureEvent) payload;
assertThat(failureEvent.getResourceCrn()).isEqualTo(ENVIRONMENT_CRN);
assertThat(failureEvent.getResourceName()).isEqualTo(ENVIRONMENT_NAME);
assertThat(failureEvent.getResourceId()).isEqualTo(ENVIRONMENT_ID);
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class EnvironmentInitHandler method goToFailedState.
private void goToFailedState(Event<EnvironmentDto> environmentDtoEvent, String message) {
EnvironmentDto environmentDto = environmentDtoEvent.getData();
EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), new BadRequestException(message), environmentDto.getResourceCrn());
eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent));
}
Aggregations