Search in sources :

Example 71 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class FreeIpaScalingValidationServiceTest method testDownscaleIfInvalidInstancesExistsThenValidationFails.

@Test
public void testDownscaleIfInvalidInstancesExistsThenValidationFails() {
    Stack stack = mock(Stack.class);
    BadRequestException exception = assertThrows(BadRequestException.class, () -> underTest.validateStackForDownscale(createValidImSet(2), stack, null));
    assertEquals("Downscaling currently only available for FreeIPA installation with 3 instances", exception.getMessage());
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 72 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class FreeIpaScalingValidationServiceTest method testUpscaleIfMoreInstancesExistsThenValidationFails.

@Test
public void testUpscaleIfMoreInstancesExistsThenValidationFails() {
    Stack stack = mock(Stack.class);
    BadRequestException exception = assertThrows(BadRequestException.class, () -> underTest.validateStackForUpscale(createValidImSet(4), stack, null));
    assertEquals("Upscaling currently only available for FreeIPA installation with 1 or 2 instances", exception.getMessage());
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 73 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class FreeIpaRecommendationServiceTest method testValidateCustomInstanceTypeWhenEntitlementIsNotEnabled.

@Test
public void testValidateCustomInstanceTypeWhenEntitlementIsNotEnabled() {
    when(defaultInstanceTypeProvider.getForPlatform(eq("AWS"))).thenReturn("medium");
    when(entitlementService.isFreeIpaSelectInstanceTypeEnabled(anyString())).thenReturn(Boolean.FALSE);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.validateCustomInstanceType(createStack("large"), new Credential("AWS", "Cred", null, "crn", "account")));
    assertEquals("Custom instance type for FreeIPA is not enabled!", badRequestException.getMessage());
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 74 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class FreeIpaScalingServiceTest method testUpscaleIfValidationFailsThenErrorThrown.

@Test
public void testUpscaleIfValidationFailsThenErrorThrown() {
    Stack stack = mock(Stack.class);
    Set<InstanceMetaData> allInstances = createValidImSet();
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    UpscaleRequest request = createUpscaleRequest();
    doThrow(new BadRequestException("validation failed")).when(validationService).validateStackForUpscale(allInstances, stack, new ScalingPath(AvailabilityType.TWO_NODE_BASED, AvailabilityType.HA));
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.upscale(ACCOUNT_ID, request));
    assertEquals(exception.getMessage(), "validation failed");
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ScalingPath(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath) UpscaleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 75 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class FreeIpaPasswordValidatorTest method testValidateShouldThrowExceptionWhenThePasswordIsTooLong.

@Test
void testValidateShouldThrowExceptionWhenThePasswordIsTooLong() {
    String password = "123456789123456789";
    BadRequestException exception = assertThrows(BadRequestException.class, () -> underTest.validate(password));
    assertEquals("Password must be between minimum 8 and maximum 16 characters.", exception.getMessage());
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)298 Test (org.junit.jupiter.api.Test)134 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)34 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)26 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)22 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)21 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Stack (com.sequenceiq.freeipa.entity.Stack)18 BaseDiagnosticsCollectionRequest (com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest)14 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)14 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)14 Set (java.util.Set)14 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)13 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)12 Json (com.sequenceiq.cloudbreak.common.json.Json)12 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)12