Search in sources :

Example 1 with ImageWrapper

use of com.sequenceiq.freeipa.dto.ImageWrapper in project cloudbreak by hortonworks.

the class UpgradeImageServiceTest method testFindTargetImagesNoNewerImage.

@Test
public void testFindTargetImagesNoNewerImage() {
    Stack stack = new Stack();
    ImageSettingsRequest imageSettingsRequest = new ImageSettingsRequest();
    Image image = createImage("2021-07-01");
    ImageWrapper imageWrapper = new ImageWrapper(image, "catalogURL", "catalogName");
    when(imageService.fetchImagesWrapperAndName(stack, imageSettingsRequest)).thenReturn(List.of(Pair.of(imageWrapper, "imageName")));
    ImageInfoResponse currentImage = new ImageInfoResponse();
    currentImage.setDate("2021-08-21");
    currentImage.setId("111-222");
    List<ImageInfoResponse> targetImages = underTest.findTargetImages(stack, imageSettingsRequest, currentImage);
    assertTrue(targetImages.isEmpty());
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 2 with ImageWrapper

use of com.sequenceiq.freeipa.dto.ImageWrapper in project cloudbreak by hortonworks.

the class UpgradeImageServiceTest method testFindTargetImagesImageWithSameId.

@Test
public void testFindTargetImagesImageWithSameId() {
    Stack stack = new Stack();
    ImageSettingsRequest imageSettingsRequest = new ImageSettingsRequest();
    Image image = createImage("2021-09-01");
    ImageWrapper imageWrapper = new ImageWrapper(image, "catalogURL", "catalogName");
    when(imageService.fetchImagesWrapperAndName(stack, imageSettingsRequest)).thenReturn(List.of(Pair.of(imageWrapper, "imageName")));
    ImageInfoResponse currentImage = new ImageInfoResponse();
    currentImage.setDate("2021-08-21");
    currentImage.setId("1234-456");
    List<ImageInfoResponse> targetImages = underTest.findTargetImages(stack, imageSettingsRequest, currentImage);
    assertTrue(targetImages.isEmpty());
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with ImageWrapper

use of com.sequenceiq.freeipa.dto.ImageWrapper in project cloudbreak by hortonworks.

the class UpgradeImageServiceTest method testFindTargetImagesCurrentImageMissingDate.

@Test
public void testFindTargetImagesCurrentImageMissingDate() {
    Stack stack = new Stack();
    stack.setCloudPlatform("AWS");
    stack.setRegion("reg");
    ImageSettingsRequest imageSettingsRequest = new ImageSettingsRequest();
    Image image = createImage("2021-09-01");
    ImageWrapper imageWrapper = new ImageWrapper(image, "catalogURL", "catalogName");
    when(imageService.fetchImagesWrapperAndName(stack, imageSettingsRequest)).thenReturn(List.of(Pair.of(imageWrapper, "imageName")));
    ArgumentCaptor<ImageSettingsRequest> captor = ArgumentCaptor.forClass(ImageSettingsRequest.class);
    Image currentImageFromCatalog = createImage("2021-08-01");
    ImageWrapper currentImageWrapperFromCatalog = new ImageWrapper(currentImageFromCatalog, "asdf", "Asdf");
    when(imageService.getImage(captor.capture(), eq(stack.getRegion()), eq(stack.getCloudPlatform().toLowerCase()))).thenReturn(currentImageWrapperFromCatalog);
    ImageInfoResponse currentImage = new ImageInfoResponse();
    currentImage.setId("222-333");
    currentImage.setCatalog("cat");
    currentImage.setCatalogName("catName");
    currentImage.setOs("zOs");
    List<ImageInfoResponse> targetImages = underTest.findTargetImages(stack, imageSettingsRequest, currentImage);
    assertEquals(1, targetImages.size());
    ImageInfoResponse imageInfoResponse = targetImages.get(0);
    assertEquals(imageWrapper.getCatalogName(), imageInfoResponse.getCatalogName());
    assertEquals(imageWrapper.getCatalogUrl(), imageInfoResponse.getCatalog());
    assertEquals(image.getDate(), imageInfoResponse.getDate());
    assertEquals(image.getUuid(), imageInfoResponse.getId());
    assertEquals(image.getOs(), imageInfoResponse.getOs());
    ImageSettingsRequest settingsRequest = captor.getValue();
    assertEquals(currentImage.getCatalog(), settingsRequest.getCatalog());
    assertEquals(currentImage.getId(), settingsRequest.getId());
    assertEquals(currentImage.getOs(), settingsRequest.getOs());
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 4 with ImageWrapper

use of com.sequenceiq.freeipa.dto.ImageWrapper in project cloudbreak by hortonworks.

the class CoreImageProviderTest method testGetImagesdReturnsEmptyListWhenFreeImagesNull.

@Test
public void testGetImagesdReturnsEmptyListWhenFreeImagesNull() throws Exception {
    when(imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, CATALOG_NAME, null, PLATFORM, null, null, false)).thenReturn(new ImagesV4Response());
    ImageSettingsRequest imageSettings = new ImageSettingsRequest();
    imageSettings.setCatalog(CATALOG_NAME);
    List<ImageWrapper> result = victim.getImages(imageSettings, "", PLATFORM);
    assertTrue(result.isEmpty());
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Test(org.junit.jupiter.api.Test)

Example 5 with ImageWrapper

use of com.sequenceiq.freeipa.dto.ImageWrapper in project cloudbreak by hortonworks.

the class CoreImageProviderTest method testGetImagesdReturnsEmptyListWhenWebApplicationExceptionThrown.

@Test
public void testGetImagesdReturnsEmptyListWhenWebApplicationExceptionThrown() throws Exception {
    when(imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, CATALOG_NAME, null, PLATFORM, null, null, false)).thenThrow(new WebApplicationException());
    ImageSettingsRequest imageSettings = new ImageSettingsRequest();
    imageSettings.setCatalog(CATALOG_NAME);
    List<ImageWrapper> result = victim.getImages(imageSettings, "", PLATFORM);
    assertTrue(result.isEmpty());
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) WebApplicationException(javax.ws.rs.WebApplicationException) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Test(org.junit.jupiter.api.Test)

Aggregations

ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)34 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)26 Test (org.junit.jupiter.api.Test)24 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)18 Stack (com.sequenceiq.freeipa.entity.Stack)10 ImageInfoResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse)8 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)6 WebApplicationException (javax.ws.rs.WebApplicationException)4 ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)3 ImageCatalog (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)3 ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)2 ImageNotFoundException (com.sequenceiq.freeipa.service.image.ImageNotFoundException)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Value (org.springframework.beans.factory.annotation.Value)2 Service (org.springframework.stereotype.Service)2