public static final ProviderKey mockProviderKey(ProviderTypeKey providerTypeKey, String suffix) { return new ProviderKey(providerTypeKey, "ProviderKey.id." + suffix); }
@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 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)); }
@Before public void setUp() { when(providerType.getProviderTypeName()).thenReturn(PROVIDER_TYPE_NAME); when(providerType.getVersion()).thenReturn(PROVIDER_VERSION); when(provider.getId()).thenReturn(PROVIDER_ID); when(provider.getProviderType()).thenReturn(providerType); when(provider.getConfig()).thenReturn(providerConfig); providerTypeKey = new ProviderTypeKey(PROVIDER_TYPE_NAME, PROVIDER_VERSION); providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); converter = new ProviderConverterImpl(handlerRegistry); }
@Before public void setUp() { when(providerType.getProviderTypeName()).thenReturn(PROVIDER_TYPE_NAME); when(providerType.getVersion()).thenReturn(PROVIDER_VERSION); when(provider.getId()).thenReturn(PROVIDER_ID); when(provider.getProviderType()).thenReturn(providerType); when(provider.getConfig()).thenReturn(providerConfig); providerTypeKey = new ProviderTypeKey(PROVIDER_TYPE_NAME, PROVIDER_VERSION); providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); converter = new ProviderConverterImpl(handlerRegistry); }
@Test public void testCreateRuntimeWhenProviderNotExists() { ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); expectedException.expectMessage("No provider was found for providerKey: " + providerKey); service.createRuntime(providerKey, RUNTIME_ID, PIPELINE_KEY, null); verify(pipelineService, never()).runPipeline(anyString(), any(Input.class), eq(true)); }
@Test public void testCreateRuntimeWhenProviderNotExists() { ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); expectedException.expectMessage("No provider was found for providerKey: " + providerKey); service.createRuntime(providerKey, RUNTIME_ID, PIPELINE_KEY, null); verify(pipelineService, never()).runPipeline(anyString(), any(Input.class), eq(true)); }
@Test public void testGetRuntimeItems() { ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(queryItems); Collection<RuntimeListItem> result = service.getRuntimeItems(providerKey); Collection<RuntimeListItem> expectedResult = buildExpectedResult(queryItems); assertEquals(expectedResult, result); }
@Test public void testCreateRuntimeWhenProviderExistsButRuntimeNameExitsts() { Provider provider = mock(Provider.class); ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); List<RuntimeQueryResultItem> items = mock(List.class); //the provider exists, so validation continues when(providerService.getProvider(providerKey)).thenReturn(provider); //but the runtime name already exists. when(runtimeProvisioningService.executeQuery(RuntimeQueryBuilder.newInstance() .withRuntimeName(RUNTIME_ID) .build())).thenReturn(items); when(items.isEmpty()).thenReturn(false); expectedException.expectMessage("A runtime with the given name already exists: " + RUNTIME_ID); service.createRuntime(providerKey, RUNTIME_ID, PIPELINE_KEY, mock(Map.class)); verify(pipelineService, never()).runPipeline(anyString(), any(Input.class), eq(true)); }
@Test public void testCreateRuntimeWhenProviderExistsButRuntimeNameExitsts() { Provider provider = mock(Provider.class); ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); List<RuntimeQueryResultItem> items = mock(List.class); //the provider exists, so validation continues when(providerService.getProvider(providerKey)).thenReturn(provider); //but the runtime name already exists. when(runtimeProvisioningService.executeQuery(RuntimeQueryBuilder.newInstance() .withRuntimeName(RUNTIME_ID) .build())).thenReturn(items); when(items.isEmpty()).thenReturn(false); expectedException.expectMessage("A runtime with the given name already exists: " + RUNTIME_ID); service.createRuntime(providerKey, RUNTIME_ID, PIPELINE_KEY, mock(Map.class)); verify(pipelineService, never()).runPipeline(anyString(), any(Input.class), eq(true)); }
@Test public void testGetRuntimeItems() { ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(queryItems); Collection<RuntimeListItem> result = service.getRuntimeItems(providerKey); Collection<RuntimeListItem> expectedResult = buildExpectedResult(queryItems); assertEquals(expectedResult, result); }
@Test public void testGetProviderNotExisting() { //create an arbitrary not existing key. ProviderTypeKey providerTypeKey = new ProviderTypeKey("not exist", "not exist"); ProviderKey providerKey = new ProviderKey(providerTypeKey, "not exist"); Provider provider = service.getProvider(providerKey); assertNull(provider); }
@Test public void testGetProviderNotExisting() { //create an arbitrary not existing key. ProviderTypeKey providerTypeKey = new ProviderTypeKey("not exist", "not exist"); ProviderKey providerKey = new ProviderKey(providerTypeKey, "not exist"); Provider provider = service.getProvider(providerKey); assertNull(provider); }
ProviderTypeKey providerTypeKey = new ProviderTypeKey(providersSpi.get(i).getProviderType().getProviderTypeName(), providersSpi.get(i).getProviderType().getVersion()); ProviderKey providerKey = new ProviderKey(providerTypeKey, providersSpi.get(i).getId());
ProviderTypeKey providerTypeKey = new ProviderTypeKey(providersSpi.get(i).getProviderType().getProviderTypeName(), providersSpi.get(i).getProviderType().getVersion()); ProviderKey providerKey = new ProviderKey(providerTypeKey, providersSpi.get(i).getId());
@Test public void testCreateRuntimeSuccessful() { Provider provider = mock(Provider.class); ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); Map<String, String> params = PipelineInputBuilderTest.mockParams(PARAMS_COUNT); List<RuntimeQueryResultItem> items = mock(List.class); when(providerService.getProvider(providerKey)).thenReturn(provider); when(runtimeProvisioningService.executeQuery(RuntimeQueryBuilder.newInstance() .withRuntimeName(RUNTIME_ID) .build())).thenReturn(items); when(items.isEmpty()).thenReturn(true); Input expectedInput = PipelineInputBuilder.newInstance() .withProvider(providerKey) .withRuntimeName(RUNTIME_ID) .withParams(params).build(); service.createRuntime(providerKey, RUNTIME_ID, PIPELINE_KEY, params); verify(pipelineService, times(1)).runPipeline(PIPELINE, expectedInput, true); }
@Test public void testCreateRuntimeSuccessful() { Provider provider = mock(Provider.class); ProviderTypeKey providerTypeKey = new ProviderTypeKey(PROVIDER_NAME, PROVIDER_VERSION); ProviderKey providerKey = new ProviderKey(providerTypeKey, PROVIDER_ID); Map<String, String> params = PipelineInputBuilderTest.mockParams(PARAMS_COUNT); List<RuntimeQueryResultItem> items = mock(List.class); when(providerService.getProvider(providerKey)).thenReturn(provider); when(runtimeProvisioningService.executeQuery(RuntimeQueryBuilder.newInstance() .withRuntimeName(RUNTIME_ID) .build())).thenReturn(items); when(items.isEmpty()).thenReturn(true); Input expectedInput = PipelineInputBuilder.newInstance() .withProvider(providerKey) .withRuntimeName(RUNTIME_ID) .withParams(params).build(); service.createRuntime(providerKey, RUNTIME_ID, PIPELINE_KEY, params); verify(pipelineService, times(1)).runPipeline(PIPELINE, expectedInput, true); }
/** * @param provider A provider representation in the guvnor-ala core domain. * @return the converted version of the provider in the format managed by the UI related modules. */ @Override public Provider toModel(org.guvnor.ala.runtime.providers.Provider provider) { Provider result = null; if (provider != null) { ProviderTypeKey providerTypeKey = new ProviderTypeKey(provider.getProviderType().getProviderTypeName(), provider.getProviderType().getVersion()); ProviderKey providerKey = new ProviderKey(providerTypeKey, provider.getId()); final BackendProviderHandler handler = handlerRegistry.ensureHandler(providerTypeKey); @SuppressWarnings("unchecked") final ProviderConfiguration providerConfiguration = (ProviderConfiguration) handler.getProviderConfigConverter().toModel(provider.getConfig()); result = new Provider(providerKey, providerConfiguration); } return result; } }
@Test public void testGetProviderExisting() { //pick one of the existing providers. org.guvnor.ala.runtime.providers.Provider providerSpi = providersSpi.get(2); //create a key for finding it. ProviderTypeKey providerTypeKey = new ProviderTypeKey(providerSpi.getProviderType().getProviderTypeName(), providerSpi.getProviderType().getVersion()); ProviderKey providerKey = new ProviderKey(providerTypeKey, providerSpi.getId()); Provider provider = service.getProvider(providerKey); assertNotNull(provider); assertEquals(providers.get(2).getKey(), provider.getKey()); }
@Test public void testGetProviderExisting() { //pick one of the existing providers. org.guvnor.ala.runtime.providers.Provider providerSpi = providersSpi.get(2); //create a key for finding it. ProviderTypeKey providerTypeKey = new ProviderTypeKey(providerSpi.getProviderType().getProviderTypeName(), providerSpi.getProviderType().getVersion()); ProviderKey providerKey = new ProviderKey(providerTypeKey, providerSpi.getId()); Provider provider = service.getProvider(providerKey); assertNotNull(provider); assertEquals(providers.get(2).getKey(), provider.getKey()); }