use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getPathShouldProperlyReturnPath.
@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());
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getRawShouldProperlyReturnInputStream.
@Test
public void getRawShouldProperlyReturnInputStream() throws Exception {
FSDataInputStream inputStream = mock(FSDataInputStream.class);
Path path = new Path("./target");
PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), new InMemoryJobManager<>(), new 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)).thenReturn(inputStream);
assertEquals(inputStream, pcapService.getRawPcap("user", "jobId", 1));
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getPdmlShouldThrowException.
@Test
public void getPdmlShouldThrowException() throws Exception {
Path path = new Path("./target");
PcapToPdmlScriptWrapper pcapToPdmlScriptWrapper = spy(new PcapToPdmlScriptWrapper());
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);
ProcessBuilder pb = mock(ProcessBuilder.class);
doReturn(pb).when(pcapToPdmlScriptWrapper).getProcessBuilder("/path/to/pdml/script", "target");
when(pb.start()).thenThrow(new IOException("some exception"));
RestException e = assertThrows(RestException.class, () -> pcapService.getPdml("user", "jobId", 1));
assertEquals("some exception", e.getMessage());
}
Aggregations