use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getRawShouldReturnNullOnNonexistentPath.
@Test
public void getRawShouldReturnNullOnNonexistentPath() 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.getRawPcap("user", "jobId", 1));
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method fixedShouldThrowRestException.
@Test
public void fixedShouldThrowRestException() throws Exception {
FixedPcapRequest fixedPcapRequest = new FixedPcapRequest();
JobManager jobManager = mock(JobManager.class);
PcapJobSupplier pcapJobSupplier = new PcapJobSupplier();
PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, pcapJobSupplier, jobManager, pcapToPdmlScriptWrapper));
FileSystem fileSystem = mock(FileSystem.class);
doReturn(fileSystem).when(pcapService).getFileSystem();
when(jobManager.submit(pcapJobSupplier, "user")).thenThrow(new JobException("some job exception"));
RestException e = assertThrows(RestException.class, () -> pcapService.submit("user", fixedPcapRequest));
assertEquals("some job exception", e.getMessage());
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getConfigurationShouldThrowRestException.
@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());
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getPdmlShouldGetPdml.
@Test
public void getPdmlShouldGetPdml() 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);
doReturn(new ByteArrayInputStream(pdmlXml.getBytes(StandardCharsets.UTF_8))).when(pcapToPdmlScriptWrapper).getRawInputStream(fileSystem, path);
ProcessBuilder pb = mock(ProcessBuilder.class);
Process p = mock(Process.class);
OutputStream outputStream = new ByteArrayOutputStream();
when(p.getOutputStream()).thenReturn(outputStream);
when(p.isAlive()).thenReturn(true);
when(p.getInputStream()).thenReturn(new ByteArrayInputStream(pdmlXml.getBytes(StandardCharsets.UTF_8)));
doReturn(pb).when(pcapToPdmlScriptWrapper).getProcessBuilder(any());
when(pb.start()).thenReturn(p);
assertEquals(JSONUtils.INSTANCE.load(expectedPdml, Pdml.class), pcapService.getPdml("user", "jobId", 1));
}
use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.
the class PcapServiceImplTest method getStatusShouldReturnNullOnMissingStatus.
@Test
public void getStatusShouldReturnNullOnMissingStatus() throws Exception {
JobManager jobManager = new InMemoryJobManager();
PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), jobManager, pcapToPdmlScriptWrapper);
assertNull(pcapService.getJobStatus("user", "jobId"));
}
Aggregations