Source:
public void testCreateAvailableClients() throws Exception { final String serverTemplateId = "kie-server-test"; final String serverInstanceId1 = serverTemplateId + "@1"; final String serverInstanceId2 = serverTemplateId + "@2"; final ContainerSpec containerSpec = newContainerSpec(); final ServerInstance serverInstance1 = new ServerInstance(); serverInstance1.setServerTemplateId(serverTemplateId); serverInstance1.setUrl("http://1"); serverInstance1.setServerInstanceId(serverInstanceId1); final ServerTemplate serverTemplate = new ServerTemplate(serverTemplateId, serverTemplateId); serverTemplate.addContainerSpec(containerSpec); final ServerInstance serverInstance2 = new ServerInstance(); serverInstance2.setServerTemplateId(serverTemplateId); serverInstance2.setUrl("http://2"); serverInstance2.setServerInstanceId(serverInstanceId2); serverTemplate.addServerInstance(serverInstance2); when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(Collections.singletonList(serverTemplate))); CountDownLatch latch = new CountDownLatch(2); doAnswer(a -> { final Object result = a.callRealMethod(); latch.countDown(); return result; }).when(kieServerIntegration).createClientForTemplate(any(), any(), any()); kieServerIntegration.createAvailableClients(); latch.await(10, TimeUnit.SECONDS); assertEquals(1, kieServerIntegration.getServerTemplatesClients().size()); assertNotNull(kieServerIntegration.getServerClient(serverTemplateId)); assertNotNull(kieServerIntegration.getAdminServerClient(serverTemplateId, serverInstanceId1)); assertNotNull(kieServerIntegration.getAdminServerClient(serverTemplateId, serverInstanceId2)); }

Target:
public void testCreateAvailableClients() throws Exception { final String serverTemplateId = "kie-server-test"; final ServerTemplate serverTemplate = new ServerTemplate(serverTemplateId, serverTemplateId); final ContainerSpec containerSpec = newContainerSpec(); serverTemplate.addContainerSpec(containerSpec); final String serverInstanceId1 = serverTemplateId + "@1"; final ServerInstance serverInstance1 = new ServerInstance(); serverInstance1.setServerTemplateId(serverTemplateId); serverInstance1.setUrl("http://1"); serverInstance1.setServerInstanceId(serverInstanceId1); serverTemplate.addServerInstance(serverInstance1); final String serverInstanceId2 = serverTemplateId + "@2"; final ServerInstance serverInstance2 = new ServerInstance(); serverInstance2.setServerTemplateId(serverTemplateId); serverInstance2.setUrl("http://2"); serverInstance2.setServerInstanceId(serverInstanceId2); serverTemplate.addServerInstance(serverInstance2); when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(Collections.singletonList(serverTemplate))); CountDownLatch latch = new CountDownLatch(2); doAnswer(a -> { final Object result = a.callRealMethod(); latch.countDown(); return result; }).when(kieServerIntegration).createClientForTemplate(any(), any(), any()); kieServerIntegration.createAvailableClients(); assertTrue("Clients not created within 10 seconds", latch.await(10, TimeUnit.SECONDS)); assertEquals(1, kieServerIntegration.getServerTemplatesClients().size()); assertNotNull(kieServerIntegration.getServerClient(serverTemplateId)); assertNotNull(kieServerIntegration.getAdminServerClient(serverTemplateId, serverInstanceId1)); assertNotNull(kieServerIntegration.getAdminServerClient(serverTemplateId, serverInstanceId2)); }