PcapServiceImpl implements PcapService { @Override public Map<String, Object> getConfiguration(String username, String jobId) throws RestException { Map<String, Object> configuration = new HashMap<>(); try { Statusable<Path> statusable = jobManager.getJob(username, jobId); if (statusable != null) { Map<String, Object> jobConfiguration = statusable.getConfiguration(); configuration.put(PcapOptions.BASE_PATH.getKey(), PcapOptions.BASE_PATH.get(jobConfiguration, String.class)); configuration.put(PcapOptions.FINAL_OUTPUT_PATH.getKey(), PcapOptions.FINAL_OUTPUT_PATH.get(jobConfiguration, String.class)); configuration.put(PcapOptions.START_TIME_MS.getKey(), PcapOptions.START_TIME_MS.get(jobConfiguration, Long.class)); configuration.put(PcapOptions.END_TIME_MS.getKey(), PcapOptions.END_TIME_MS.get(jobConfiguration, Long.class)); configuration.put(PcapOptions.NUM_REDUCERS.getKey(), PcapOptions.NUM_REDUCERS.get(jobConfiguration, Integer.class)); boolean isFixedFilter = PcapOptions.FILTER_IMPL.get(jobConfiguration, PcapFilterConfigurator.class) instanceof FixedPcapFilter.Configurator; if (isFixedFilter) { configuration.put(FixedPcapOptions.IP_SRC_ADDR.getKey(), FixedPcapOptions.IP_SRC_ADDR.get(jobConfiguration, String.class)); configuration.put(FixedPcapOptions.IP_DST_ADDR.getKey(), FixedPcapOptions.IP_DST_ADDR.get(jobConfiguration, String.class)); configuration.put(FixedPcapOptions.IP_SRC_PORT.getKey(), FixedPcapOptions.IP_SRC_PORT.get(jobConfiguration, Integer.class)); configuration.put(FixedPcapOptions.IP_DST_PORT.getKey(), FixedPcapOptions.IP_DST_PORT.get(jobConfiguration, Integer.class)); configuration.put(FixedPcapOptions.PROTOCOL.getKey(), FixedPcapOptions.PROTOCOL.get(jobConfiguration, String.class)); configuration.put(FixedPcapOptions.PACKET_FILTER.getKey(), FixedPcapOptions.PACKET_FILTER.get(jobConfiguration, String.class)); configuration.put(FixedPcapOptions.INCLUDE_REVERSE.getKey(), FixedPcapOptions.INCLUDE_REVERSE.get(jobConfiguration, Boolean.class)); } else { configuration.put(QueryPcapOptions.QUERY.getKey(), QueryPcapOptions.QUERY.get(jobConfiguration, String.class)); } } } catch (JobNotFoundException e) { LOG.warn(String.format("Could not get job configuration. Job not found for user %s with job id %s", username, jobId)); } catch (JobException e) { throw new RestException(e); } return configuration; } @Autowired  PcapServiceImpl(Environment environment, Configuration configuration, PcapJobSupplier pcapJobSupplier, JobManager<Path> jobManager, PcapToPdmlScriptWrapper pcapToPdmlScriptWrapper); @Override PcapStatus submit(String username, PcapRequest pcapRequest); @Override PcapStatus getJobStatus(String username, String jobId); @Override List<PcapStatus> getJobStatus(String username, JobStatus.State state); @Override PcapStatus killJob(String username, String jobId); @Override Path getPath(String username, String jobId, Integer page); @Override Pdml getPdml(String username, String jobId, Integer page); @Override InputStream getRawPcap(String username, String jobId, Integer page); @Override Map<String, Object> getConfiguration(String username, String jobId);  }
@Test public void getConfigurationShouldReturnEmptyMapOnMissingJob() throws Exception { MockPcapJob mockPcapJob = mock(MockPcapJob.class); JobManager jobManager = mock(JobManager.class); doThrow(new JobNotFoundException("Not found test exception.")).when(jobManager).getJob("user", "jobId"); PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, mockPcapJobSupplier, jobManager, pcapToPdmlScriptWrapper); Map<String, Object> configuration = pcapService.getConfiguration("user", "jobId"); assertEquals(new HashMap<>(), configuration); }
@Test public void getConfigurationShouldThrowRestException() throws Exception { JobManager jobManager = mock(JobManager.class); when(jobManager.getJob("user", "jobId")).thenThrow(new JobException("some job exception")); PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), jobManager, pcapToPdmlScriptWrapper); RestException e = assertThrows(RestException.class, () -> pcapService.getConfiguration("user", "jobId")); assertEquals("some job exception", e.getMessage()); }