PcapServiceImpl implements PcapService { @Override public Path getPath(String username, String jobId, Integer page) throws RestException { Path path = null; try { Statusable<Path> statusable = jobManager.getJob(username, jobId); if (statusable != null && statusable.isDone()) { Pageable<Path> pageable = statusable.get(); if (pageable != null && page <= pageable.getSize() && page > 0) { path = pageable.getPage(page - 1); } } } catch (JobNotFoundException e) { LOG.warn(String.format("Could not get path for page %s. Job not found for user %s with job id %s", page, username, jobId)); } catch (JobException | InterruptedException e) { throw new RestException(e); } return path; } @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 getPathShouldProperlyReturnPath() throws Exception { Path actualPath = new Path("/path"); MockPcapJob mockPcapJob = mock(MockPcapJob.class); JobManager jobManager = mock(JobManager.class); Pageable pageable = mock(Pageable.class); PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), jobManager, pcapToPdmlScriptWrapper); when(pageable.getSize()).thenReturn(2); when(mockPcapJob.isDone()).thenReturn(true); when(mockPcapJob.get()).thenReturn(pageable); when(pageable.getPage(0)).thenReturn(actualPath); when(jobManager.getJob("user", "jobId")).thenReturn(mockPcapJob); assertEquals("/path", pcapService.getPath("user", "jobId", 1).toUri().getPath()); }
@Test public void getPathShouldReturnNullOnInvalidPageSize() throws Exception { MockPcapJob mockPcapJob = mock(MockPcapJob.class); JobManager jobManager = mock(JobManager.class); Pageable pageable = mock(Pageable.class); PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), jobManager, pcapToPdmlScriptWrapper); when(pageable.getSize()).thenReturn(2); when(mockPcapJob.isDone()).thenReturn(true); when(mockPcapJob.get()).thenReturn(pageable); when(jobManager.getJob("user", "jobId")).thenReturn(mockPcapJob); assertNull(pcapService.getPath("user", "jobId", 0)); assertNull(pcapService.getPath("user", "jobId", 3)); }