Search in sources :

Example 16 with TestContext

use of com.sequenceiq.it.cloudbreak.context.TestContext 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)

Example 17 with TestContext

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

the class ImageCatalogTest method testGetImageCatalogsRequestFromExistingImageCatalog.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "image catalog get request", when = "calling get request on catalog endpoint", then = "getting back the catalog request")
public void testGetImageCatalogsRequestFromExistingImageCatalog(MockedTestContext testContext) {
    String imgCatalogName = resourcePropertyProvider().getName();
    testContext.given(imgCatalogName, ImageCatalogTestDto.class).withName(imgCatalogName).withUrl(getImageCatalogMockServerSetup().getImageCatalogUrl()).when(imageCatalogTestClient.createV4(), key(imgCatalogName)).select(ImageCatalogTestDto::getRequest, key(imgCatalogName)).when((testContext1, entity, cloudbreakClient) -> {
        ImageCatalogV4Request request = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().getRequest(cloudbreakClient.getWorkspaceId(), imgCatalogName);
        entity.setRequest(request);
        return entity;
    }).then((testContext1, entity, cloudbreakClient) -> {
        ImageCatalogV4Request imgCatReq = testContext1.getSelected(imgCatalogName);
        if (entity.getRequest().equals(imgCatReq)) {
            throw new IllegalArgumentException("The requests are not identical.");
        }
        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) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) UpdateImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request) ImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.ImageCatalogV4Request) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Example 18 with TestContext

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

the class ImageCatalogTest method testUpdateImageCatalog.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "image catalog update request", when = "calling update request with new url", then = "the image catalog list should contains the new url")
public void testUpdateImageCatalog(MockedTestContext testContext) {
    String imgCatalogName = resourcePropertyProvider().getName();
    testContext.given(imgCatalogName, ImageCatalogTestDto.class).withName(imgCatalogName).withUrl(getImageCatalogMockServerSetup().getImageCatalogUrl()).when(imageCatalogTestClient.createV4(), key(imgCatalogName)).select(ImageCatalogTestDto::getResponse, key(imgCatalogName)).when((testContext1, entity, cloudbreakClient) -> {
        ImageCatalogV4Response originalResponse = entity.getResponse();
        UpdateImageCatalogV4Request updateRequest = new UpdateImageCatalogV4Request();
        updateRequest.setCrn(originalResponse.getCrn());
        updateRequest.setName(originalResponse.getName());
        updateRequest.setUrl(IMG_CATALOG_URL);
        ImageCatalogV4Response updateResponse = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().update(cloudbreakClient.getWorkspaceId(), updateRequest);
        entity.setResponse(updateResponse);
        return entity;
    }, key(imgCatalogName)).then((testContext1, entity, cloudbreakClient) -> {
        ImageCatalogV4Response originalRepsonse = testContext1.getSelected(imgCatalogName);
        if (originalRepsonse.getUrl().equals(entity.getResponse().getUrl())) {
            throw new IllegalArgumentException("The catalog URL should not be the same after update.");
        }
        return entity;
    }, key(imgCatalogName)).validate();
}
Also used : UpdateImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request) 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) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) ImageCatalogV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Example 19 with TestContext

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

the class UsedImagesTest method verifyImagesAreUsed.

private <T extends CloudbreakTestDto> T verifyImagesAreUsed(TestContext testContext, T testDto) {
    testContext.given(UsedImagesTestDto.class).when(utilTestClient.usedImages()).then((tc, usedImagesTestDto, client) -> {
        List<UsedImageStacksV4Response> usedImages = usedImagesTestDto.getResponse().getUsedImages();
        UsedImageStacksV4Response usedImageStacksV4Response = usedImages.stream().filter(usedImage -> usedImage.getImage().getImageId().contains(sdxImageUuid)).findFirst().orElseThrow(() -> new TestFailException(String.format("SDX image is NOT in use with ID:: %s", sdxImageUuid)));
        LOGGER.info("Used SDX image ID:: {}", usedImageStacksV4Response.getImage().getImageId());
        return usedImagesTestDto;
    }).given(FreeipaUsedImagesTestDto.class).when(freeIpaTestClient.usedImages()).then((tc, usedImagesTestDto, client) -> {
        List<UsedImageStacksV1Response> usedImages = usedImagesTestDto.getResponse().getUsedImages();
        UsedImageStacksV1Response usedImageStacksV1Response = usedImages.stream().filter(usedImage -> usedImage.getImage().getImageId().contains(freeipaImageUuid)).findFirst().orElseThrow(() -> new TestFailException(String.format("FreeIpa image is NOT in use with ID:: %s", freeipaImageUuid)));
        LOGGER.info("Used FreeIpa image ID:: {}", usedImageStacksV1Response.getImage().getImageId());
        return usedImagesTestDto;
    }).validate();
    return testDto;
}
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) Description(com.sequenceiq.it.cloudbreak.context.Description) EnvironmentNetworkTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentNetworkTestDto) Inject(javax.inject.Inject) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Status(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) CloudbreakTestDto(com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto) FreeipaUsedImagesTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeipaUsedImagesTestDto) UsedImagesTestDto(com.sequenceiq.it.cloudbreak.dto.util.UsedImagesTestDto) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) UUID(java.util.UUID) UsedImageStacksV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.UsedImageStacksV4Response) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) List(java.util.List) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) UtilTestClient(com.sequenceiq.it.cloudbreak.client.UtilTestClient) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) UsedImageStacksV1Response(com.sequenceiq.freeipa.api.v1.util.model.UsedImageStacksV1Response) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) UsedImageStacksV1Response(com.sequenceiq.freeipa.api.v1.util.model.UsedImageStacksV1Response) FreeipaUsedImagesTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeipaUsedImagesTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) List(java.util.List) UsedImageStacksV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.UsedImageStacksV4Response)

Example 20 with TestContext

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

the class EnvironmentEditTest method authenticationEditWhenSetExistingKeyAndDeleteManagedSuccessfully.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "there is a running cloudbreak managed ssh key", when = "change managed ssh key to existing one", then = "delete managed ssh key but not create new one")
public void authenticationEditWhenSetExistingKeyAndDeleteManagedSuccessfully(MockedTestContext testContext) {
    String randomPublicKeyId = UUID.randomUUID().toString();
    testContext.given(HttpMock.class).mockSpi().getPublicKey().get().pathVariable("publicKeyId", randomPublicKeyId).thenReturn(Map.of("publicKeyId", randomPublicKeyId, "publicKey", "asd")).given(EnvironmentTestDto.class).withCreateFreeIpa(false).when(environmentTestClient.create()).await(EnvironmentStatus.AVAILABLE).given(EnvironmentAuthenticationTestDto.class).withPublicKeyId(randomPublicKeyId).withPublicKey(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 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) HttpMock(com.sequenceiq.it.cloudbreak.dto.mock.HttpMock) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

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