Search in sources :

Example 36 with TestContext

use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.

the class EnvironmentEditTest method authenticationEditWhenSetManagedKeyAndNotDeleteExisted.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "there is a running cloudbreak with existed ssh key", when = "change existing ssh key to managed one", then = "delete managed ssh key but not create new one")
public void authenticationEditWhenSetManagedKeyAndNotDeleteExisted(MockedTestContext testContext) {
    String randomPublicKeyId = UUID.randomUUID().toString();
    testContext.given(EnvironmentAuthenticationTestDto.class).withPublicKeyId(randomPublicKeyId).withPublicKey(null).given(EnvironmentTestDto.class).withCreateFreeIpa(false).when(environmentTestClient.create()).await(EnvironmentStatus.AVAILABLE).given(EnvironmentAuthenticationTestDto.class).withPublicKey(PUBLIC_KEY).withPublicKeyId(null).given(EnvironmentTestDto.class).when(environmentTestClient.changeAuthentication()).when(environmentTestClient.describe()).then((tc, t, c) -> {
        String publicKeyId = t.getResponse().getAuthentication().getPublicKeyId();
        String publicKey = t.getResponse().getAuthentication().getPublicKey();
        if (randomPublicKeyId.equals(publicKeyId)) {
            throw new TestFailException("The auth public key id was not changed, but it should be changed");
        }
        if (publicKey == null) {
            throw new TestFailException("The auth public key should not be null");
        }
        return t;
    }).validate();
}
Also used : MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) Test(org.testng.annotations.Test) HttpMock(com.sequenceiq.it.cloudbreak.dto.mock.HttpMock) UUID(java.util.UUID) EnvironmentSecurityAccessTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentSecurityAccessTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) EnvironmentAuthenticationTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentAuthenticationTestDto) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) BadRequestException(javax.ws.rs.BadRequestException) RunningParameter.expectedMessage(com.sequenceiq.it.cloudbreak.context.RunningParameter.expectedMessage) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) EnvironmentAuthenticationTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentAuthenticationTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Example 37 with TestContext

use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.

the class AbstractMinimalTest method collectTestCaseDescription.

private TestCaseDescription collectTestCaseDescription(TestContext testContext, Method method, Object[] params) {
    Description declaredAnnotation = method.getDeclaredAnnotation(Description.class);
    TestCaseDescription testCaseDescription = null;
    if (declaredAnnotation != null) {
        testCaseDescription = new TestCaseDescriptionBuilder().given(declaredAnnotation.given()).when(declaredAnnotation.when()).then(declaredAnnotation.then());
        testContext.addDescription(testCaseDescription);
    } else if (method.getParameters().length == params.length) {
        Parameter[] parameters = method.getParameters();
        for (int i = 1; i < parameters.length; i++) {
            if (parameters[i].getAnnotation(Description.class) != null) {
                Object param = params[i];
                if (!(param instanceof TestCaseDescription)) {
                    throw new IllegalArgumentException("The param annotated with @Description but the type is should be " + TestCaseDescription.class.getSimpleName());
                }
                testCaseDescription = (TestCaseDescription) param;
                testContext.addDescription(testCaseDescription);
                break;
            }
        }
    }
    return Optional.ofNullable(testCaseDescription).filter(d -> !Strings.isNullOrEmpty(d.getValue())).orElseThrow(() -> new TestCaseDescriptionMissingException(method.getName()));
}
Also used : BeforeSuite(org.testng.annotations.BeforeSuite) DataProvider(org.testng.annotations.DataProvider) E2ETestContext(com.sequenceiq.it.cloudbreak.context.E2ETestContext) LoggerFactory(org.slf4j.LoggerFactory) AfterMethod(org.testng.annotations.AfterMethod) TracerAutoConfiguration(io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration) ITestResult(org.testng.ITestResult) IntegrationTestConfiguration(com.sequenceiq.it.config.IntegrationTestConfiguration) Description(com.sequenceiq.it.cloudbreak.context.Description) TestCaseDescriptionBuilder(com.sequenceiq.it.cloudbreak.context.TestCaseDescription.TestCaseDescriptionBuilder) AuditBeanConfig(com.sequenceiq.it.config.AuditBeanConfig) LongStringGeneratorUtil(com.sequenceiq.it.util.LongStringGeneratorUtil) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) ConfigFileApplicationContextInitializer(org.springframework.boot.test.context.ConfigFileApplicationContextInitializer) Parameter(java.lang.reflect.Parameter) Map(java.util.Map) PurgeGarbageService(com.sequenceiq.it.cloudbreak.context.PurgeGarbageService) CommonCloudProperties(com.sequenceiq.it.cloudbreak.cloud.v4.CommonCloudProperties) ThreadLocalProfiles(com.sequenceiq.it.cloudbreak.mock.ThreadLocalProfiles) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription) Method(java.lang.reflect.Method) MeasuredTestContext.createMeasuredTestContext(com.sequenceiq.it.cloudbreak.context.MeasuredTestContext.createMeasuredTestContext) AbstractTestNGSpringContextTests(org.springframework.test.context.testng.AbstractTestNGSpringContextTests) ResourcePropertyProvider(com.sequenceiq.it.cloudbreak.ResourcePropertyProvider) MeasuredTestContext(com.sequenceiq.it.cloudbreak.context.MeasuredTestContext) AfterClass(org.testng.annotations.AfterClass) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) TestCaseDescriptionMissingException(com.sequenceiq.it.cloudbreak.exception.TestCaseDescriptionMissingException) ITestContext(org.testng.ITestContext) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) BeansException(org.springframework.beans.BeansException) CommonClusterManagerProperties(com.sequenceiq.it.cloudbreak.cloud.v4.CommonClusterManagerProperties) MDC(org.slf4j.MDC) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Optional(java.util.Optional) TestCaseDescriptionMissingException(com.sequenceiq.it.cloudbreak.exception.TestCaseDescriptionMissingException) Description(com.sequenceiq.it.cloudbreak.context.Description) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription) TestCaseDescriptionBuilder(com.sequenceiq.it.cloudbreak.context.TestCaseDescription.TestCaseDescriptionBuilder) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription)

Example 38 with TestContext

use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.

the class AbstractImageValidatorE2ETest method validateImageIdAndWriteToFile.

@AfterMethod
public void validateImageIdAndWriteToFile(Object[] data, ITestResult result) {
    TestContext testContext = (TestContext) data[0];
    if (result.getStatus() == ITestResult.SUCCESS) {
        String expectedImageUuid = commonCloudProperties().getImageValidation().getImageUuid();
        String actualImageUuid = getImageId(testContext);
        if (Strings.isNotNullAndNotEmpty(expectedImageUuid) && !expectedImageUuid.equalsIgnoreCase(actualImageUuid)) {
            throw new RuntimeException("The test was successful but the image is not the expected one. Actual: " + actualImageUuid + " Expected: " + expectedImageUuid);
        }
        LOG.info("The test was successful with this image:  " + actualImageUuid);
        writeImageIdToFile(testContext);
    }
}
Also used : TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) AfterMethod(org.testng.annotations.AfterMethod)

Example 39 with TestContext

use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.

the class DistroXScaleTest method testCreateAndScaleDistroX.

@Test(dataProvider = TEST_CONTEXT, description = "Resilient Scaling: " + "UseCase1: " + "- Start upscale on running cluster " + "- Delete a non CM server host from provider other hostgroup during upscale " + "- Upscale should complete ")
@Description(given = "there is a running default Distrox cluster", when = "deleted a Compute instance while cluster was upscaling (by Worker nodes)", then = "cluster can be resiliently scaled up then down with higher node count")
public void testCreateAndScaleDistroX(TestContext testContext, ITestContext iTestContext) {
    DistroXScaleTestParameters params = new DistroXScaleTestParameters(iTestContext.getCurrentXmlTest().getAllParameters());
    if (params.getTimes() < 1) {
        throw new TestFailException("Test should execute at least 1 round of scaling");
    }
    StringBuilder instanceToStopId = new StringBuilder();
    testContext.given(DistroXTestDto.class).then((tc, testDto, client) -> {
        CloudFunctionality cloudFunctionality = tc.getCloudProvider().getCloudFunctionality();
        Optional<String> anInstanceToStop = distroxUtil.getInstanceIds(testDto, client, params.getHostGroup()).stream().findFirst();
        if (anInstanceToStop.isEmpty()) {
            throw new TestFailException(String.format("At least 1 instance needed from group %s to test stop it and test targeted upscale.", params.getIrrelevantHostGroup()));
        }
        cloudFunctionality.stopInstances(testDto.getName(), List.of(anInstanceToStop.get()));
        instanceToStopId.append(anInstanceToStop.get());
        return testDto;
    }).await(STACK_NODE_FAILURE).when(distroXTestClient.scale(params.getHostGroup(), params.getScaleUpTarget())).then((tc, testDto, client) -> {
        CloudFunctionality cloudFunctionality = tc.getCloudProvider().getCloudFunctionality();
        Optional<String> anInstanceToDelete = distroxUtil.getInstanceIds(testDto, client, params.getIrrelevantHostGroup()).stream().findFirst();
        if (anInstanceToDelete.isEmpty()) {
            throw new TestFailException(String.format("At least 1 instance needed from group %s to test delete it and test targeted upscale.", params.getIrrelevantHostGroup()));
        }
        cloudFunctionality.deleteInstances(testDto.getName(), List.of(anInstanceToDelete.get()));
        testDto.setInstanceIdsForActions(List.of(anInstanceToDelete.get()));
        return testDto;
    }).awaitForFlow().awaitForActionedInstances(DELETED_ON_PROVIDER_SIDE).then((tc, testDto, client) -> {
        testDto.setInstanceIdsForActions(mergeInstanceIdList(testDto.getInstanceIdsForAction(), instanceToStopId.toString()));
        return testDto;
    }).when(distroXTestClient.removeInstances()).awaitForFlow().when(distroXTestClient.scale(params.getHostGroup(), params.getScaleDownTarget())).awaitForFlow().validate();
    IntStream.range(1, params.getTimes()).forEach(i -> testContext.given(DistroXTestDto.class).when(distroXTestClient.scale(params.getHostGroup(), params.getScaleUpTarget())).awaitForFlow().when(distroXTestClient.scale(params.getHostGroup(), params.getScaleDownTarget())).awaitForFlow().validate());
}
Also used : IntStream(java.util.stream.IntStream) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ITestContext(org.testng.ITestContext) Test(org.testng.annotations.Test) DELETED_ON_PROVIDER_SIDE(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DELETED_ON_PROVIDER_SIDE) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) ArrayList(java.util.ArrayList) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) List(java.util.List) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) DistroxUtil(com.sequenceiq.it.cloudbreak.util.DistroxUtil) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CloudFunctionality(com.sequenceiq.it.cloudbreak.util.CloudFunctionality) Optional(java.util.Optional) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) Optional(java.util.Optional) CloudFunctionality(com.sequenceiq.it.cloudbreak.util.CloudFunctionality) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest)

Example 40 with TestContext

use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.

the class DistroXStopStartScaleTest method testStopStartScaleDistroX.

/**
 * The "Scaling" via Instance Stop/Start for DataHub ‘compute’ nodes (NodeManagers only) improves scaling performance
 * - at best, 4-6 minutes for a single node.
 *
 * @param testContext   Spring offers ApplicationContextAware interface to provide configuration of the Integration Test ApplicationContext.
 * @param iTestContext  TestNG offers the ITestContext interface to store and share test objects through test execution.
 */
@Test(dataProvider = TEST_CONTEXT)
@Description(given = "there is a running default Distrox cluster", when = "cluster has been scaled successfully by 4 compute nodes", then = "cluster compute nodes can be scaled down then up via stop then start instances at provider")
public void testStopStartScaleDistroX(TestContext testContext, ITestContext iTestContext) {
    AtomicReference<List<String>> instancesToStop = new AtomicReference<>();
    DistroXScaleTestParameters params = new DistroXScaleTestParameters(iTestContext.getCurrentXmlTest().getAllParameters());
    if (params.getTimes() < 1) {
        throw new TestFailException("Test should execute at least 1 round of scaling");
    }
    testContext.given(DistroXTestDto.class).when(distroXTestClient.scale(params.getHostGroup(), params.getScaleUpTarget())).awaitForFlow().then((tc, testDto, client) -> {
        instancesToStop.set(distroxUtil.getInstanceIds(testDto, client, params.getHostGroup()).stream().limit(params.getScaleDownTarget()).collect(Collectors.toList()));
        testDto.setInstanceIdsForActions(instancesToStop.get());
        return testDto;
    }).when(distroXTestClient.scaleStopInstances()).awaitForFlow().then(new DistroxStopStartScaleDurationAssertions(6, false)).when(distroXTestClient.scaleStartInstances(params.getHostGroup(), params.getScaleUpTarget())).awaitForFlow().when(distroXTestClient.get()).then(new DistroxStopStartScaleDurationAssertions(6, true));
    IntStream.range(1, params.getTimes()).forEach(i -> {
        testContext.given(DistroXTestDto.class).when(distroXTestClient.scaleStopInstances()).awaitForFlow().then(new DistroxStopStartScaleDurationAssertions(6, false)).when(distroXTestClient.scaleStartInstances(params.getHostGroup(), params.getScaleUpTarget())).awaitForFlow().when(distroXTestClient.get()).then(new DistroxStopStartScaleDurationAssertions(6, true));
    });
    testContext.given(DistroXTestDto.class).validate();
}
Also used : IntStream(java.util.stream.IntStream) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ITestContext(org.testng.ITestContext) DistroxStopStartScaleDurationAssertions(com.sequenceiq.it.cloudbreak.assertion.distrox.DistroxStopStartScaleDurationAssertions) Test(org.testng.annotations.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) List(java.util.List) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) DistroxUtil(com.sequenceiq.it.cloudbreak.util.DistroxUtil) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) DistroxStopStartScaleDurationAssertions(com.sequenceiq.it.cloudbreak.assertion.distrox.DistroxStopStartScaleDurationAssertions) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest)

Aggregations

TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)45 Test (org.testng.annotations.Test)38 Description (com.sequenceiq.it.cloudbreak.context.Description)32 Inject (javax.inject.Inject)32 RunningParameter.key (com.sequenceiq.it.cloudbreak.context.RunningParameter.key)20 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)20 SdxTestClient (com.sequenceiq.it.cloudbreak.client.SdxTestClient)18 MockedTestContext (com.sequenceiq.it.cloudbreak.context.MockedTestContext)18 UseSpotInstances (com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances)17 SdxClusterStatusResponse (com.sequenceiq.sdx.api.model.SdxClusterStatusResponse)17 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)15 List (java.util.List)15 AbstractE2ETest (com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest)14 DistroXTestClient (com.sequenceiq.it.cloudbreak.client.DistroXTestClient)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 EnvironmentTestDto (com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto)12 SdxTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto)12 SdxDatabaseRequest (com.sequenceiq.sdx.api.model.SdxDatabaseRequest)11 EnvironmentTestClient (com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient)10