Search in sources :

Example 1 with MockedTestContext

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

the class AbstractMinimalTest method testContextWithMock.

@DataProvider(name = TEST_CONTEXT_WITH_MOCK)
public Object[][] testContextWithMock() {
    MockedTestContext testContext = getBean(MockedTestContext.class);
    MeasuredTestContext tc = createMeasuredTestContext(testContext);
    return new Object[][] { { tc } };
}
Also used : MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) MeasuredTestContext.createMeasuredTestContext(com.sequenceiq.it.cloudbreak.context.MeasuredTestContext.createMeasuredTestContext) MeasuredTestContext(com.sequenceiq.it.cloudbreak.context.MeasuredTestContext) DataProvider(org.testng.annotations.DataProvider)

Example 2 with MockedTestContext

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

the class MultiThreadTenantTest method collectTestCaseDescription.

private TestCaseDescription collectTestCaseDescription(MockedTestContext 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 : ImageCatalogTestClient(com.sequenceiq.it.cloudbreak.client.ImageCatalogTestClient) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) LoggerFactory(org.slf4j.LoggerFactory) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) IntegrationTestConfiguration(com.sequenceiq.it.config.IntegrationTestConfiguration) Description(com.sequenceiq.it.cloudbreak.context.Description) EnvironmentNetworkTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentNetworkTestDto) Map(java.util.Map) ThreadLocalProfiles(com.sequenceiq.it.cloudbreak.mock.ThreadLocalProfiles) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription) Method(java.lang.reflect.Method) AbstractTestNGSpringContextTests(org.springframework.test.context.testng.AbstractTestNGSpringContextTests) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestCaseDescriptionMissingException(com.sequenceiq.it.cloudbreak.exception.TestCaseDescriptionMissingException) BeforeMethod(org.testng.annotations.BeforeMethod) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) Optional(java.util.Optional) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) BlueprintTestDto(com.sequenceiq.it.cloudbreak.dto.blueprint.BlueprintTestDto) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) ImageCatalogCreateRetryAction(com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogCreateRetryAction) CredentialTestDto(com.sequenceiq.it.cloudbreak.dto.credential.CredentialTestDto) DataProvider(org.testng.annotations.DataProvider) TracerAutoConfiguration(io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration) ITestResult(org.testng.ITestResult) TestCaseDescriptionBuilder(com.sequenceiq.it.cloudbreak.context.TestCaseDescription.TestCaseDescriptionBuilder) Inject(javax.inject.Inject) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) Strings(com.google.common.base.Strings) ConfigFileApplicationContextInitializer(org.springframework.boot.test.context.ConfigFileApplicationContextInitializer) Parameter(java.lang.reflect.Parameter) CredentialTestClient(com.sequenceiq.it.cloudbreak.client.CredentialTestClient) ResourcePropertyProvider(com.sequenceiq.it.cloudbreak.ResourcePropertyProvider) AfterClass(org.testng.annotations.AfterClass) BlueprintTestClient(com.sequenceiq.it.cloudbreak.client.BlueprintTestClient) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) BeansException(org.springframework.beans.BeansException) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) CloudbreakActor(com.sequenceiq.it.cloudbreak.actor.CloudbreakActor) MDC(org.slf4j.MDC) ContextConfiguration(org.springframework.test.context.ContextConfiguration) 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 3 with MockedTestContext

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

the class MultiThreadTenantTest method beforeTest.

@BeforeMethod
public void beforeTest(Method method, Object[] params) {
    MDC.put("testlabel", method.getDeclaringClass().getSimpleName() + '.' + method.getName());
    MockedTestContext testContext = (MockedTestContext) params[0];
    testContext.setTestMethodName(method.getName());
    collectTestCaseDescription(testContext, method, params);
}
Also used : MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with MockedTestContext

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

the class ImageCatalogChangeTest method testFreeipaImageCatalogChange.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "a running Freeipa/Datalake/Datahub", when = "calling change image catalog", then = "it should have new image catalog")
public void testFreeipaImageCatalogChange(MockedTestContext testContext) {
    // Freeipa
    final String newImageCatalog = testContext.given(FreeIpaTestDto.class).getResponse().getImage().getCatalog() + "&changed=true";
    testContext.given(FreeipaChangeImageCatalogTestDto.class).withImageCatalog(newImageCatalog).when(freeIpaTestClient.changeImageCatalog()).given(FreeIpaTestDto.class).when(freeIpaTestClient.describe()).then((testContext1, testDto, client) -> {
        final String actualCatalog = testDto.getResponse().getImage().getCatalog();
        if (!newImageCatalog.equals(actualCatalog)) {
            throw new TestFailException(String.format("Image catalog of Freeipa was not changed. Catalog : %s", actualCatalog));
        }
        return testDto;
    });
    // Datalake
    testContext.given(SdxInternalTestDto.class).when(sdxTestClient.createInternal()).await(SdxClusterStatusResponse.RUNNING);
    final StackImageV4Response sdxImage = testContext.given(SdxInternalTestDto.class).getResponse().getStackV4Response().getImage();
    final String sdxNewImageCatalogName = createNewImageCatalog(testContext, sdxImage);
    testContext.given(SdxChangeImageCatalogTestDto.class).withImageCatalog(sdxNewImageCatalogName).when(sdxTestClient.changeImageCatalog()).given(SdxInternalTestDto.class).when(sdxTestClient.describeInternal()).then((testContext1, testDto, client) -> {
        final String actualCatalog = testDto.getResponse().getStackV4Response().getImage().getCatalogName();
        if (!sdxNewImageCatalogName.equals(actualCatalog)) {
            throw new TestFailException(String.format("Image catalog of Datalake was not changed. Catalog : %s", actualCatalog));
        }
        return testDto;
    });
    // Datahub
    testContext.given(DistroXTestDto.class).when(distroXClient.create()).await(STACK_AVAILABLE);
    final StackImageV4Response distroXImage = testContext.given(DistroXTestDto.class).getResponse().getImage();
    final String distroXNewImageCatalogName = createNewImageCatalog(testContext, distroXImage);
    testContext.given(DistroXChangeImageCatalogTestDto.class).withImageCatalog(distroXNewImageCatalogName).when(distroXClient.changeImageCatalog()).given(DistroXTestDto.class).when(distroXClient.get()).then((testContext1, testDto, client) -> {
        final String actualCatalog = testDto.getResponse().getImage().getCatalogName();
        if (!distroXNewImageCatalogName.equals(actualCatalog)) {
            throw new TestFailException(String.format("Image catalog of Datahub was not changed. Catalog : %s", actualCatalog));
        }
        return testDto;
    }).validate();
}
Also used : ImageCatalogTestClient(com.sequenceiq.it.cloudbreak.client.ImageCatalogTestClient) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) FreeipaChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeipaChangeImageCatalogTestDto) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) Test(org.testng.annotations.Test) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response) DistroXChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXChangeImageCatalogTestDto) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) SdxChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxChangeImageCatalogTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) NotNull(org.jetbrains.annotations.NotNull) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) FreeipaChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeipaChangeImageCatalogTestDto) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response) SdxChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxChangeImageCatalogTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Example 5 with MockedTestContext

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

the class ImageCatalogTest method testGetImageCatalogWhenCatalogDoesNotContainTheRequestedProvider.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "image catalog get the default catalog with AWS provider but catalog does not contain AWS entry", when = "calling get on the default", then = "the response does not contains AWS images")
public void testGetImageCatalogWhenCatalogDoesNotContainTheRequestedProvider(MockedTestContext testContext) {
    String imgCatalogName = resourcePropertyProvider().getName();
    testContext.given(imgCatalogName, ImageCatalogTestDto.class).withName(imgCatalogName).withUrl(getImageCatalogMockServerSetup().getImageCatalogUrl()).when(imageCatalogTestClient.createV4(), key(imgCatalogName)).when(new ImageCatalogGetImagesByNameAction(CloudPlatform.AWS), key(imgCatalogName)).then((testContext1, entity, cloudbreakClient) -> {
        ImagesV4Response catalog = entity.getResponseByProvider();
        if (!catalog.getBaseImages().isEmpty()) {
            throw new IllegalArgumentException("The Images response should NOT contain results for AWS provider.");
        }
        return entity;
    }).validate();
}
Also used : ImageCatalogTestClient(com.sequenceiq.it.cloudbreak.client.ImageCatalogTestClient) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) Test(org.testng.annotations.Test) ImageCatalogV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Responses) UpdateImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request) StackTestClient(com.sequenceiq.it.cloudbreak.client.StackTestClient) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) NotFoundException(javax.ws.rs.NotFoundException) ImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.ImageCatalogV4Request) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) ImageCatalogV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) ImageCatalogGetImagesByNameAction(com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogGetImagesByNameAction) BadRequestException(javax.ws.rs.BadRequestException) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) RunningParameter.expectedMessage(com.sequenceiq.it.cloudbreak.context.RunningParameter.expectedMessage) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) ImageCatalogGetImagesByNameAction(com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogGetImagesByNameAction) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Aggregations

MockedTestContext (com.sequenceiq.it.cloudbreak.context.MockedTestContext)12 Inject (javax.inject.Inject)9 Description (com.sequenceiq.it.cloudbreak.context.Description)8 Test (org.testng.annotations.Test)8 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)7 EnvironmentTestClient (com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient)6 ImageCatalogTestClient (com.sequenceiq.it.cloudbreak.client.ImageCatalogTestClient)5 RunningParameter.expectedMessage (com.sequenceiq.it.cloudbreak.context.RunningParameter.expectedMessage)5 EnvironmentTestDto (com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto)5 ImageCatalogTestDto (com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto)5 BadRequestException (javax.ws.rs.BadRequestException)5 EnvironmentStatus (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus)4 RunningParameter.key (com.sequenceiq.it.cloudbreak.context.RunningParameter.key)4 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)4 ImageCatalogV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.ImageCatalogV4Request)3 UpdateImageCatalogV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request)3 ImageCatalogV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response)3 ImageCatalogV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Responses)3 ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)3 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)3