Search in sources :

Example 56 with Description

use of com.sequenceiq.it.cloudbreak.context.Description 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 57 with Description

use of com.sequenceiq.it.cloudbreak.context.Description 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 58 with Description

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

the class ChangeImageCatalogTest method testChangeDataLakeImageCatalog.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "there is a running DataLake and image catalogs created by ENV_CREATOR_A", when = "a change image catalog request is sent to use an image catalog created by ENV_CREATOR_A", then = "ENV_CREATOR_A, ACCOUNT_ADMIN and ENV_CREATOR_B with shared resource user and environment admin right can perform the operation")
public void testChangeDataLakeImageCatalog(MockedTestContext testContext) {
    useRealUmsUser(testContext, AuthUserKeys.ENV_CREATOR_A);
    createDefaultImageCatalog(testContext);
    ImageCatalogTestDto imageCatalog1 = resourceCreator.createNewImageCatalog(testContext);
    ImageCatalogTestDto imageCatalog2 = resourceCreator.createNewImageCatalog(testContext);
    ImageCatalogTestDto imageCatalog3 = resourceCreator.createNewImageCatalog(testContext);
    // ENV_CREATOR_A can change DL image catalog in case of DL and target image catalog are created by ENV_CREATOR_A
    testContext.given(CredentialTestDto.class).when(credentialTestClient.create()).given(EnvironmentTestDto.class).when(environmentTestClient.create()).await(EnvironmentStatus.AVAILABLE).given(SdxInternalTestDto.class).when(sdxTestClient.createInternal()).await(SdxClusterStatusResponse.RUNNING).when(sdxTestClient.detailedDescribeInternal()).given(SdxChangeImageCatalogTestDto.class).withImageCatalog(imageCatalog1.getName()).when(sdxTestClient.changeImageCatalog()).validate();
    // ACCOUNT_ADMIN can change DL image catalog in case of DL and target image catalog are created by ENV_CREATOR_A
    useRealUmsUser(testContext, AuthUserKeys.ACCOUNT_ADMIN);
    testContext.given(SdxChangeImageCatalogTestDto.class).withImageCatalog(imageCatalog2.getName()).when(sdxTestClient.changeImageCatalog()).validate();
    // ENV_CREATOR_B can change DL image catalog in case of DL and target image catalog are created by ENV_CREATOR_A and
    // ENV_CREATOR_B has environment admin right in terms of the environment created by ENV_CREATOR_A and
    // ENV_CREATOR_B has shared resource right in terms of the image catalog created by ENV_CREATOR_A
    useRealUmsUser(testContext, AuthUserKeys.ENV_CREATOR_B);
    testContext.given(UmsTestDto.class).assignTarget(EnvironmentTestDto.class.getSimpleName()).withEnvironmentAdmin().when(umsTestClient.assignResourceRole(AuthUserKeys.ENV_CREATOR_B, regionAwareInternalCrnGeneratorFactory)).given(UmsTestDto.class).assignTarget(imageCatalog3.getName()).withSharedResourceUser().when(umsTestClient.assignResourceRole(AuthUserKeys.ENV_CREATOR_B, regionAwareInternalCrnGeneratorFactory)).given(SdxChangeImageCatalogTestDto.class).withImageCatalog(imageCatalog3.getName()).when(sdxTestClient.changeImageCatalog()).validate();
}
Also used : EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) FreeipaChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeipaChangeImageCatalogTestDto) DistroXChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXChangeImageCatalogTestDto) SdxChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxChangeImageCatalogTestDto) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) SdxChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxChangeImageCatalogTestDto) UmsTestDto(com.sequenceiq.it.cloudbreak.dto.ums.UmsTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractIntegrationTest(com.sequenceiq.it.cloudbreak.testcase.AbstractIntegrationTest)

Example 59 with Description

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

the class ChangeImageCatalogTest method testChangeDataHubImageCatalog.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "there is a running DataHub and image catalogs created by ENV_CREATOR_A", when = "a change image catalog request is sent to use an image catalog created by ENV_CREATOR_A", then = "ENV_CREATOR_A, ACCOUNT_ADMIN and ENV_CREATOR_B with shared resource user and environment admin rights can perform the operation")
public void testChangeDataHubImageCatalog(MockedTestContext testContext) {
    useRealUmsUser(testContext, AuthUserKeys.ENV_CREATOR_A);
    createDefaultImageCatalog(testContext);
    ImageCatalogTestDto imageCatalog1 = resourceCreator.createNewImageCatalog(testContext);
    ImageCatalogTestDto imageCatalog2 = resourceCreator.createNewImageCatalog(testContext);
    ImageCatalogTestDto imageCatalog3 = resourceCreator.createNewImageCatalog(testContext);
    // ENV_CREATOR_A can change DH image catalog in case of DH and target image catalog are created by ENV_CREATOR_A
    testContext.given(CredentialTestDto.class).when(credentialTestClient.create()).given(EnvironmentTestDto.class).when(environmentTestClient.create()).await(EnvironmentStatus.AVAILABLE).given(FreeIpaTestDto.class).when(freeIpaTestClient.create()).await(Status.AVAILABLE).given(SdxInternalTestDto.class).when(sdxTestClient.createInternal()).await(SdxClusterStatusResponse.RUNNING).when(sdxTestClient.detailedDescribeInternal()).given(DistroXTestDto.class).when(distroXClient.create()).await(STACK_AVAILABLE, RunningParameter.who(cloudbreakActor.useRealUmsUser(AuthUserKeys.ACCOUNT_ADMIN))).given(DistroXChangeImageCatalogTestDto.class).withImageCatalog(imageCatalog1.getName()).when(distroXClient.changeImageCatalog()).validate();
    // ENV_CREATOR_B can change DH image catalog in case of DH and target image catalog are created by ENV_CREATOR_A and
    // ENV_CREATOR_B has environment admin right in terms of the environment created by ENV_CREATOR_A and
    // ENV_CREATOR_B has shared resource right in terms of the image catalog created by ENV_CREATOR_A
    useRealUmsUser(testContext, AuthUserKeys.ENV_CREATOR_B);
    testContext.given(UmsTestDto.class).assignTarget(imageCatalog2.getName()).withSharedResourceUser().when(umsTestClient.assignResourceRole(AuthUserKeys.ENV_CREATOR_B, regionAwareInternalCrnGeneratorFactory)).given(UmsTestDto.class).assignTarget(EnvironmentTestDto.class.getSimpleName()).withEnvironmentAdmin().when(umsTestClient.assignResourceRole(AuthUserKeys.ENV_CREATOR_B, regionAwareInternalCrnGeneratorFactory)).given(DistroXChangeImageCatalogTestDto.class).withImageCatalog(imageCatalog2.getName()).when(distroXClient.changeImageCatalog()).validate();
    // ACCOUNT_ADMIN can change DH image catalog in case of DH and target image catalog are created by ENV_CREATOR_A
    useRealUmsUser(testContext, AuthUserKeys.ACCOUNT_ADMIN);
    testContext.given(DistroXChangeImageCatalogTestDto.class).withImageCatalog(imageCatalog3.getName()).when(distroXClient.changeImageCatalog()).validate();
}
Also used : EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) FreeipaChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeipaChangeImageCatalogTestDto) DistroXChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXChangeImageCatalogTestDto) SdxChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxChangeImageCatalogTestDto) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) UmsTestDto(com.sequenceiq.it.cloudbreak.dto.ums.UmsTestDto) DistroXChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXChangeImageCatalogTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractIntegrationTest(com.sequenceiq.it.cloudbreak.testcase.AbstractIntegrationTest)

Example 60 with Description

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

the class CreateDhWithDatahubCreator method testCreateEnvironmentWithDh.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "there is a running env service", when = "valid create environment request is sent and then datahub is created", then = "environment should be created but unauthorized users should not be able to access it")
public void testCreateEnvironmentWithDh(TestContext testContext) {
    useRealUmsUser(testContext, AuthUserKeys.ENV_CREATOR_A);
    testContext.given(CredentialTestDto.class).when(credentialTestClient.create()).given(EnvironmentTestDto.class).withCreateFreeIpa(false).when(environmentTestClient.create()).await(EnvironmentStatus.AVAILABLE).whenException(environmentTestClient.describe(), ForbiddenException.class, expectedMessage("Doesn't have 'environments/describeEnvironment' right on environment " + environmentPattern(testContext)).withWho(cloudbreakActor.useRealUmsUser(AuthUserKeys.ENV_CREATOR_B))).whenException(environmentTestClient.describe(), ForbiddenException.class, expectedMessage("Doesn't have 'environments/describeEnvironment' right on environment " + environmentPattern(testContext)).withWho(cloudbreakActor.useRealUmsUser(AuthUserKeys.ZERO_RIGHTS))).validate();
    useRealUmsUser(testContext, AuthUserKeys.ENV_CREATOR_A);
    EnvironmentTestDto environment = testContext.get(EnvironmentTestDto.class);
    resourceCreator.createNewFreeIpa(testContext, environment);
    createDatalake(testContext);
    String recipe1Name = testContext.given(RecipeTestDto.class).valid().when(recipeTestClient.createV4(), RunningParameter.who(cloudbreakActor.useRealUmsUser(AuthUserKeys.ACCOUNT_ADMIN))).getResponse().getName();
    String recipe2Name = testContext.given(RecipeTestDto.class).valid().when(recipeTestClient.createV4(), RunningParameter.who(cloudbreakActor.useRealUmsUser(AuthUserKeys.ENV_CREATOR_B))).getResponse().getName();
    testContext.given(EnvironmentTestDto.class).given(UmsTestDto.class).assignTarget(EnvironmentTestDto.class.getSimpleName()).withDatahubCreator().when(umsTestClient.assignResourceRole(AuthUserKeys.ENV_CREATOR_B, regionAwareInternalCrnGeneratorFactory)).withEnvironmentUser().when(umsTestClient.assignResourceRole(AuthUserKeys.ENV_CREATOR_B, regionAwareInternalCrnGeneratorFactory)).given(EnvironmentTestDto.class).given(DistroXTestDto.class).withRecipe(recipe1Name).whenException(distroXClient.create(), ForbiddenException.class, expectedMessage("Doesn't have 'environments/useSharedResource' right on" + " recipe " + datahubRecipePattern(recipe1Name)).withWho(cloudbreakActor.useRealUmsUser(AuthUserKeys.ENV_CREATOR_B))).withRecipe(recipe2Name).when(distroXClient.create(), RunningParameter.who(cloudbreakActor.useRealUmsUser(AuthUserKeys.ENV_CREATOR_B))).await(STACK_AVAILABLE, RunningParameter.who(cloudbreakActor.useRealUmsUser(AuthUserKeys.ACCOUNT_ADMIN))).given(RenewDistroXCertificateTestDto.class).whenException(distroXClient.renewDistroXCertificateV4(), ForbiddenException.class, expectedMessage("Doesn't have 'datahub/repairDatahub'" + " right on any of the " + environmentDatahubPattern(testContext) + " or on " + datahubPattern(testContext)).withWho(cloudbreakActor.useRealUmsUser(AuthUserKeys.ZERO_RIGHTS))).validate();
    testCheckRightUtil(testContext, testContext.given(DistroXTestDto.class).getCrn());
}
Also used : EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) ForbiddenException(javax.ws.rs.ForbiddenException) UmsTestDto(com.sequenceiq.it.cloudbreak.dto.ums.UmsTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractIntegrationTest(com.sequenceiq.it.cloudbreak.testcase.AbstractIntegrationTest)

Aggregations

Description (com.sequenceiq.it.cloudbreak.context.Description)72 Test (org.testng.annotations.Test)71 EnvironmentTestDto (com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto)30 Inject (javax.inject.Inject)30 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)29 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)24 AbstractE2ETest (com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest)22 RunningParameter.key (com.sequenceiq.it.cloudbreak.context.RunningParameter.key)19 UseSpotInstances (com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances)19 SdxTestClient (com.sequenceiq.it.cloudbreak.client.SdxTestClient)17 SdxInternalTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto)17 FreeIpaTestDto (com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto)16 SdxClusterStatusResponse (com.sequenceiq.sdx.api.model.SdxClusterStatusResponse)16 SdxDatabaseRequest (com.sequenceiq.sdx.api.model.SdxDatabaseRequest)15 EnvironmentNetworkTestDto (com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentNetworkTestDto)14 List (java.util.List)14 ImageCatalogTestDto (com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto)13 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)13 AbstractIntegrationTest (com.sequenceiq.it.cloudbreak.testcase.AbstractIntegrationTest)13 DistroXTestClient (com.sequenceiq.it.cloudbreak.client.DistroXTestClient)12