use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapControllerIntegrationTest method testGetFixedFilterConfiguration.
@Test
public void testGetFixedFilterConfiguration() 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"));
this.mockMvc.perform(get(pcapUrl + "/jobId/config").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.basePath").value("/base/path")).andExpect(jsonPath("$.finalOutputPath").value("/final/output/path")).andExpect(jsonPath("$.startTimeMs").value(10)).andExpect(jsonPath("$.endTimeMs").value(20)).andExpect(jsonPath("$.numReducers").value(2)).andExpect(jsonPath("$.ipSrcAddr").value("192.168.1.2")).andExpect(jsonPath("$.ipDstAddr").value("192.168.1.1")).andExpect(jsonPath("$.ipSrcPort").value("2000")).andExpect(jsonPath("$.ipDstPort").value("1000")).andExpect(jsonPath("$.protocol").value("TCP")).andExpect(jsonPath("$.packetFilter").value("filter")).andExpect(jsonPath("$.includeReverse").value("true"));
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapControllerIntegrationTest method testKillNonExistentJobReturns404.
@Test
public void testKillNonExistentJobReturns404() throws Exception {
MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
this.mockMvc.perform(get(pcapUrl + "/jobId123").with(httpBasic(user, password))).andExpect(status().isNotFound());
this.mockMvc.perform(delete(pcapUrl + "/kill/{id}", "jobId123").with(httpBasic(user, password))).andExpect(status().isNotFound());
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapControllerIntegrationTest method testGetStatus.
@Test
public void testGetStatus() 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"));
mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.SUCCEEDED));
Pageable<Path> pageable = new PcapPages(Arrays.asList(new Path("path1"), new Path("path1")));
mockPcapJob.setIsDone(true);
mockPcapJob.setPageable(pageable);
this.mockMvc.perform(get(pcapUrl + "/jobId").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobStatus").value("SUCCEEDED")).andExpect(jsonPath("$.pageTotal").value(2));
mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.FINALIZING));
this.mockMvc.perform(get(pcapUrl + "/jobId").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobStatus").value("FINALIZING"));
mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.FAILED));
this.mockMvc.perform(get(pcapUrl + "/jobId").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobStatus").value("FAILED"));
mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.KILLED));
this.mockMvc.perform(get(pcapUrl + "/jobId").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobStatus").value("KILLED"));
this.mockMvc.perform(get(pcapUrl + "/someJobId").with(httpBasic(user, password))).andExpect(status().isNotFound());
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapControllerIntegrationTest method testFixedRequestDefaults.
@Test
public void testFixedRequestDefaults() throws Exception {
MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
mockPcapJob.setStatus(new JobStatus().withState(JobStatus.State.RUNNING));
long beforeJobTime = System.currentTimeMillis();
this.mockMvc.perform(post(pcapUrl + "/fixed").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(fixedWithDefaultsJson)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobStatus").value("RUNNING"));
assertEquals("/apps/metron/pcap/input", mockPcapJob.getBasePath());
assertEquals("/apps/metron/pcap/interim", mockPcapJob.getBaseInterrimResultPath());
assertEquals("/apps/metron/pcap/output", mockPcapJob.getFinalOutputPath());
assertEquals(0, mockPcapJob.getStartTimeNs());
assertTrue(beforeJobTime < mockPcapJob.getEndTimeNs() / 1000000);
assertTrue(System.currentTimeMillis() > mockPcapJob.getEndTimeNs() / 1000000);
assertEquals(10, 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()));
}
Aggregations