@Override public RuntimesInfo getRuntimesInfo(final ProviderKey providerKey) { checkNotNull("providerKey", providerKey); final Provider provider = providerService.getProvider(providerKey); if (provider == null) { return null; } final Collection<RuntimeListItem> items = runtimeService.getRuntimeItems(providerKey); return new RuntimesInfo(provider, items); }
@Override public void complete() { final ProviderConfiguration providerConfiguration = providerConfigurationPage.buildProviderConfiguration(); providerService.call((Void aVoid) -> onCreateProviderSuccess(providerConfiguration), popupHelper.getPopupErrorCallback()).createProvider(providerType, providerConfiguration); }
public void removeProvider() { providerService.call(response -> { notification.fire(new NotificationEvent(view.getRemoveProviderSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); providerTypeSelectedEvent.fire(new ProviderTypeSelectedEvent(provider.getKey().getProviderTypeKey())); }, (message, throwable) -> { notification.fire(new NotificationEvent(view.getRemoveProviderErrorMessage(), NotificationEvent.NotificationType.ERROR)); providerTypeSelectedEvent.fire(new ProviderTypeSelectedEvent(provider.getKey().getProviderTypeKey())); return false; }).deleteProvider(provider.getKey()); }
@Override public ProvidersInfo getProvidersInfo(final ProviderTypeKey providerTypeKey) { checkNotNull("providerTypeKey", providerTypeKey); final ProviderType providerType = providerTypeService.getProviderType(providerTypeKey); if (providerType == null) { return null; } final Collection<ProviderKey> providersKey = providerService.getProvidersKey(providerType); return new ProvidersInfo(providerType, providersKey); }
@Test public void testGetProvidersInfoProviderTypeNotExisting() { //the provider type not exists. when(providerTypeService.getProviderType(providerTypeKey)).thenReturn(null); ProvidersInfo providersInfo = service.getProvidersInfo(providerTypeKey); assertNull(providersInfo); verify(providerTypeService, times(1)).getProviderType(providerTypeKey); verify(providerService, never()).getProvidersKey(providerType); }
@Test public void testGetRuntimesInfoProviderNotExisting() { //the provider not exists. when(providerService.getProvider(providerKey)).thenReturn(null); RuntimesInfo info = service.getRuntimesInfo(providerKey); assertNull(info); verify(providerService, times(1)).getProvider(providerKey); verify(runtimeService, never()).getRuntimeItems(providerKey); }
@Override public void complete() { final ProviderConfiguration providerConfiguration = providerConfigurationPage.buildProviderConfiguration(); providerService.call((Void aVoid) -> onCreateProviderSuccess(providerConfiguration), popupHelper.getPopupErrorCallback()).createProvider(providerType, providerConfiguration); }
public void removeProvider() { providerService.call(response -> { notification.fire(new NotificationEvent(view.getRemoveProviderSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); providerTypeSelectedEvent.fire(new ProviderTypeSelectedEvent(provider.getKey().getProviderTypeKey())); }, (message, throwable) -> { notification.fire(new NotificationEvent(view.getRemoveProviderErrorMessage(), NotificationEvent.NotificationType.ERROR)); providerTypeSelectedEvent.fire(new ProviderTypeSelectedEvent(provider.getKey().getProviderTypeKey())); return false; }).deleteProvider(provider.getKey()); }
@Test public void testGetProvidersInfoProviderTypeNotExisting() { //the provider type not exists. when(providerTypeService.getProviderType(providerTypeKey)).thenReturn(null); ProvidersInfo providersInfo = service.getProvidersInfo(providerTypeKey); assertNull(providersInfo); verify(providerTypeService, times(1)).getProviderType(providerTypeKey); verify(providerService, never()).getProvidersKey(providerType); }
@Test public void testGetRuntimesInfoProviderNotExisting() { //the provider not exists. when(providerService.getProvider(providerKey)).thenReturn(null); RuntimesInfo info = service.getRuntimesInfo(providerKey); assertNull(info); verify(providerService, times(1)).getProvider(providerKey); verify(runtimeService, never()).getRuntimeItems(providerKey); }
@Test public void testCreateProviderFailure() { //initialize and start the wizard. wizard.start(providerType); //emulate the user completing the wizard. preCompleteWizard(); prepareServiceCallerError(providerService, providerServiceCaller); //emulate the user pressing the finish button. wizard.complete(); verify(providerService, times(1)).createProvider(providerType, providerConfiguration); verify(popupHelper, times(1)).getPopupErrorCallback(); verify(defaultErrorCallback, times(1)).error(any(Message.class), any(Throwable.class)); verify(providerTypeSelectedEvent, never()).fire(any(ProviderTypeSelectedEvent.class)); }
private void testRemoveProvider(boolean withErrors) { //emulate that the provider was previously loaded. prepareRuntimesInfo(); presenter.onProviderSelected(new ProviderSelectedEvent(providerKey)); when(view.getRemoveProviderSuccessMessage()).thenReturn(SUCCESS_MESSAGE); when(view.getRemoveProviderErrorMessage()).thenReturn(ERROR_MESSAGE); if (withErrors) { //make the providerService fail. prepareServiceCallerError(providerService, providerServiceCaller); } //the user confirms the delete operation at a later time from the ui. presenter.removeProvider(); verify(providerService, times(1)).deleteProvider(providerKey); verify(providerTypeSelectedEvent, times(1)).fire(new ProviderTypeSelectedEvent(providerKey.getProviderTypeKey())); if (withErrors) { verify(notification, times(1)).fire(new NotificationEvent(ERROR_MESSAGE, NotificationEvent.NotificationType.ERROR)); } else { verify(notification, times(1)).fire(new NotificationEvent(SUCCESS_MESSAGE, NotificationEvent.NotificationType.SUCCESS)); } }
@Test public void testGetProvidersInfoProviderTypeExisting() { //the provider type exists. when(providerTypeService.getProviderType(providerTypeKey)).thenReturn(providerType); when(providerService.getProvidersKey(providerType)).thenReturn(providerKeys); ProvidersInfo providersInfo = service.getProvidersInfo(providerTypeKey); assertNotNull(providersInfo); assertEquals(providerType, providersInfo.getProviderType()); assertEquals(providerKeys, providersInfo.getProvidersKey()); verify(providerTypeService, times(1)).getProviderType(providerTypeKey); verify(providerService, times(1)).getProvidersKey(providerType); }
private void validateForCreateRuntime(final ProviderKey providerKey, final String runtimeName) { final Provider provider = providerService.getProvider(providerKey); if (provider == null) { //uncommon case logger.error("No provider was found for providerKey: " + providerKey); throw new ServiceException("No provider was found for providerKey: " + providerKey); } final Collection<RuntimeQueryResultItem> items = runtimeProvisioningService.executeQuery(RuntimeQueryBuilder.newInstance() .withRuntimeName(runtimeName) .build()); if (!items.isEmpty()) { throw new ServiceException("A runtime with the given name already exists: " + runtimeName); } } }
@Test public void testCreateProviderFailure() { //initialize and start the wizard. wizard.start(providerType); //emulate the user completing the wizard. preCompleteWizard(); prepareServiceCallerError(providerService, providerServiceCaller); //emulate the user pressing the finish button. wizard.complete(); verify(providerService, times(1)).createProvider(providerType, providerConfiguration); verify(popupHelper, times(1)).getPopupErrorCallback(); verify(defaultErrorCallback, times(1)).error(any(Message.class), any(Throwable.class)); verify(providerTypeSelectedEvent, never()).fire(any(ProviderTypeSelectedEvent.class)); }
private void testRemoveProvider(boolean withErrors) { //emulate that the provider was previously loaded. prepareRuntimesInfo(); presenter.onProviderSelected(new ProviderSelectedEvent(providerKey)); when(view.getRemoveProviderSuccessMessage()).thenReturn(SUCCESS_MESSAGE); when(view.getRemoveProviderErrorMessage()).thenReturn(ERROR_MESSAGE); if (withErrors) { //make the providerService fail. prepareServiceCallerError(providerService, providerServiceCaller); } //the user confirms the delete operation at a later time from the ui. presenter.removeProvider(); verify(providerService, times(1)).deleteProvider(providerKey); verify(providerTypeSelectedEvent, times(1)).fire(new ProviderTypeSelectedEvent(providerKey.getProviderTypeKey())); if (withErrors) { verify(notification, times(1)).fire(new NotificationEvent(ERROR_MESSAGE, NotificationEvent.NotificationType.ERROR)); } else { verify(notification, times(1)).fire(new NotificationEvent(SUCCESS_MESSAGE, NotificationEvent.NotificationType.SUCCESS)); } }
@Test public void testGetProvidersInfoProviderTypeExisting() { //the provider type exists. when(providerTypeService.getProviderType(providerTypeKey)).thenReturn(providerType); when(providerService.getProvidersKey(providerType)).thenReturn(providerKeys); ProvidersInfo providersInfo = service.getProvidersInfo(providerTypeKey); assertNotNull(providersInfo); assertEquals(providerType, providersInfo.getProviderType()); assertEquals(providerKeys, providersInfo.getProvidersKey()); verify(providerTypeService, times(1)).getProviderType(providerTypeKey); verify(providerService, times(1)).getProvidersKey(providerType); }
@Test public void testCreateRuntimeWhenUnExpectedError() { Provider provider = mock(Provider.class); ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); when(providerService.getProvider(providerKey)).thenReturn(provider); when(pipelineService.runPipeline(anyString(), any(Input.class), eq(true))).thenThrow(new RuntimeException(ERROR_MESSAGE)); expectedException.expectMessage(ERROR_MESSAGE); service.createRuntime(providerKey, "irrelevant for the test", mock(PipelineKey.class), mock(Map.class)); }
@Test public void testCreateProviderSuccess() { //initialize and start the wizard. wizard.start(providerType); //emulate the user completing the wizard. preCompleteWizard(); //emulate the user pressing the finish button. wizard.complete(); //verify that the provider has been created and the proper notifications were fired. verify(providerService, times(1)).createProvider(providerType, providerConfiguration); verify(notification, times(1)).fire(new NotificationEvent(SUCCESS_MESSAGE, NotificationEvent.NotificationType.SUCCESS)); verify(providerTypeSelectedEvent, times(1)).fire(new ProviderTypeSelectedEvent(providerType.getKey(), providerConfiguration.getId())); }
@Test public void testCreateRuntimeWhenUnExpectedError() { Provider provider = mock(Provider.class); ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); when(providerService.getProvider(providerKey)).thenReturn(provider); when(pipelineService.runPipeline(anyString(), any(Input.class), eq(true))).thenThrow(new RuntimeException(ERROR_MESSAGE)); expectedException.expectMessage(ERROR_MESSAGE); service.createRuntime(providerKey, "irrelevant for the test", mock(PipelineKey.class), mock(Map.class)); }