use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.
the class ClusterUpgradeTargetImageServiceTest method testSaveImageShouldRemoveTheOldTargetImageAndSaveTheTargetImageWhenAnOldImageIsPresent.
@Test
void testSaveImageShouldRemoveTheOldTargetImageAndSaveTheTargetImageWhenAnOldImageIsPresent() throws IOException, CloudbreakImageNotFoundException {
StatedImage targetImage = ImageTestUtil.getImageFromCatalog(true, IMAGE_ID, STACK_VERSION, IMAGE_CATALOG_URL, IMAGE_CATALOG_NAME);
Image targetModelImage = createTargetModelImage(IMAGE_ID, IMAGE_CATALOG_URL, IMAGE_CATALOG_NAME);
Image oldTargetImage = createTargetModelImage("old-image-id", IMAGE_CATALOG_URL, IMAGE_CATALOG_NAME);
Optional<Component> existingTargetImageComponent = createExistingTargetImageComponent(oldTargetImage);
when(imageProvider.convertJsonToImage(existingTargetImageComponent.get().getAttributes())).thenReturn(oldTargetImage);
when(stackImageService.findImageComponentByName(STACK_ID, TARGET_IMAGE)).thenReturn(existingTargetImageComponent);
when(stackService.getById(STACK_ID)).thenReturn(stack);
when(stackImageService.getCurrentImage(stack)).thenReturn(currentImage);
when(stackImageService.getImageModelFromStatedImage(stack, currentImage, targetImage)).thenReturn(targetModelImage);
underTest.saveImage(STACK_ID, targetImage);
verify(stackImageService).getCurrentImage(stack);
verify(stackImageService).findImageComponentByName(STACK_ID, TARGET_IMAGE);
verify(stackService).getById(STACK_ID);
ArgumentCaptor<Component> targetComponentCaptor = ArgumentCaptor.forClass(Component.class);
verify(componentConfigProviderService).store(targetComponentCaptor.capture());
Component targetComponent = targetComponentCaptor.getValue();
assertEquals(ComponentType.IMAGE, targetComponent.getComponentType());
assertEquals(TARGET_IMAGE, targetComponent.getName());
assertEquals(stack, targetComponent.getStack());
assertEquals(targetModelImage.getImageId(), targetComponent.getAttributes().get(Image.class).getImageId());
}
use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.
the class ClusterUpgradeTargetImageServiceTest method testSaveImageShouldNotSaveTheTargetImageWhenIsAlreadyPresent.
@Test
void testSaveImageShouldNotSaveTheTargetImageWhenIsAlreadyPresent() {
StatedImage targetImage = ImageTestUtil.getImageFromCatalog(true, IMAGE_ID, STACK_VERSION, IMAGE_CATALOG_URL, IMAGE_CATALOG_NAME);
Image targetModelImageImage = createTargetModelImage(IMAGE_ID, IMAGE_CATALOG_URL, IMAGE_CATALOG_NAME);
Optional<Component> existingTargetImageComponent = createExistingTargetImageComponent(targetModelImageImage);
when(stackImageService.findImageComponentByName(STACK_ID, TARGET_IMAGE)).thenReturn(existingTargetImageComponent);
when(imageProvider.convertJsonToImage(existingTargetImageComponent.get().getAttributes())).thenReturn(targetModelImageImage);
underTest.saveImage(STACK_ID, targetImage);
verify(stackImageService).findImageComponentByName(STACK_ID, TARGET_IMAGE);
verify(imageProvider).convertJsonToImage(existingTargetImageComponent.get().getAttributes());
verifyNoInteractions(stackService);
verifyNoInteractions(componentConfigProviderService);
}
Aggregations