public static ServerInstanceKey newServerInstanceKey(String serverTemplateId, String url) { try { URL serverUrl = new URL(url); String serverInstanceId = null; if (serverUrl.getPort() == -1) { serverInstanceId = serverTemplateId + "@" + serverUrl.getHost(); } else { serverInstanceId = serverTemplateId + "@" + serverUrl.getHost() + ":" + serverUrl.getPort(); } return new ServerInstanceKey(serverTemplateId, serverInstanceId, serverInstanceId, url); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid server url " + url); } } }
public static ServerInstanceKey newServerInstanceKey(String serverTemplateId, String url) { try { URL serverUrl = new URL(url); String serverInstanceId = null; if (serverUrl.getPort() == -1) { serverInstanceId = serverTemplateId + "@" + serverUrl.getHost(); } else { serverInstanceId = serverTemplateId + "@" + serverUrl.getHost() + ":" + serverUrl.getPort(); } return new ServerInstanceKey(serverTemplateId, serverInstanceId, serverInstanceId, url); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid server url " + url); } } }
public ServerInstanceKey getServerInstanceKey() { return new ServerInstanceKey(getServerTemplateId(), serverInstanceId, serverInstanceId, getUrl()); }
public ServerInstanceKey getServerInstanceKey() { return new ServerInstanceKey(getServerTemplateId(), serverInstanceId, serverInstanceId, getUrl()); }
public static ServerInstanceKey toKey( final ServerInstance serverInstance ) { return new ServerInstanceKey( serverInstance.getServerTemplateId(), serverInstance.getServerName(), serverInstance.getServerInstanceId(), serverInstance.getUrl() ); }
@Test public void testSetup() { final Container container = new Container( "containerSpecId", "containerName", new ServerInstanceKey(), Collections.<Message>emptyList(), null, null ); presenter.setup( Collections.singletonList( container ) ); verify( containerCardPresenter ).setup( container ); verify( view ).addCard( any( Widget.class ) ); } }
@Test public void testOnSelectedServerInstance() { final RemotePresenter.View remoteView = mock( RemotePresenter.View.class ); when( remotePresenter.getView() ).thenReturn( remoteView ); presenter.onSelected( new ServerInstanceSelected( new ServerInstanceKey() ) ); verify( view ).setContent( remoteView ); }
@Test public void testLoadContainers() { final Container container = new Container("containerSpecId", "containerName", new ServerInstanceKey(), Collections.<Message>emptyList(), null, null); containerSpecData.getContainers().add(container); presenter.loadContainers(containerSpecData); verifyLoad(true, 1); }
@Test public void testRemoveError() { final ServerInstanceKey serverInstanceKey = new ServerInstanceKey( "templateId", "serverName", "serverInstanceId", "url" ); presenter.onSelect( new ServerInstanceSelected( serverInstanceKey ) ); doThrow( new RuntimeException() ).when( specManagementService ).deleteServerInstance( serverInstanceKey ); presenter.remove(); final ArgumentCaptor<NotificationEvent> notificationCaptor = ArgumentCaptor.forClass( NotificationEvent.class ); verify( notification ).fire( notificationCaptor.capture() ); assertEquals( NotificationEvent.NotificationType.ERROR, notificationCaptor.getValue().getType() ); }
@Test public void testRemove() { final ServerInstanceKey serverInstanceKey = new ServerInstanceKey( "templateId", "serverName", "serverInstanceId", "url" ); presenter.onSelect( new ServerInstanceSelected( serverInstanceKey ) ); presenter.remove(); verify( specManagementService ).deleteServerInstance( serverInstanceKey ); verify( notification ).fire( any( NotificationEvent.class ) ); }
@Test public void testLoadContainersNonStoped() { final Container container = new Container("containerSpecId", "containerName", new ServerInstanceKey(), Collections.<Message>emptyList(), null, null); container.setStatus(KieContainerStatus.STARTED); containerSpecData.getContainers().add(container); presenter.loadContainers(containerSpecData); verifyLoad(false, 1); }
@Test public void testOnDeleteWithoutCurrentServer() { final ServerInstanceKey serverInstanceKey = new ServerInstanceKey( "serverInstanceKeyId", "serverName", "serverInstanceId", "url" ); presenter.onDelete( new ServerInstanceDeleted( serverInstanceKey.getServerInstanceId() ) ); verify( specManagementService, never() ).listServerTemplateKeys(); }
@Test public void testServerTemplateUpdatedWithServerInstance() { final String serverTemplateId = "id1"; final ServerTemplate st1 = new ServerTemplate(serverTemplateId, "kie-server-template1"); st1.addServerInstance(new ServerInstanceKey()); when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(singletonList(st1))); serverTemplateSelectorMenuBuilder.onServerTemplateUpdated(new ServerTemplateUpdated(st1)); verifyNoMoreInteractions(view); }
@Test public void testOneServerTemplate() { final String serverTemplateId = "id1"; final ServerTemplate st1 = new ServerTemplate(serverTemplateId, "kie-server-template1"); st1.addServerInstance(new ServerInstanceKey()); when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(singletonList(st1))); serverTemplateSelectorMenuBuilder.init(); verify(specManagementService).listServerTemplates(); verify(view).setServerTemplateChangeHandler(any(ParameterizedCommand.class)); verify(view).removeAllServerTemplates(); verify(view).addServerTemplate(serverTemplateId); verify(view).selectServerTemplate(serverTemplateId); verify(view).setVisible(false); verifyNoMoreInteractions(view); }
@Test public void testServerTemplateUpdatedWithServerInstance() { final String serverTemplateId = "id1"; final ServerTemplate st1 = new ServerTemplate(serverTemplateId, "kie-server-template1"); st1.addServerInstance(new ServerInstanceKey()); when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(singletonList(st1))); serverTemplateSelectorMenuBuilder.onServerTemplateUpdated(new ServerTemplateUpdated(st1)); verifyNoMoreInteractions(view); }
@Test public void testOnDelete() { final ServerInstanceKey serverInstanceKey = new ServerInstanceKey( "serverInstanceKeyId", "serverName", "serverInstanceId", "url" ); final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateId", "ServerTemplateName" ); serverTemplate.addServerInstance( serverInstanceKey ); when( serverTemplatePresenter.getCurrentServerTemplate() ).thenReturn( serverTemplate ); final ServerTemplateKey serverTemplateKey = new ServerTemplateKey( "ServerTemplateKeyId", "ServerTemplateKeyName" ); final List<ServerTemplateKey> serverTemplateKeys = Collections.singletonList( serverTemplateKey ); when( specManagementService.listServerTemplateKeys() ).thenReturn( new ServerTemplateKeyList(serverTemplateKeys) ); presenter.onDelete( new ServerInstanceDeleted( serverInstanceKey.getServerInstanceId() ) ); verify( navigationPresenter ).setup( serverTemplateKey, serverTemplateKeys ); final ArgumentCaptor<ServerTemplateSelected> templateSelectedCaptor = ArgumentCaptor.forClass( ServerTemplateSelected.class ); verify( serverTemplateSelectedEvent ).fire( templateSelectedCaptor.capture() ); assertEquals( serverTemplateKey, templateSelectedCaptor.getValue().getServerTemplateKey() ); }
@Test public void testGetContainersByTemplate() { when(kieServerInstanceManager.getContainers(any(), any())).thenReturn(singletonList(container)); org.kie.server.controller.api.model.runtime.ServerInstanceKey instanceKey = new ServerInstanceKey("instanceId", "test server", serverTemplate.getId(), "http://fake.url.org"); serverTemplate.addServerInstance(instanceKey); specManagementService.saveServerTemplate(serverTemplate); ContainerList containers = runtimeManagementService.getContainers(serverTemplate, containerSpec); assertNotNull(containers); assertEquals(1, containers.getContainers().length); assertEquals(container, containers.getContainers()[0]); verify(kieServerInstanceManager).getContainers(any(), any()); }
@Test public void testGetContainersByInstance() { when(kieServerInstanceManager.getContainers(any(ServerInstanceKey.class))).thenReturn(singletonList(container)); org.kie.server.controller.api.model.runtime.ServerInstanceKey instanceKey = new ServerInstanceKey(serverTemplate.getId(), "test server", "instanceId", "http://fake.url.org"); serverTemplate.addServerInstance(instanceKey); specManagementService.saveServerTemplate(serverTemplate); ContainerList containers = runtimeManagementService.getContainers(instanceKey); assertNotNull(containers); assertEquals(1, containers.getContainers().length); assertEquals(container, containers.getContainers()[0]); verify(kieServerInstanceManager).getContainers(any()); }
@Test public void testSelectAndRefreshEmptyContainers() { final ServerInstanceKey serverInstanceKey = new ServerInstanceKey( "templateId", "serverName", "serverInstanceId", "url" ); when( runtimeManagementService.getContainersByServerInstance( serverInstanceKey.getServerTemplateId(), serverInstanceKey.getServerInstanceId() ) ).thenReturn( Collections.<Container>emptyList() ); presenter.onSelect( new ServerInstanceSelected( serverInstanceKey ) ); verify( view ).clear(); verify( view ).setServerName( serverInstanceKey.getServerName() ); verify( view ).setServerURL( serverInstanceKey.getUrl() ); verify( view ).setEmptyView( remoteEmptyPresenter.getView() ); }
@Test public void testOnServerInstanceSelect() { final ServerInstanceKey serverInstanceKey = new ServerInstanceKey( "serverInstanceKeyId", "serverName", "serverInstanceId", "url" ); presenter.onServerInstanceSelect( new ServerInstanceSelected( serverInstanceKey ) ); verify( view ).selectServerInstance( serverInstanceKey.getServerTemplateId(), serverInstanceKey.getServerInstanceId() ); }