use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapServiceImplTest method getConfigurationShouldReturnEmptyMapOnMissingJob.
@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);
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapServiceImplTest method getStatusShouldProperlyReturnStatus.
@Test
public void getStatusShouldProperlyReturnStatus() throws Exception {
MockPcapJob mockPcapJob = mock(MockPcapJob.class);
JobManager jobManager = mock(JobManager.class);
JobStatus actualJobStatus = new JobStatus().withJobId("jobId").withState(JobStatus.State.SUCCEEDED).withDescription("description").withPercentComplete(100.0);
Pageable pageable = mock(Pageable.class);
when(pageable.getSize()).thenReturn(2);
when(mockPcapJob.getStatus()).thenReturn(actualJobStatus);
when(mockPcapJob.isDone()).thenReturn(true);
when(mockPcapJob.get()).thenReturn(pageable);
when(jobManager.getJob("user", "jobId")).thenReturn(mockPcapJob);
PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, mockPcapJobSupplier, jobManager, pcapToPdmlScriptWrapper);
PcapStatus expectedPcapStatus = new PcapStatus();
expectedPcapStatus.setJobId("jobId");
expectedPcapStatus.setJobStatus(JobStatus.State.SUCCEEDED.name());
expectedPcapStatus.setDescription("description");
expectedPcapStatus.setPercentComplete(100.0);
expectedPcapStatus.setPageTotal(2);
assertEquals(expectedPcapStatus, pcapService.getJobStatus("user", "jobId"));
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapControllerIntegrationTest method testKillJob.
@Test
public void testKillJob() throws Exception {
MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
this.mockMvc.perform(get(pcapUrl + "/jobId123").with(httpBasic(user, password))).andExpect(status().isNotFound());
mockPcapJob.setStatus(new JobStatus().withJobId("jobId123").withState(JobStatus.State.RUNNING));
this.mockMvc.perform(post(pcapUrl + "/fixed").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(fixedJson)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobId").value("jobId123")).andExpect(jsonPath("$.jobStatus").value("RUNNING"));
mockPcapJob.setStatus(new JobStatus().withJobId("jobId123").withState(JobStatus.State.KILLED));
this.mockMvc.perform(delete(pcapUrl + "/kill/{id}", "jobId123").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobId").value("jobId123")).andExpect(jsonPath("$.jobStatus").value("KILLED"));
mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.KILLED));
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapControllerIntegrationTest method testFixedRequest.
@Test
public void testFixedRequest() throws Exception {
MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
mockPcapJob.setStatus(new JobStatus().withState(JobStatus.State.RUNNING));
this.mockMvc.perform(post(pcapUrl + "/fixed").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(fixedJson)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobStatus").value("RUNNING"));
assertEquals("/base/path", mockPcapJob.getBasePath());
assertEquals("/base/interim/result/path", mockPcapJob.getBaseInterrimResultPath());
assertEquals("/final/output/path", mockPcapJob.getFinalOutputPath());
assertEquals(10000000, mockPcapJob.getStartTimeNs());
assertEquals(20000000, mockPcapJob.getEndTimeNs());
assertEquals(2, mockPcapJob.getNumReducers());
assertTrue(mockPcapJob.getFilterImpl() instanceof FixedPcapFilter.Configurator);
Map<String, String> actualFixedFields = mockPcapJob.getFixedFields();
assertEquals("192.168.1.2", actualFixedFields.get(Constants.Fields.SRC_ADDR.getName()));
assertEquals("2000", actualFixedFields.get(Constants.Fields.SRC_PORT.getName()));
assertEquals("192.168.1.1", actualFixedFields.get(Constants.Fields.DST_ADDR.getName()));
assertEquals("1000", actualFixedFields.get(Constants.Fields.DST_PORT.getName()));
assertEquals("true", actualFixedFields.get(Constants.Fields.INCLUDES_REVERSE_TRAFFIC.getName()));
assertEquals("TCP", actualFixedFields.get(Constants.Fields.PROTOCOL.getName()));
assertEquals("filter", actualFixedFields.get(PcapHelper.PacketFields.PACKET_FILTER.getName()));
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapControllerIntegrationTest method testGetPdml.
@Test
public void testGetPdml() throws Exception {
MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.RUNNING));
this.mockMvc.perform(post(pcapUrl + "/fixed").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(fixedJson)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobId").value("jobId")).andExpect(jsonPath("$.jobStatus").value("RUNNING"));
Pageable<Path> pageable = new PcapPages(Arrays.asList(new Path("./target")));
mockPcapJob.setIsDone(true);
mockPcapJob.setPageable(pageable);
this.mockMvc.perform(get(pcapUrl + "/jobId/pdml?page=1").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.version").value("0")).andExpect(jsonPath("$.creator").value("wireshark/2.6.1")).andExpect(jsonPath("$.time").value("Thu Jun 28 14:14:38 2018")).andExpect(jsonPath("$.captureFile").value("/tmp/pcap-data-201806272004-289365c53112438ca55ea047e13a12a5+0001.pcap")).andExpect(jsonPath("$.packets[0].protos[0].name").value("geninfo")).andExpect(jsonPath("$.packets[0].protos[0].fields[0].name").value("num")).andExpect(jsonPath("$.packets[0].protos[1].name").value("ip")).andExpect(jsonPath("$.packets[0].protos[1].fields[0].name").value("ip.addr"));
this.mockMvc.perform(get(pcapUrl + "/jobId/pdml?page=0").with(httpBasic(user, password))).andExpect(status().isNotFound());
this.mockMvc.perform(get(pcapUrl + "/jobId/pdml?page=2").with(httpBasic(user, password))).andExpect(status().isNotFound());
}
Aggregations