use of org.apache.metron.job.JobStatus in project metron by apache.
the class PcapControllerIntegrationTest method testGetQueryFilterConfiguration.
@Test
public void testGetQueryFilterConfiguration() throws Exception {
MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.RUNNING));
this.mockMvc.perform(post(pcapUrl + "/query").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(queryJson)).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("$.query").value("query"));
}
use of org.apache.metron.job.JobStatus in project metron by apache.
the class PcapControllerIntegrationTest method testRawDownload.
@Test
public void testRawDownload() throws Exception {
String pcapFileContents = "pcap file contents";
FileUtils.write(new File("./target/pcapFile"), pcapFileContents, "UTF8");
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/pcapFile")));
mockPcapJob.setIsDone(true);
mockPcapJob.setPageable(pageable);
this.mockMvc.perform(get(pcapUrl + "/jobId/raw?page=1").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(header().string("Content-Disposition", "attachment; filename=\"pcap_jobId_1.pcap\"")).andExpect(header().string("Content-Length", Integer.toString(pcapFileContents.length()))).andExpect(content().contentType(MediaType.parseMediaType("application/octet-stream"))).andExpect(content().bytes(pcapFileContents.getBytes(StandardCharsets.UTF_8)));
this.mockMvc.perform(get(pcapUrl + "/jobId/raw?page=1&fileName=pcapFile.pcap").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(header().string("Content-Disposition", "attachment; filename=\"pcapFile.pcap\"")).andExpect(header().string("Content-Length", Integer.toString(pcapFileContents.length()))).andExpect(content().contentType(MediaType.parseMediaType("application/octet-stream"))).andExpect(content().bytes(pcapFileContents.getBytes(StandardCharsets.UTF_8)));
this.mockMvc.perform(get(pcapUrl + "/jobId/raw?page=2").with(httpBasic(user, password))).andExpect(status().isNotFound());
}
use of org.apache.metron.job.JobStatus in project metron by apache.
the class PcapControllerIntegrationTest method testTooManyJobs.
@Test
public void testTooManyJobs() 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(post(pcapUrl + "/fixed").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(fixedJson)).andExpect(status().isInternalServerError()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.message").value("Cannot submit job because a job is already running. Please contact the administrator to cancel job(s) with id(s) jobId"));
}
use of org.apache.metron.job.JobStatus in project metron by apache.
the class PcapControllerIntegrationTest method testQueryRequest.
@Test
public void testQueryRequest() throws Exception {
MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
mockPcapJob.setStatus(new JobStatus().withState(JobStatus.State.RUNNING));
this.mockMvc.perform(post(pcapUrl + "/query").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(queryJson)).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 QueryPcapFilter.Configurator);
assertEquals("query", mockPcapJob.getQuery());
}
use of org.apache.metron.job.JobStatus in project metron by apache.
the class PcapControllerIntegrationTest method testGetStatusList.
@Test
public void testGetStatusList() 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 + "?state=RUNNING").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$[0].jobId").value("jobId")).andExpect(jsonPath("$[0].jobStatus").value("RUNNING"));
this.mockMvc.perform(get(pcapUrl + "?state=SUCCEEDED").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(content().json("[]"));
}
Aggregations