private void validateForCreateProvider(ProviderConfiguration configuration) { for (final Provider provider : getAllProviders()) { if (configuration.getId().equals(provider.getKey().getId())) { throw new ServiceException("A provider with the given name already exists: " + configuration.getId()); } } } }
private void onCreateProviderSuccess(final ProviderConfiguration providerConfiguration) { notification.fire(new NotificationEvent(translationService.getTranslation(NewProviderWizard_ProviderCreateSuccessMessage), NotificationEvent.NotificationType.SUCCESS)); NewProviderWizard.super.complete(); providerTypeSelectedEvent.fire(new ProviderTypeSelectedEvent(providerType.getKey(), providerConfiguration.getId())); }
private void onCreateProviderSuccess(final ProviderConfiguration providerConfiguration) { notification.fire(new NotificationEvent(translationService.getTranslation(NewProviderWizard_ProviderCreateSuccessMessage), NotificationEvent.NotificationType.SUCCESS)); NewProviderWizard.super.complete(); providerTypeSelectedEvent.fire(new ProviderTypeSelectedEvent(providerType.getKey(), providerConfiguration.getId())); }
@Test public void testCreateProvider() { prepareConfigurationForCreate(); //PROVIDER_ID don't exists by construction. when(providerConfiguration.getId()).thenReturn(PROVIDER_ID); service.createProvider(providerType, providerConfiguration); verify(runtimeProvisioningService, times(1)).registerProvider(providerConfig); }
@Test public void testCreateProvider() { prepareConfigurationForCreate(); //PROVIDER_ID don't exists by construction. when(providerConfiguration.getId()).thenReturn(PROVIDER_ID); service.createProvider(providerType, providerConfiguration); verify(runtimeProvisioningService, times(1)).registerProvider(providerConfig); }
@Test public void testCreateProviderExisting() { prepareConfigurationForCreate(); //emulate that one of the existing providers has the same id by picking an arbitrary existing id. String existingId = providers.get(1).getKey().getId(); when(providerConfiguration.getId()).thenReturn(existingId); expectedException.expectMessage("A provider with the given name already exists: " + existingId); service.createProvider(providerType, providerConfiguration); verify(runtimeProvisioningService, never()).registerProvider(any(ProviderConfig.class)); }
@Test public void testCreateProviderExisting() { prepareConfigurationForCreate(); //emulate that one of the existing providers has the same id by picking an arbitrary existing id. String existingId = providers.get(1).getKey().getId(); when(providerConfiguration.getId()).thenReturn(existingId); expectedException.expectMessage("A provider with the given name already exists: " + existingId); service.createProvider(providerType, providerConfiguration); verify(runtimeProvisioningService, never()).registerProvider(any(ProviderConfig.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 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 testToModel() { OpenShiftProviderConfig config = mock(OpenShiftProviderConfig.class); when(config.getName()).thenReturn(PROVIDER_NAME_VALUE); when(config.getKubernetesMaster()).thenReturn(MASTER_URL_VALUE); when(config.getKubernetesAuthBasicUsername()).thenReturn(USER_VALUE); when(config.getKubernetesAuthBasicPassword()).thenReturn(PASSWORD_VALUE); ProviderConfiguration result = converter.toModel(config); assertNotNull(result); assertEquals(PROVIDER_NAME_VALUE, result.getId()); assertEquals(MASTER_URL_VALUE, result.getValues().get(KUBERNETES_MASTER.inputKey())); assertEquals(USER_VALUE, result.getValues().get(KUBERNETES_AUTH_BASIC_USERNAME.inputKey())); assertEquals(PASSWORD_VALUE, result.getValues().get(KUBERNETES_AUTH_BASIC_PASSWORD.inputKey())); }
@Test public void testToModel() { OpenShiftProviderConfig config = mock(OpenShiftProviderConfig.class); when(config.getName()).thenReturn(PROVIDER_NAME_VALUE); when(config.getKubernetesMaster()).thenReturn(MASTER_URL_VALUE); when(config.getKubernetesAuthBasicUsername()).thenReturn(USER_VALUE); when(config.getKubernetesAuthBasicPassword()).thenReturn(PASSWORD_VALUE); ProviderConfiguration result = converter.toModel(config); assertNotNull(result); assertEquals(PROVIDER_NAME_VALUE, result.getId()); assertEquals(MASTER_URL_VALUE, result.getValues().get(KUBERNETES_MASTER.inputKey())); assertEquals(USER_VALUE, result.getValues().get(KUBERNETES_AUTH_BASIC_USERNAME.inputKey())); assertEquals(PASSWORD_VALUE, result.getValues().get(KUBERNETES_AUTH_BASIC_PASSWORD.inputKey())); }
@Override public OpenShiftProviderConfig toDomain(ProviderConfiguration modelValue) { if (modelValue == null) { return null; } OpenShiftProviderConfigImpl openShiftProviderConfig = new OpenShiftProviderConfigImpl(); openShiftProviderConfig.clear(); openShiftProviderConfig.setName(modelValue.getId()); openShiftProviderConfig.setKubernetesMaster(getStringValue(modelValue.getValues(), KUBERNETES_MASTER.inputKey())); openShiftProviderConfig.setKubernetesAuthBasicUsername(getStringValue(modelValue.getValues(), KUBERNETES_AUTH_BASIC_USERNAME.inputKey())); openShiftProviderConfig.setKubernetesAuthBasicPassword(getStringValue(modelValue.getValues(), KUBERNETES_AUTH_BASIC_PASSWORD.inputKey())); return openShiftProviderConfig; }
@Override public OpenShiftProviderConfig toDomain(ProviderConfiguration modelValue) { if (modelValue == null) { return null; } OpenShiftProviderConfigImpl openShiftProviderConfig = new OpenShiftProviderConfigImpl(); openShiftProviderConfig.clear(); openShiftProviderConfig.setName(modelValue.getId()); openShiftProviderConfig.setKubernetesMaster(getStringValue(modelValue.getValues(), KUBERNETES_MASTER.inputKey())); openShiftProviderConfig.setKubernetesAuthBasicUsername(getStringValue(modelValue.getValues(), KUBERNETES_AUTH_BASIC_USERNAME.inputKey())); openShiftProviderConfig.setKubernetesAuthBasicPassword(getStringValue(modelValue.getValues(), KUBERNETES_AUTH_BASIC_PASSWORD.inputKey())); return openShiftProviderConfig; }