use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getRawShouldThrowException.
@Test
public void getRawShouldThrowException() throws Exception {
Path path = new Path("./target");
PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), new InMemoryJobManager<>(), pcapToPdmlScriptWrapper));
FileSystem fileSystem = mock(FileSystem.class);
doReturn(fileSystem).when(pcapService).getFileSystem();
when(fileSystem.exists(path)).thenReturn(true);
doReturn(path).when(pcapService).getPath("user", "jobId", 1);
when(fileSystem.open(path)).thenThrow(new IOException("some exception"));
RestException e = assertThrows(RestException.class, () -> pcapService.getRawPcap("user", "jobId", 1));
assertEquals("some exception", e.getMessage());
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getPdmlShouldReturnNullOnNonexistentPath.
@Test
public void getPdmlShouldReturnNullOnNonexistentPath() throws Exception {
Path path = new Path("/some/path");
PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), new InMemoryJobManager<>(), pcapToPdmlScriptWrapper));
FileSystem fileSystem = mock(FileSystem.class);
doReturn(fileSystem).when(pcapService).getFileSystem();
when(fileSystem.exists(path)).thenReturn(false);
doReturn(path).when(pcapService).getPath("user", "jobId", 1);
assertNull(pcapService.getPdml("user", "jobId", 1));
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getRawShouldReturnNullOnInvalidPage.
@Test
public void getRawShouldReturnNullOnInvalidPage() throws Exception {
Path path = new Path("/some/path");
PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), new InMemoryJobManager<>(), pcapToPdmlScriptWrapper));
FileSystem fileSystem = mock(FileSystem.class);
doReturn(fileSystem).when(pcapService).getFileSystem();
assertNull(pcapService.getRawPcap("user", "jobId", 1));
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getStatusShouldThrowRestException.
@Test
public void getStatusShouldThrowRestException() 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.getJobStatus("user", "jobId"));
assertEquals("some job exception", e.getMessage());
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getPathShouldReturnNullOnInvalidPageSize.
@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));
}
Aggregations