use of org.kie.server.controller.api.storage.KieServerTemplateStorage in project kie-wb-common by kiegroup.
the class RuntimeManagementServiceCDITest method getContainersByContainerSpec_returnsContainerSpecData.
@Test
public void getContainersByContainerSpec_returnsContainerSpecData() {
final String templateId = "templateId", templateName = "templateName", serverInstanceId = "serverInstanceId", containerName = "containerName1", group = "g1", artifact = "a1", version = "1", containerSpecId = String.join(":", group, artifact, version);
final ReleaseId releaseId = new ReleaseId(group, artifact, version);
ServerInstanceKey serverInstanceKey = new ServerInstanceKey(templateId, null, serverInstanceId, null);
Container container = new Container(containerSpecId, containerName, serverInstanceKey, Collections.emptyList(), releaseId, null);
ContainerSpec containerSpec = new ContainerSpec(containerSpecId, containerName, new ServerTemplateKey(templateId, templateName), releaseId, KieContainerStatus.STARTED, Collections.emptyMap());
ServerTemplate serverTemplate = new ServerTemplate(templateId, templateName, Collections.emptyList(), Collections.emptyMap(), Collections.singletonList(containerSpec), Collections.singletonList(serverInstanceKey));
final List<Container> containersInServerInstance = Collections.singletonList(container);
// Setup mocks
KieServerTemplateStorage templateStorageMock = createMockStorageWithOneTemplate(serverTemplate);
KieServerInstanceManager instanceMangerMock = mock(KieServerInstanceManager.class);
when(instanceMangerMock.getContainers(serverInstanceKey)).thenReturn(containersInServerInstance);
// Setup tested object
runtimeManagementService.setTemplateStorage(templateStorageMock);
runtimeManagementService.setKieServerInstanceManager(instanceMangerMock);
specManagementService.setTemplateStorage(templateStorageMock);
specManagementService.setKieServerInstanceManager(instanceMangerMock);
// Tested method
ContainerSpecData containerSpecData = runtimeManagementServiceCDI.getContainersByContainerSpec(templateId, containerSpecId);
assertThat(containerSpecData.getContainers()).contains(container);
assertThat(containerSpecData.getContainerSpec()).isEqualTo(containerSpec);
}
use of org.kie.server.controller.api.storage.KieServerTemplateStorage in project kie-wb-common by kiegroup.
the class RuntimeManagementServiceCDITest method getContainersByServerInstance_returnsListOfContainers_whenInstanceWithIdExists.
@Test
public void getContainersByServerInstance_returnsListOfContainers_whenInstanceWithIdExists() {
final String templateId = "templateId";
final String templateName = "templateName";
final String serverInstanceId = "serverInstanceId";
ServerInstanceKey serverInstanceKey = new ServerInstanceKey(templateId, templateName, serverInstanceId, "dummyUrl");
ServerTemplate serverTemplate = new ServerTemplate(templateId, templateName, Collections.emptyList(), Collections.emptyMap(), Collections.emptyList(), Collections.singletonList(serverInstanceKey));
final List<Container> containersInServerInstance = Arrays.asList(new Container(), new Container());
KieServerTemplateStorage templateStorageMock = createMockStorageWithOneTemplate(serverTemplate);
// Instance with 2 dummy containers
KieServerInstanceManager instanceMangerMock = mock(KieServerInstanceManager.class);
when(instanceMangerMock.getContainers(eq(serverInstanceKey))).thenReturn(containersInServerInstance);
runtimeManagementService.setTemplateStorage(templateStorageMock);
runtimeManagementService.setKieServerInstanceManager(instanceMangerMock);
specManagementService.setTemplateStorage(templateStorageMock);
specManagementService.setKieServerInstanceManager(instanceMangerMock);
Collection<Container> containers = runtimeManagementServiceCDI.getContainersByServerInstance(templateId, serverInstanceId);
assertThat(containers).as("Should return list of containers from server instance id").hasSameSizeAs(containersInServerInstance);
}
use of org.kie.server.controller.api.storage.KieServerTemplateStorage in project kie-wb-common by kiegroup.
the class RuntimeManagementServiceCDITest method getContainersByServerInstance_returnsEmptyList_whenInstanceWithIdDoesntExistInTemplate.
@Test
public void getContainersByServerInstance_returnsEmptyList_whenInstanceWithIdDoesntExistInTemplate() {
final String templateId = "templateId";
final String serverInstanceId = "serverInstanceId";
KieServerTemplateStorage templateStorageMock = mock(KieServerTemplateStorage.class);
when(templateStorageMock.load(eq(templateId))).thenReturn(new ServerTemplate(null, null, Collections.emptyList(), Collections.emptyMap(), Collections.emptyList(), Collections.emptyList()));
// Setup tested service
runtimeManagementService.setTemplateStorage(templateStorageMock);
specManagementService.setTemplateStorage(templateStorageMock);
// Tested method
Collection<Container> containers = runtimeManagementServiceCDI.getContainersByServerInstance(templateId, serverInstanceId);
assertThat(containers).as("List of containers should be empty, when Server template doesn't contain server instance id").isEmpty();
}
use of org.kie.server.controller.api.storage.KieServerTemplateStorage in project kie-wb-common by kiegroup.
the class RuntimeManagementServiceCDITest method createMockStorageWithOneTemplate.
private KieServerTemplateStorage createMockStorageWithOneTemplate(ServerTemplate serverTemplate) {
KieServerTemplateStorage templateStorageMock = mock(KieServerTemplateStorage.class);
when(templateStorageMock.load(eq(serverTemplate.getId()))).thenReturn(serverTemplate);
return templateStorageMock;
}
Aggregations