use of com.sequenceiq.cloudbreak.service.ComponentConfigProviderService in project cloudbreak by hortonworks.
the class StackComponentUpdaterTest method testUpdateImageComponents.
@Test
public void testUpdateImageComponents() throws CloudbreakImageCatalogException, CloudbreakImageNotFoundException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
stack.setCluster(cluster);
StatedImage targetImage = ImageTestUtil.getImageFromCatalog(true, "targetImageUuid", TARGET_STACK_VERSION);
Image originalImage = ImageTestUtil.getImage(true, "originalImageUuid", STACK_VERSION);
Component originalImageComponent = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json(originalImage), stack);
when(componentConfigProviderService.getComponentsByStackId(stack.getId())).thenReturn(Set.of(originalImageComponent));
Set<Component> targetComponents = createComponents(stack, targetImage);
underTest.updateComponentsByStackId(stack, targetComponents, true);
ArgumentCaptor<Set<Component>> componentCatcher = ArgumentCaptor.forClass(Set.class);
verify(componentConfigProviderService, times(1)).store(componentCatcher.capture());
assertEquals(3, componentCatcher.getValue().size());
assertTrue(componentCatcher.getValue().stream().anyMatch(component -> {
Object version = component.getAttributes().getValue("version");
if (Objects.nonNull(version)) {
return ((String) version).contains(TARGET_STACK_VERSION);
} else {
return false;
}
}));
assertTrue(componentCatcher.getValue().stream().anyMatch(component -> {
Object userData = component.getAttributes().getValue("userdata");
if (Objects.nonNull(userData)) {
return ((Map<String, String>) userData).get(InstanceGroupType.GATEWAY.name()).contains("gw user data");
} else {
return false;
}
}));
}
Aggregations