Search in sources :

Example 1 with UsedImagesListV1Response

use of com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response in project cloudbreak by hortonworks.

the class UsedImagesProvider method getUsedImages.

public UsedImagesListV1Response getUsedImages(Integer thresholdInDays) {
    final UsedImagesListV1Response usedImages = new UsedImagesListV1Response();
    stackService.getImagesOfAliveStacks(thresholdInDays).stream().map(ImageEntity::getImageId).forEach(usedImages::addImage);
    return usedImages;
}
Also used : UsedImagesListV1Response(com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response)

Example 2 with UsedImagesListV1Response

use of com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response in project cloudbreak by hortonworks.

the class UsedImagesProviderTest method testMultipleImages.

@Test
void testMultipleImages() {
    when(stackService.getImagesOfAliveStacks(THRESHOLD_IN_DAYS)).thenReturn(List.of(createImage("aws-image"), createImage("aws-image"), createImage("azure-image")));
    final UsedImagesListV1Response result = underTest.getUsedImages(THRESHOLD_IN_DAYS);
    assertThat(result.getUsedImages()).hasSize(2).anyMatch(usedImage -> usedImage.getImage().getImageId().equals("aws-image") && usedImage.getNumberOfStacks() == 2).anyMatch(usedImage -> usedImage.getImage().getImageId().equals("azure-image") && usedImage.getNumberOfStacks() == 1);
}
Also used : Test(org.junit.jupiter.api.Test) InjectMocks(org.mockito.InjectMocks) UsedImagesListV1Response(com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response) List(java.util.List) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StackService(com.sequenceiq.freeipa.service.stack.StackService) Mockito.when(org.mockito.Mockito.when) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) UsedImagesListV1Response(com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response) Test(org.junit.jupiter.api.Test)

Example 3 with UsedImagesListV1Response

use of com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response in project cloudbreak by hortonworks.

the class UsedImagesProviderTest method testSingleImage.

@Test
void testSingleImage() {
    when(stackService.getImagesOfAliveStacks(THRESHOLD_IN_DAYS)).thenReturn(List.of(createImage("aws-image")));
    final UsedImagesListV1Response result = underTest.getUsedImages(THRESHOLD_IN_DAYS);
    assertThat(result.getUsedImages()).hasSize(1);
    assertThat(result.getUsedImages().get(0).getNumberOfStacks()).isEqualTo(1);
}
Also used : UsedImagesListV1Response(com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response) Test(org.junit.jupiter.api.Test)

Example 4 with UsedImagesListV1Response

use of com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response in project cloudbreak by hortonworks.

the class UsedImagesProviderTest method testEmpty.

@Test
void testEmpty() {
    when(stackService.getImagesOfAliveStacks(THRESHOLD_IN_DAYS)).thenReturn(List.of());
    final UsedImagesListV1Response result = underTest.getUsedImages(THRESHOLD_IN_DAYS);
    assertThat(result.getUsedImages()).isEmpty();
}
Also used : UsedImagesListV1Response(com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response) Test(org.junit.jupiter.api.Test)

Example 5 with UsedImagesListV1Response

use of com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response in project cloudbreak by hortonworks.

the class FreeipaUsedImagesAction method action.

@Override
public FreeipaUsedImagesTestDto action(TestContext testContext, FreeipaUsedImagesTestDto testDto, FreeIpaClient client) throws Exception {
    final UsedImagesListV1Response usedImages = client.getInternalClient(testContext).utilV1Endpoint().usedImages(null);
    testDto.setResponse(usedImages);
    return testDto;
}
Also used : UsedImagesListV1Response(com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response)

Aggregations

UsedImagesListV1Response (com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response)5 Test (org.junit.jupiter.api.Test)3 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)1 StackService (com.sequenceiq.freeipa.service.stack.StackService)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 InjectMocks (org.mockito.InjectMocks)1 Mock (org.mockito.Mock)1 Mockito.when (org.mockito.Mockito.when)1 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)1