@Before public void setUp() { when(module.getModuleName()).thenReturn(MODULE_NAME); queryItems = mockRuntimeQueryResultItemList(QUERY_ITEMS_SIZE); pipelineNames = mockPipelineNames(QUERY_ITEMS_SIZE); pipelineKeys = mockPipelineKeys(pipelineNames); service = new RuntimeServiceImpl(runtimeProvisioningService, pipelineService, providerService, runtimeChangeEvent, pipelineExecutionChangeEvent); }
private List<RuntimeQueryResultItem> mockRuntimeQueryResultItemList(int count) { List<RuntimeQueryResultItem> items = new ArrayList<>(); for (int i = 0; i < count; i++) { items.add(mockRuntimeQueryResultItem(Integer.toString(i), i)); } return items; }
@Test public void testDeleteRuntimeForced() { testDeleteRuntime(true); }
@Test public void getRuntimeItemByRuntimeKeyExisting() { ProviderKey providerKey = mock(ProviderKey.class); RuntimeKey runtimeKey = new RuntimeKey(providerKey, RUNTIME_ID); List<RuntimeQueryResultItem> singleResult = mockRuntimeQueryResultItemList(1); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(singleResult); RuntimeListItem expectedItem = buildExpectedResult(singleResult).iterator().next(); RuntimeListItem result = service.getRuntimeItem(runtimeKey); assertEquals(expectedItem, result); }
@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 getRuntimeItemByRuntimeKeyExisting() { ProviderKey providerKey = mock(ProviderKey.class); RuntimeKey runtimeKey = new RuntimeKey(providerKey, RUNTIME_ID); List<RuntimeQueryResultItem> singleResult = mockRuntimeQueryResultItemList(1); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(singleResult); RuntimeListItem expectedItem = buildExpectedResult(singleResult).iterator().next(); RuntimeListItem result = service.getRuntimeItem(runtimeKey); assertEquals(expectedItem, result); }
@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); }
@Before public void setUp() { when(project.getProjectName()).thenReturn(PROJECT_NAME); queryItems = mockRuntimeQueryResultItemList(QUERY_ITEMS_SIZE); pipelineNames = mockPipelineNames(QUERY_ITEMS_SIZE); pipelineKeys = mockPipelineKeys(pipelineNames); service = new RuntimeServiceImpl(runtimeProvisioningService, pipelineService, providerService, runtimeChangeEvent, pipelineExecutionChangeEvent); }
@Test public void getRuntimeItemByPipelineExecutionKeyExisting() { PipelineExecutionTraceKey traceKey = new PipelineExecutionTraceKey(PIPELINE_EXECUTION_ID); List<RuntimeQueryResultItem> singleResult = mockRuntimeQueryResultItemList(1); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(singleResult); RuntimeListItem expectedItem = buildExpectedResult(singleResult).iterator().next(); RuntimeListItem result = service.getRuntimeItem(traceKey); assertEquals(expectedItem, result); }
@Test public void testDeleteRuntimeNotForced() { testDeleteRuntime(false); }
private List<RuntimeQueryResultItem> mockRuntimeQueryResultItemList(int count) { List<RuntimeQueryResultItem> items = new ArrayList<>(); for (int i = 0; i < count; i++) { items.add(mockRuntimeQueryResultItem(Integer.toString(i), i)); } return items; }
@Test public void getRuntimeItemByPipelineExecutionKeyExisting() { PipelineExecutionTraceKey traceKey = new PipelineExecutionTraceKey(PIPELINE_EXECUTION_ID); List<RuntimeQueryResultItem> singleResult = mockRuntimeQueryResultItemList(1); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(singleResult); RuntimeListItem expectedItem = buildExpectedResult(singleResult).iterator().next(); RuntimeListItem result = service.getRuntimeItem(traceKey); assertEquals(expectedItem, result); }
@Test public void testDeleteRuntimeNotForced() { testDeleteRuntime(false); }
@Test public void testDeleteRuntimeForced() { testDeleteRuntime(true); }