@Override public boolean hasRuntimes(final ProviderKey providerKey) { checkNotNull("providerKey", providerKey); return !runtimeService.getRuntimeItems(providerKey).isEmpty(); } }
@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); }
@Test public void testHasRuntimesTrue() { Collection<RuntimeListItem> runtimes = mock(Collection.class); when(runtimeService.getRuntimeItems(providerKey)).thenReturn(runtimes); when(runtimes.isEmpty()).thenReturn(false); assertTrue(service.hasRuntimes(providerKey)); verify(runtimeService, times(1)).getRuntimeItems(providerKey); }
@Test public void testHasRuntimesTrue() { Collection<RuntimeListItem> runtimes = mock(Collection.class); when(runtimeService.getRuntimeItems(providerKey)).thenReturn(runtimes); when(runtimes.isEmpty()).thenReturn(false); assertTrue(service.hasRuntimes(providerKey)); verify(runtimeService, times(1)).getRuntimeItems(providerKey); }
@Test public void testHasRuntimesFalse() { Collection<RuntimeListItem> runtimes = mock(Collection.class); when(runtimeService.getRuntimeItems(providerKey)).thenReturn(runtimes); when(runtimes.isEmpty()).thenReturn(true); assertFalse(service.hasRuntimes(providerKey)); verify(runtimeService, times(1)).getRuntimeItems(providerKey); } }
@Test public void testHasRuntimesFalse() { Collection<RuntimeListItem> runtimes = mock(Collection.class); when(runtimeService.getRuntimeItems(providerKey)).thenReturn(runtimes); when(runtimes.isEmpty()).thenReturn(true); assertFalse(service.hasRuntimes(providerKey)); verify(runtimeService, times(1)).getRuntimeItems(providerKey); } }
@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 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 testGetRuntimesInfoProviderExisting() { //the provider exists. when(providerService.getProvider(providerKey)).thenReturn(provider); when(runtimeService.getRuntimeItems(providerKey)).thenReturn(runtimeListItems); RuntimesInfo info = service.getRuntimesInfo(providerKey); assertNotNull(info); assertEquals(provider, info.getProvider()); assertEquals(runtimeListItems, info.getRuntimeItems()); verify(providerService, times(1)).getProvider(providerKey); verify(runtimeService, times(1)).getRuntimeItems(providerKey); }
@Test public void testGetRuntimesInfoProviderExisting() { //the provider exists. when(providerService.getProvider(providerKey)).thenReturn(provider); when(runtimeService.getRuntimeItems(providerKey)).thenReturn(runtimeListItems); RuntimesInfo info = service.getRuntimesInfo(providerKey); assertNotNull(info); assertEquals(provider, info.getProvider()); assertEquals(runtimeListItems, info.getRuntimeItems()); verify(providerService, times(1)).getProvider(providerKey); verify(runtimeService, times(1)).getRuntimeItems(providerKey); }
@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 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); }