CalvalusDescribeProcessOperation extends WpsOperation { public List<ProcessDescriptionType> getProcesses(String processorId) throws WpsProcessorNotFoundException { CalvalusLogger.getLogger().info("Getting processors " + processorId + " for user " + this.calvalusFacade.getRemoteUserName()); try { String[] processorIdArray = processorId.split(","); List<ProcessDescriptionType> processDescriptionTypeList = new ArrayList<>(); List<WpsProcess> processors = new ArrayList<>(); if (processorId.equalsIgnoreCase("all")) { processors.addAll(calvalusFacade.getProcessors()); processors.addAll(localFacade.getProcessors()); processDescriptionTypeList.addAll(getMultipleProcessType(processors)); } else if (processorIdArray.length > 1) { processors.addAll(getMultipleCalvalusProcessors(calvalusFacade, processorIdArray)); processors.addAll(getMultipleLocalProcessors(processorIdArray)); processDescriptionTypeList.addAll(getMultipleProcessType(processors)); } else { ProcessorNameConverter parser = new ProcessorNameConverter(processorId); WpsProcess processor = localFacade.getProcessor(parser); if (processor == null) { processor = calvalusFacade.getProcessor(parser); } if (processor == null) { throw new WpsProcessorNotFoundException("Unable to retrieve processor '" + parser.getProcessorIdentifier() + "'"); } processDescriptionTypeList.add(getSingleProcess(processor)); } return processDescriptionTypeList; } catch (IOException | ProductSetsNotAvailableException | InvalidProcessorIdException exception) { throw new WpsProcessorNotFoundException("Unable to retrieve the selected process(es)", exception); } } CalvalusDescribeProcessOperation(WpsRequestContext context); List<ProcessDescriptionType> getProcesses(String processorId);  }
@Test public void canGetSingleProcess() throws Exception { ProductSet mockProductSet = mock(ProductSet.class); when(mockProductSet.getProductType()).thenReturn("inputProductType"); ProductSet[] mockProductSets = new ProductSet[]{mockProductSet}; ProcessorNameConverter mockProcessorNameConverter = mock(ProcessorNameConverter.class); CalvalusProcessor calvalusProcessor1 = getProcess1(); when(mockCalvalusFacade.getProcessor(any(ProcessorNameConverter.class))).thenReturn(calvalusProcessor1); when(mockCalvalusFacade.getProductSets()).thenReturn(mockProductSets); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); PowerMockito.whenNew(ProcessorNameConverter.class).withAnyArguments().thenReturn(mockProcessorNameConverter); describeProcessOperation = new CalvalusDescribeProcessOperation(mockRequestContext); List<ProcessDescriptionType> processes = describeProcessOperation.getProcesses("process1"); assertThat(processes.size(), equalTo(1)); assertThat(processes.get(0).getIdentifier().getValue(), equalTo("beam-buildin~1.0~BandMaths")); assertThat(processes.get(0).getTitle().getValue(), equalTo("beam-buildin~1.0~BandMaths")); assertThat(processes.get(0).getAbstract().getValue(), equalTo("Some description")); }
@Test public void canGetMultipleProcesses() throws Exception { ProductSet mockProductSet = mock(ProductSet.class); when(mockProductSet.getProductType()).thenReturn("inputProductType"); ProductSet[] mockProductSets = new ProductSet[]{mockProductSet}; ProcessorNameConverter mockProcessorNameConverter = mock(ProcessorNameConverter.class); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); PowerMockito.whenNew(ProcessorNameConverter.class).withAnyArguments().thenReturn(mockProcessorNameConverter); CalvalusProcessor calvalusProcessor1 = getProcess1(); CalvalusProcessor calvalusProcessor2 = getProcess2(); when(mockCalvalusFacade.getProcessor(any(ProcessorNameConverter.class))).thenReturn(calvalusProcessor1, calvalusProcessor2); when(mockCalvalusFacade.getProductSets()).thenReturn(mockProductSets); describeProcessOperation = new CalvalusDescribeProcessOperation(mockRequestContext); List<ProcessDescriptionType> processes = describeProcessOperation.getProcesses("process1,process2"); assertThat(processes.size(), equalTo(2)); assertThat(processes.get(0).getIdentifier().getValue(), equalTo("beam-buildin~1.0~BandMaths")); assertThat(processes.get(0).getTitle().getValue(), equalTo("beam-buildin~1.0~BandMaths")); assertThat(processes.get(0).getAbstract().getValue(), equalTo("Some description")); assertThat(processes.get(1).getIdentifier().getValue(), equalTo("beam-buildin~1.0~urban-tep-indices")); assertThat(processes.get(1).getTitle().getValue(), equalTo("beam-buildin~1.0~urban-tep-indices")); assertThat(processes.get(1).getAbstract().getValue(), equalTo("Some description")); }
@Test public void canGetAllProcesses() throws Exception { ProductSet mockProductSet = mock(ProductSet.class); when(mockProductSet.getProductType()).thenReturn("inputProductType"); ProductSet[] mockProductSets = new ProductSet[]{mockProductSet}; ProcessorNameConverter mockProcessorNameConverter = mock(ProcessorNameConverter.class); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); PowerMockito.whenNew(ProcessorNameConverter.class).withAnyArguments().thenReturn(mockProcessorNameConverter); List<WpsProcess> mockProcessorList = getMockProcessList(); when(mockCalvalusFacade.getProcessors()).thenReturn(mockProcessorList); when(mockCalvalusFacade.getProductSets()).thenReturn(mockProductSets); describeProcessOperation = new CalvalusDescribeProcessOperation(mockRequestContext); List<ProcessDescriptionType> processes = describeProcessOperation.getProcesses("all"); assertThat(processes.size(), equalTo(3)); assertThat(processes.get(0).getIdentifier().getValue(), equalTo("beam-buildin~1.0~BandMaths")); assertThat(processes.get(0).getTitle().getValue(), equalTo("beam-buildin~1.0~BandMaths")); assertThat(processes.get(0).getAbstract().getValue(), equalTo("Some description")); assertThat(processes.get(1).getIdentifier().getValue(), equalTo("beam-buildin~1.0~urban-tep-indices")); assertThat(processes.get(1).getTitle().getValue(), equalTo("beam-buildin~1.0~urban-tep-indices")); assertThat(processes.get(1).getAbstract().getValue(), equalTo("Some description")); assertThat(processes.get(2).getIdentifier().getValue(), equalTo("urbantep-local-test~1.0~Subset")); assertThat(processes.get(2).getTitle().getValue(), equalTo("urbantep-local-test~1.0~Subset")); assertThat(processes.get(2).getAbstract().getValue(), equalTo(null)); }
@Test(expected = WpsProcessorNotFoundException.class) public void canThrowExceptionWhenProcessorIsNull() throws Exception { ProcessorNameConverter mockProcessorNameConverter = mock(ProcessorNameConverter.class); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); PowerMockito.whenNew(ProcessorNameConverter.class).withAnyArguments().thenReturn(mockProcessorNameConverter); when(mockCalvalusFacade.getProcessor(any(ProcessorNameConverter.class))).thenReturn(null); describeProcessOperation = new CalvalusDescribeProcessOperation(mockRequestContext); describeProcessOperation.getProcesses("process1"); }
@Test(expected = WpsProcessorNotFoundException.class) public void canThrowExceptionWhenOneOfProcessorsNotAvailable() throws Exception { ProcessorNameConverter mockProcessorNameConverter = mock(ProcessorNameConverter.class); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); PowerMockito.whenNew(ProcessorNameConverter.class).withAnyArguments().thenReturn(mockProcessorNameConverter); CalvalusProcessor calvalusProcessor1 = getProcess1(); CalvalusProcessor calvalusProcessor2 = getProcess2(); when(mockCalvalusFacade.getProcessor(any(ProcessorNameConverter.class))).thenReturn(calvalusProcessor1, null, calvalusProcessor2); describeProcessOperation = new CalvalusDescribeProcessOperation(mockRequestContext); describeProcessOperation.getProcesses("process1,invalidProcessId,process2"); }
@Test(expected = WpsProcessorNotFoundException.class) public void canCatchInvalidProcessorIdException() throws Exception { PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); PowerMockito.whenNew(ProcessorNameConverter.class).withAnyArguments().thenThrow(new InvalidProcessorIdException("processorId not found")); describeProcessOperation = new CalvalusDescribeProcessOperation(mockRequestContext); describeProcessOperation.getProcesses("process1"); }
@Test(expected = WpsProcessorNotFoundException.class) public void canCatchIOException() throws Exception { ProductSet mockProductSet = mock(ProductSet.class); when(mockProductSet.getProductType()).thenReturn("inputProductType"); ProcessorNameConverter mockProcessorNameConverter = mock(ProcessorNameConverter.class); CalvalusProcessor calvalusProcessor1 = getProcess1(); when(mockCalvalusFacade.getProcessor(any(ProcessorNameConverter.class))).thenReturn(calvalusProcessor1); when(mockCalvalusFacade.getProductSets()).thenThrow(new IOException("IO Exception")); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); PowerMockito.whenNew(ProcessorNameConverter.class).withAnyArguments().thenReturn(mockProcessorNameConverter); describeProcessOperation = new CalvalusDescribeProcessOperation(mockRequestContext); describeProcessOperation.getProcesses("process1"); }