CalvalusFacade extends ProcessFacade { public ProductSet[] getProductSets() throws ProductionException, IOException { List<ProductSet> productSets = new ArrayList<>(); InventoryService inventoryService = getServices().getInventoryService(); productSets.addAll(Arrays.asList(inventoryService.getProductSets(remoteUserName, ""))); productSets.addAll(Arrays.asList(inventoryService.getProductSets(remoteUserName, "user=" + remoteUserName))); productSets.addAll(Arrays.asList(inventoryService.getProductSets(remoteUserName, "user=all"))); return productSets.toArray(new ProductSet[productSets.size()]); } CalvalusFacade(WpsRequestContext wpsRequestContext); @Override LocalProductionStatus orderProductionAsynchronous(Execute executeRequest); @Override LocalProductionStatus orderProductionSynchronous(Execute executeRequest); @Override List<String> getProductResultUrls(String jobId); @Override void stageProduction(String jobId); @Override void observeStagingStatus(String jobId); @Override void generateProductMetadata(String jobId); @Override List<WpsProcess> getProcessors(); @Override WpsProcess getProcessor(ProcessorNameConverter parser); ProductSet[] getProductSets(); Production getProduction(String jobId); String[] getRegionFiles(); String[][] loadRegionDataInfo(String url);  }
@Test public void testGetProductSets() throws Exception { PowerMockito.mockStatic(CalvalusProductionService.class); ServiceContainer mockServiceContainer = mock(ServiceContainer.class); PowerMockito.when(CalvalusProductionService.getServiceContainerSingleton()).thenReturn(mockServiceContainer); InventoryService mockInventoryService = mock(InventoryService.class); ProductSet[] mockProductSets = new ProductSet[]{}; when(mockInventoryService.getProductSets(anyString(), anyString())).thenReturn(mockProductSets); PowerMockito.when(mockServiceContainer.getInventoryService()).thenReturn(mockInventoryService); ArgumentCaptor<String> arg1 = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class); calvalusFacade = new CalvalusFacade(mockRequestContext); calvalusFacade.getProductSets(); verify(mockInventoryService, times(3)).getProductSets(arg1.capture(), arg2.capture()); assertThat((arg1.getAllValues().get(0)), equalTo("mockUserName")); assertThat((arg2.getAllValues().get(0)), equalTo("")); assertThat((arg1.getAllValues().get(1)), equalTo("mockUserName")); assertThat((arg2.getAllValues().get(1)), equalTo("user=mockUserName")); }
@Test(expected = IOException.class) public void canThrowIOExceptionWhenGetNullProductSets() throws Exception { PowerMockito.mockStatic(CalvalusProductionService.class); ServiceContainer mockServiceContainer = mock(ServiceContainer.class); InventoryService mockInventoryService = mock(InventoryService.class); PowerMockito.when(mockServiceContainer.getInventoryService()).thenReturn(mockInventoryService); ProductSet[] mockProductSets = new ProductSet[]{}; when(mockInventoryService.getProductSets("mockUserName", "")).thenReturn(mockProductSets); when(mockInventoryService.getProductSets("mockUserName", "user=mockUserName")).thenThrow(new IOException("null productsets")); PowerMockito.when(CalvalusProductionService.getServiceContainerSingleton()).thenReturn(mockServiceContainer); calvalusFacade = new CalvalusFacade(mockRequestContext); calvalusFacade.getProductSets(); }