@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())); runtimeManagementService.setTemplateStorage(templateStorageMock); specManagementService.setTemplateStorage(templateStorageMock); 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(); }
@Override public Collection<Container> getContainersByServerInstance(final String serverTemplateId, final String serverInstanceId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } return serverTemplate.getServerInstanceKeys().stream() .filter(serverInstanceKey -> serverInstanceKey.getServerInstanceId().equalsIgnoreCase(serverInstanceId)) .findFirst() .map(serverInstanceKey -> Arrays.asList(service.getContainers(serverInstanceKey).getContainers())) .orElse(Collections.emptyList()); }
RuntimeManagementServiceCDI implements RuntimeManagementService { @Override public Collection<Container> getContainersByServerInstance(final String serverTemplateId, final String serverInstanceId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } return serverTemplate.getServerInstanceKeys().stream() .filter(serverInstanceKey -> serverInstanceKey.getServerInstanceId().equalsIgnoreCase(serverInstanceId)) .findFirst() .map(serverInstanceKey -> Arrays.asList(service.getContainers(serverInstanceKey).getContainers())) .orElse(Collections.emptyList()); } }
RuntimeManagementServiceCDI implements RuntimeManagementService { @Override public Collection<Container> getContainersByServerInstance(final String serverTemplateId, final String serverInstanceId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } return serverTemplate.getServerInstanceKeys().stream() .filter(serverInstanceKey -> serverInstanceKey.getServerInstanceId().equalsIgnoreCase(serverInstanceId)) .findFirst() .map(serverInstanceKey -> Arrays.asList(service.getContainers(serverInstanceKey).getContainers())) .orElse(Collections.emptyList()); }  }
RuntimeManagementServiceCDI implements RuntimeManagementService { @Override public Collection<Container> getContainersByServerInstance(final String serverTemplateId, final String serverInstanceId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } return serverTemplate.getServerInstanceKeys().stream() .filter(serverInstanceKey -> serverInstanceKey.getServerInstanceId().equalsIgnoreCase(serverInstanceId)) .findFirst() .map(serverInstanceKey -> Arrays.asList(service.getContainers(serverInstanceKey).getContainers())) .orElse(Collections.emptyList()); }  @Override Collection<Container> getContainersByServerInstance(final String serverTemplateId,
                                                               final String serverInstanceId); @Override ContainerSpecData getContainersByContainerSpec(final String serverTemplateId,
                                                          final String containerSpecId); }
RuntimeManagementServiceCDI implements RuntimeManagementService { @Override public Collection<Container> getContainersByServerInstance(final String serverTemplateId, final String serverInstanceId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } return serverTemplate.getServerInstanceKeys().stream() .filter(serverInstanceKey -> serverInstanceKey.getServerInstanceId().equalsIgnoreCase(serverInstanceId)) .findFirst() .map(serverInstanceKey -> Arrays.asList(service.getContainers(serverInstanceKey).getContainers())) .orElse(Collections.emptyList()); }  @Override Collection<Container> getContainersByServerInstance(final String serverTemplateId,
                                                               final String serverInstanceId); @Override ContainerSpecData getContainersByContainerSpec(final String serverTemplateId,
                                                          final String containerSpecId);  }