Search in sources :

Example 21 with MockPcapJob

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"));
}
Also used : JobStatus(org.apache.metron.job.JobStatus) MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with MockPcapJob

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());
}
Also used : MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with MockPcapJob

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());
}
Also used : JobStatus(org.apache.metron.job.JobStatus) Path(org.apache.hadoop.fs.Path) MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) PcapPages(org.apache.metron.pcap.PcapPages) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with MockPcapJob

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()));
}
Also used : JobStatus(org.apache.metron.job.JobStatus) MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) FixedPcapFilter(org.apache.metron.pcap.filter.fixed.FixedPcapFilter) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MockPcapJob (org.apache.metron.rest.mock.MockPcapJob)24 Test (org.junit.jupiter.api.Test)24 InMemoryJobManager (org.apache.metron.job.manager.InMemoryJobManager)12 JobManager (org.apache.metron.job.manager.JobManager)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 JobStatus (org.apache.metron.job.JobStatus)11 FileSystem (org.apache.hadoop.fs.FileSystem)5 Path (org.apache.hadoop.fs.Path)5 FixedPcapFilter (org.apache.metron.pcap.filter.fixed.FixedPcapFilter)4 PcapPages (org.apache.metron.pcap.PcapPages)3 QueryPcapFilter (org.apache.metron.pcap.filter.query.QueryPcapFilter)2 PcapJobSupplier (org.apache.metron.rest.config.PcapJobSupplier)2 MockPcapJobSupplier (org.apache.metron.rest.mock.MockPcapJobSupplier)2 File (java.io.File)1 HashMap (java.util.HashMap)1