Repository: nifi
Updated Branches:
  refs/heads/master d6391652e -> 65d895827


http://git-wip-us.apache.org/repos/asf/nifi/blob/65d89582/nifi-nar-bundles/nifi-windows-event-log-bundle/nifi-windows-event-log-processors/src/test/java/org/apache/nifi/processors/windows/event/log/jna/ErrorLookupTest.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-windows-event-log-bundle/nifi-windows-event-log-processors/src/test/java/org/apache/nifi/processors/windows/event/log/jna/ErrorLookupTest.java
 
b/nifi-nar-bundles/nifi-windows-event-log-bundle/nifi-windows-event-log-processors/src/test/java/org/apache/nifi/processors/windows/event/log/jna/ErrorLookupTest.java
new file mode 100644
index 0000000..ef4a91f
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-windows-event-log-bundle/nifi-windows-event-log-processors/src/test/java/org/apache/nifi/processors/windows/event/log/jna/ErrorLookupTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.processors.windows.event.log.jna;
+
+import com.sun.jna.platform.win32.Kernel32;
+import com.sun.jna.platform.win32.WinError;
+import org.apache.nifi.processors.windows.event.log.JNAJUnitRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+@RunWith(JNAJUnitRunner.class)
+public class ErrorLookupTest {
+    @Mock
+    Kernel32 kernel32;
+
+    private ErrorLookup errorLookup;
+
+    @Before
+    public void setup() {
+        errorLookup = new ErrorLookup(kernel32);
+    }
+
+    @Test
+    public void testErrorLookupExists() {
+        
when(kernel32.GetLastError()).thenReturn(WinError.ERROR_INSUFFICIENT_BUFFER);
+        assertEquals("ERROR_INSUFFICIENT_BUFFER(" + 
WinError.ERROR_INSUFFICIENT_BUFFER + ")", errorLookup.getLastError());
+    }
+
+    @Test
+    public void testErrorLookupDoesntExist() {
+        when(kernel32.GetLastError()).thenReturn(Integer.MAX_VALUE);
+        assertEquals(Integer.toString(Integer.MAX_VALUE), 
errorLookup.getLastError());
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi/blob/65d89582/nifi-nar-bundles/nifi-windows-event-log-bundle/nifi-windows-event-log-processors/src/test/java/org/apache/nifi/processors/windows/event/log/jna/EventSubscribeXmlRenderingCallbackTest.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-windows-event-log-bundle/nifi-windows-event-log-processors/src/test/java/org/apache/nifi/processors/windows/event/log/jna/EventSubscribeXmlRenderingCallbackTest.java
 
b/nifi-nar-bundles/nifi-windows-event-log-bundle/nifi-windows-event-log-processors/src/test/java/org/apache/nifi/processors/windows/event/log/jna/EventSubscribeXmlRenderingCallbackTest.java
new file mode 100644
index 0000000..3ec7331
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-windows-event-log-bundle/nifi-windows-event-log-processors/src/test/java/org/apache/nifi/processors/windows/event/log/jna/EventSubscribeXmlRenderingCallbackTest.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.processors.windows.event.log.jna;
+
+import com.sun.jna.Pointer;
+import com.sun.jna.platform.win32.Kernel32;
+import com.sun.jna.platform.win32.WinNT;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.processors.windows.event.log.ConsumeWindowsEventLogTest;
+import org.apache.nifi.processors.windows.event.log.JNAJUnitRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+
+import java.util.Arrays;
+import java.util.function.Consumer;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(JNAJUnitRunner.class)
+public class EventSubscribeXmlRenderingCallbackTest {
+    @Mock
+    ComponentLog logger;
+
+    @Mock
+    Consumer<String> consumer;
+
+    @Mock
+    WEvtApi wEvtApi;
+
+    @Mock
+    Kernel32 kernel32;
+
+    @Mock
+    ErrorLookup errorLookup;
+
+    @Mock
+    WinNT.HANDLE handle;
+
+    private EventSubscribeXmlRenderingCallback 
eventSubscribeXmlRenderingCallback;
+    private int maxBufferSize;
+
+    @Before
+    public void setup() {
+        maxBufferSize = 8;
+        eventSubscribeXmlRenderingCallback = new 
EventSubscribeXmlRenderingCallback(logger, consumer, maxBufferSize, wEvtApi, 
kernel32, errorLookup);
+    }
+
+    @Test
+    public void testErrorJustLogs() {
+        int errorCode = 111;
+        Pointer pointer = mock(Pointer.class);
+        when(handle.getPointer()).thenReturn(pointer);
+        when(pointer.getInt(0)).thenReturn(errorCode);
+
+        
eventSubscribeXmlRenderingCallback.onEvent(WEvtApi.EvtSubscribeNotifyAction.ERROR,
 null, handle);
+        
verify(logger).error(EventSubscribeXmlRenderingCallback.RECEIVED_THE_FOLLOWING_WIN32_ERROR
 + errorCode);
+    }
+
+    @Test
+    public void testMissingRecordLog() {
+        Pointer pointer = mock(Pointer.class);
+        when(handle.getPointer()).thenReturn(pointer);
+        
when(pointer.getInt(0)).thenReturn(WEvtApi.EvtSubscribeErrors.ERROR_EVT_QUERY_RESULT_STALE);
+
+        
eventSubscribeXmlRenderingCallback.onEvent(WEvtApi.EvtSubscribeNotifyAction.ERROR,
 null, handle);
+        
verify(logger).error(EventSubscribeXmlRenderingCallback.MISSING_EVENT_MESSAGE);
+    }
+
+    @Test
+    public void testSuccessfulRender() {
+        String small = "abc";
+        handle = ConsumeWindowsEventLogTest.mockEventHandles(wEvtApi, 
kernel32, Arrays.asList(small + "\u0000")).get(0);
+        
eventSubscribeXmlRenderingCallback.onEvent(WEvtApi.EvtSubscribeNotifyAction.DELIVER,
 null, handle);
+        verify(consumer).accept(small);
+    }
+
+    @Test
+    public void testUnuccessfulRender() {
+        String large = "abcde";
+        handle = ConsumeWindowsEventLogTest.mockEventHandles(wEvtApi, 
kernel32, Arrays.asList(large)).get(0);
+        
eventSubscribeXmlRenderingCallback.onEvent(WEvtApi.EvtSubscribeNotifyAction.DELIVER,
 null, handle);
+        verify(consumer, never()).accept(anyString());
+    }
+
+    @Test
+    public void testResizeRender() {
+        // Make a string too big to fit into initial buffer
+        StringBuilder testStringBuilder = new StringBuilder();
+        for (int i = 0; i < 10; i++) {
+            testStringBuilder.append(i);
+        }
+        String base = testStringBuilder.toString();
+        testStringBuilder = new StringBuilder();
+        for (int i = 0; i < 100; i++) {
+            testStringBuilder.append(base);
+        }
+        String veryLarge = testStringBuilder.toString();
+
+        handle = ConsumeWindowsEventLogTest.mockEventHandles(wEvtApi, 
kernel32, Arrays.asList(veryLarge)).get(0);
+        eventSubscribeXmlRenderingCallback = new 
EventSubscribeXmlRenderingCallback(logger, consumer, 2048, wEvtApi, kernel32, 
errorLookup);
+        
eventSubscribeXmlRenderingCallback.onEvent(WEvtApi.EvtSubscribeNotifyAction.DELIVER,
 null, handle);
+        verify(consumer).accept(veryLarge);
+    }
+
+    @Test
+    public void testErrorRendering() {
+        int value = 225;
+        String code = "225code";
+        when(kernel32.GetLastError()).thenReturn(value);
+        when(errorLookup.getLastError()).thenReturn(code);
+        
eventSubscribeXmlRenderingCallback.onEvent(WEvtApi.EvtSubscribeNotifyAction.DELIVER,
 null, handle);
+        
verify(logger).error(EventSubscribeXmlRenderingCallback.EVT_RENDER_RETURNED_THE_FOLLOWING_ERROR_CODE
 + code + ".");
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi/blob/65d89582/nifi-nar-bundles/nifi-windows-event-log-bundle/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-windows-event-log-bundle/pom.xml 
b/nifi-nar-bundles/nifi-windows-event-log-bundle/pom.xml
new file mode 100644
index 0000000..cea1bf6
--- /dev/null
+++ b/nifi-nar-bundles/nifi-windows-event-log-bundle/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+license agreements. See the NOTICE file distributed with this work for 
additional
+information regarding copyright ownership. The ASF licenses this file to
+You under the Apache License, Version 2.0 (the "License"); you may not use
+this file except in compliance with the License. You may obtain a copy of
+the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+by applicable law or agreed to in writing, software distributed under the
+License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+OF ANY KIND, either express or implied. See the License for the specific
+language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.nifi</groupId>
+        <artifactId>nifi-nar-bundles</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.nifi</groupId>
+    <artifactId>nifi-windows-event-log-bundle</artifactId>
+    <packaging>pom</packaging>
+
+    <properties>
+        <lucene.version>5.3.1</lucene.version>
+    </properties>
+
+    <modules>
+        <module>nifi-windows-event-log-nar</module>
+        <module>nifi-windows-event-log-processors</module>
+    </modules>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.nifi</groupId>
+                <artifactId>nifi-windows-event-log-processors</artifactId>
+                <version>1.0.0-SNAPSHOT</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+</project>

http://git-wip-us.apache.org/repos/asf/nifi/blob/65d89582/nifi-nar-bundles/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/pom.xml b/nifi-nar-bundles/pom.xml
index dba9ae7..d554e03 100644
--- a/nifi-nar-bundles/pom.xml
+++ b/nifi-nar-bundles/pom.xml
@@ -66,6 +66,7 @@
         <module>nifi-evtx-bundle</module>
         <module>nifi-slack-bundle</module>
         <module>nifi-snmp-bundle</module>
+        <module>nifi-windows-event-log-bundle</module>
     </modules>
 
     <dependencyManagement>

http://git-wip-us.apache.org/repos/asf/nifi/blob/65d89582/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 8a3dad8..0a41aa4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1161,6 +1161,12 @@ language governing permissions and limitations under the 
License. -->
                 <version>1.0.0-SNAPSHOT</version>
                 <type>nar</type>
             </dependency>
+           <dependency>
+                <groupId>org.apache.nifi</groupId>
+                <artifactId>nifi-windows-event-log-nar</artifactId>
+                <version>1.0.0-SNAPSHOT</version>
+                <type>nar</type>
+            </dependency>
             <dependency>
                 <groupId>org.apache.nifi</groupId>
                 <artifactId>nifi-properties</artifactId>

Reply via email to