Search in sources :

Example 1 with RootNode

use of org.apache.nifi.processors.evtx.parser.bxml.RootNode in project nifi by apache.

the class ParseEvtxTest method testProcessChunkGranularity.

@Test
public void testProcessChunkGranularity() throws IOException, MalformedChunkException, XMLStreamException {
    String basename = "basename";
    int chunkNum = 5;
    int offset = 10001;
    byte[] badChunk = { 8 };
    RootNodeHandler rootNodeHandler1 = mock(RootNodeHandler.class);
    RootNodeHandler rootNodeHandler2 = mock(RootNodeHandler.class);
    OutputStream out2 = mock(OutputStream.class);
    when(rootNodeHandlerFactory.create(out)).thenReturn(rootNodeHandler1);
    when(rootNodeHandlerFactory.create(out2)).thenReturn(rootNodeHandler2);
    ChunkHeader chunkHeader1 = mock(ChunkHeader.class);
    ChunkHeader chunkHeader2 = mock(ChunkHeader.class);
    Record record1 = mock(Record.class);
    Record record2 = mock(Record.class);
    Record record3 = mock(Record.class);
    RootNode rootNode1 = mock(RootNode.class);
    RootNode rootNode2 = mock(RootNode.class);
    RootNode rootNode3 = mock(RootNode.class);
    ProcessSession session = mock(ProcessSession.class);
    FlowFile flowFile = mock(FlowFile.class);
    FlowFile created1 = mock(FlowFile.class);
    FlowFile updated1 = mock(FlowFile.class);
    FlowFile created2 = mock(FlowFile.class);
    FlowFile updated2 = mock(FlowFile.class);
    MalformedChunkException malformedChunkException = new MalformedChunkException("Test", null, offset, chunkNum, badChunk);
    when(session.create(flowFile)).thenReturn(created1).thenReturn(created2).thenReturn(null);
    when(session.write(eq(created1), any(OutputStreamCallback.class))).thenAnswer(invocation -> {
        ((OutputStreamCallback) invocation.getArguments()[1]).process(out);
        return updated1;
    });
    when(session.write(eq(created2), any(OutputStreamCallback.class))).thenAnswer(invocation -> {
        ((OutputStreamCallback) invocation.getArguments()[1]).process(out2);
        return updated2;
    });
    when(record1.getRootNode()).thenReturn(rootNode1);
    when(record2.getRootNode()).thenReturn(rootNode2);
    when(record3.getRootNode()).thenReturn(rootNode3);
    when(fileHeader.hasNext()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
    when(fileHeader.next()).thenThrow(malformedChunkException).thenReturn(chunkHeader1).thenReturn(chunkHeader2).thenReturn(null);
    when(chunkHeader1.hasNext()).thenReturn(true).thenReturn(false);
    when(chunkHeader1.next()).thenReturn(record1).thenReturn(null);
    when(chunkHeader2.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
    when(chunkHeader2.next()).thenReturn(record2).thenReturn(record3).thenReturn(null);
    parseEvtx.processChunkGranularity(session, componentLog, flowFile, basename, in);
    verify(malformedChunkHandler).handle(flowFile, session, parseEvtx.getName(basename, chunkNum, null, ParseEvtx.EVTX_EXTENSION), badChunk);
    verify(rootNodeHandler1).handle(rootNode1);
    verify(rootNodeHandler1).close();
    verify(rootNodeHandler2).handle(rootNode2);
    verify(rootNodeHandler2).handle(rootNode3);
    verify(rootNodeHandler2).close();
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) RootNode(org.apache.nifi.processors.evtx.parser.bxml.RootNode) FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) OutputStream(java.io.OutputStream) ChunkHeader(org.apache.nifi.processors.evtx.parser.ChunkHeader) Record(org.apache.nifi.processors.evtx.parser.Record) Mockito.anyString(org.mockito.Mockito.anyString) MalformedChunkException(org.apache.nifi.processors.evtx.parser.MalformedChunkException) OutputStreamCallback(org.apache.nifi.processor.io.OutputStreamCallback) Test(org.junit.Test)

Example 2 with RootNode

use of org.apache.nifi.processors.evtx.parser.bxml.RootNode in project nifi by apache.

the class ParseEvtxTest method testProcessFileGranularity.

@Test
public void testProcessFileGranularity() throws IOException, MalformedChunkException, XMLStreamException {
    String basename = "basename";
    int chunkNum = 5;
    int offset = 10001;
    byte[] badChunk = { 8 };
    RootNodeHandler rootNodeHandler = mock(RootNodeHandler.class);
    when(rootNodeHandlerFactory.create(out)).thenReturn(rootNodeHandler);
    ChunkHeader chunkHeader1 = mock(ChunkHeader.class);
    ChunkHeader chunkHeader2 = mock(ChunkHeader.class);
    Record record1 = mock(Record.class);
    Record record2 = mock(Record.class);
    Record record3 = mock(Record.class);
    RootNode rootNode1 = mock(RootNode.class);
    RootNode rootNode2 = mock(RootNode.class);
    RootNode rootNode3 = mock(RootNode.class);
    ProcessSession session = mock(ProcessSession.class);
    FlowFile flowFile = mock(FlowFile.class);
    AtomicReference<Exception> reference = new AtomicReference<>();
    MalformedChunkException malformedChunkException = new MalformedChunkException("Test", null, offset, chunkNum, badChunk);
    when(record1.getRootNode()).thenReturn(rootNode1);
    when(record2.getRootNode()).thenReturn(rootNode2);
    when(record3.getRootNode()).thenReturn(rootNode3);
    when(fileHeader.hasNext()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
    when(fileHeader.next()).thenThrow(malformedChunkException).thenReturn(chunkHeader1).thenReturn(chunkHeader2).thenReturn(null);
    when(chunkHeader1.hasNext()).thenReturn(true).thenReturn(false);
    when(chunkHeader1.next()).thenReturn(record1).thenReturn(null);
    when(chunkHeader2.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
    when(chunkHeader2.next()).thenReturn(record2).thenReturn(record3).thenReturn(null);
    parseEvtx.processFileGranularity(session, componentLog, flowFile, basename, reference, in, out);
    verify(malformedChunkHandler).handle(flowFile, session, parseEvtx.getName(basename, chunkNum, null, ParseEvtx.EVTX_EXTENSION), badChunk);
    verify(rootNodeHandler).handle(rootNode1);
    verify(rootNodeHandler).handle(rootNode2);
    verify(rootNodeHandler).handle(rootNode3);
    verify(rootNodeHandler).close();
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) RootNode(org.apache.nifi.processors.evtx.parser.bxml.RootNode) FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) AtomicReference(java.util.concurrent.atomic.AtomicReference) Mockito.anyString(org.mockito.Mockito.anyString) MalformedChunkException(org.apache.nifi.processors.evtx.parser.MalformedChunkException) XMLStreamException(javax.xml.stream.XMLStreamException) MalformedChunkException(org.apache.nifi.processors.evtx.parser.MalformedChunkException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ChunkHeader(org.apache.nifi.processors.evtx.parser.ChunkHeader) Record(org.apache.nifi.processors.evtx.parser.Record) Test(org.junit.Test)

Example 3 with RootNode

use of org.apache.nifi.processors.evtx.parser.bxml.RootNode in project nifi by apache.

the class XmlBxmlNodeVisitorTest method testVisitRootNode.

@Test
public void testVisitRootNode() throws IOException {
    RootNode rootNode = mock(RootNode.class);
    BxmlNode child = mock(BxmlNode.class);
    when(rootNode.getChildren()).thenReturn(Arrays.asList(child));
    xmlBxmlNodeVisitor.visit(rootNode);
    ArgumentCaptor<BxmlNodeVisitor> captor = ArgumentCaptor.forClass(BxmlNodeVisitor.class);
    verify(child).accept(captor.capture());
    BxmlNodeVisitor value = captor.getValue();
    assertTrue(value instanceof XmlBxmlNodeVisitor);
    assertNotEquals(xmlBxmlNodeVisitor, value);
}
Also used : RootNode(org.apache.nifi.processors.evtx.parser.bxml.RootNode) BxmlNodeVisitor(org.apache.nifi.processors.evtx.parser.BxmlNodeVisitor) BxmlNode(org.apache.nifi.processors.evtx.parser.bxml.BxmlNode) Test(org.junit.Test)

Example 4 with RootNode

use of org.apache.nifi.processors.evtx.parser.bxml.RootNode in project nifi by apache.

the class XmlBxmlNodeVisitorTest method testVisitBxmlTypeNode.

@Test
public void testVisitBxmlTypeNode() throws IOException {
    BXmlTypeNode bXmlTypeNode = mock(BXmlTypeNode.class);
    RootNode rootNode = mock(RootNode.class);
    when(bXmlTypeNode.getRootNode()).thenReturn(rootNode);
    xmlBxmlNodeVisitor.visit(bXmlTypeNode);
    verify(rootNode).accept(xmlBxmlNodeVisitor);
}
Also used : RootNode(org.apache.nifi.processors.evtx.parser.bxml.RootNode) BXmlTypeNode(org.apache.nifi.processors.evtx.parser.bxml.value.BXmlTypeNode) Test(org.junit.Test)

Example 5 with RootNode

use of org.apache.nifi.processors.evtx.parser.bxml.RootNode in project nifi by apache.

the class ChunkHeaderTest method testInit.

@Test
public void testInit() throws IOException {
    int count = 0;
    for (Map.Entry<Integer, NameStringNode> integerNameStringNodeEntry : new TreeMap<>(chunkHeader.getNameStrings()).entrySet()) {
        assertEquals(Integer.toString(count++), integerNameStringNodeEntry.getValue().getString());
    }
    Iterator<String> iterator = guids.iterator();
    for (Map.Entry<Integer, TemplateNode> integerTemplateNodeEntry : new TreeMap<>(chunkHeader.getTemplateNodes()).entrySet()) {
        assertEquals(iterator.next(), integerTemplateNodeEntry.getValue().getGuid());
    }
    assertTrue(chunkHeader.hasNext());
    Record next = chunkHeader.next();
    assertEquals(fileLastRecordNumber, next.getRecordNum().intValue());
    RootNode rootNode = next.getRootNode();
    List<BxmlNode> children = rootNode.getChildren();
    assertEquals(1, children.size());
    assertTrue(children.get(0) instanceof EndOfStreamNode);
    assertEquals(0, rootNode.getSubstitutions().size());
    assertFalse(chunkHeader.hasNext());
}
Also used : TemplateNode(org.apache.nifi.processors.evtx.parser.bxml.TemplateNode) RootNode(org.apache.nifi.processors.evtx.parser.bxml.RootNode) BxmlNode(org.apache.nifi.processors.evtx.parser.bxml.BxmlNode) UnsignedInteger(com.google.common.primitives.UnsignedInteger) NameStringNode(org.apache.nifi.processors.evtx.parser.bxml.NameStringNode) EndOfStreamNode(org.apache.nifi.processors.evtx.parser.bxml.EndOfStreamNode) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.Test) TemplateNodeTest(org.apache.nifi.processors.evtx.parser.bxml.TemplateNodeTest) NameStringNodeTest(org.apache.nifi.processors.evtx.parser.bxml.NameStringNodeTest)

Aggregations

RootNode (org.apache.nifi.processors.evtx.parser.bxml.RootNode)8 Test (org.junit.Test)8 BxmlNode (org.apache.nifi.processors.evtx.parser.bxml.BxmlNode)4 FlowFile (org.apache.nifi.flowfile.FlowFile)3 ProcessSession (org.apache.nifi.processor.ProcessSession)3 ChunkHeader (org.apache.nifi.processors.evtx.parser.ChunkHeader)3 MalformedChunkException (org.apache.nifi.processors.evtx.parser.MalformedChunkException)3 Record (org.apache.nifi.processors.evtx.parser.Record)3 EndOfStreamNode (org.apache.nifi.processors.evtx.parser.bxml.EndOfStreamNode)3 MockFlowFile (org.apache.nifi.util.MockFlowFile)3 Mockito.anyString (org.mockito.Mockito.anyString)3 OutputStream (java.io.OutputStream)2 OutputStreamCallback (org.apache.nifi.processor.io.OutputStreamCallback)2 UnsignedInteger (com.google.common.primitives.UnsignedInteger)1 IOException (java.io.IOException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1