You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/04/15 05:45:01 UTC
svn commit: r1587396 [2/2] - in /logging/log4j/log4j2/trunk: ./
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ log4j-streams/
log4j-streams/src/ log4j-streams/src/main/ log4j-streams/src/main/java/
log4j-streams/src/main/java/org/ log4j-s...
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,127 @@
+/*
+ * 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.logging.log4j.streams;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoggerInputStreamTest extends StreamTesting {
+ protected ByteArrayInputStream wrapped;
+ protected ByteArrayOutputStream read;
+ protected InputStream in;
+
+ @Before
+ public void createStream() {
+ wrapped = new ByteArrayInputStream((FIRST + "\r\n" + LAST).getBytes());
+ read = new ByteArrayOutputStream();
+ in = createInputStream();
+ }
+
+ protected InputStream createInputStream() {
+ return new LoggerInputStream(wrapped, getLogger(), LEVEL);
+ }
+
+ @Test
+ public void testRead_int() throws Exception {
+ for (int i = 0; i < FIRST.length(); i++) {
+ read.write(in.read());
+ }
+ if (!(in instanceof BufferedInputStream)) {
+ assertMessages();
+ }
+ assertEquals("carriage return", '\r', in.read());
+ if (!(in instanceof BufferedInputStream)) {
+ assertMessages();
+ }
+ assertEquals("newline", '\n', in.read());
+ assertMessages(FIRST);
+ }
+
+ @Test
+ public void testRead_ByteArray() throws Exception {
+ final byte[] bytes = new byte[FIRST.length()];
+ assertEquals("len", bytes.length, in.read(bytes));
+ if (!(in instanceof BufferedInputStream)) {
+ assertMessages();
+ }
+ in.read(bytes);
+ assertMessages(FIRST);
+ }
+
+ @Test
+ public void testRead_ByteArray_Offset_Length() throws Exception {
+ final byte[] bytes = new byte[FIRST.length() * 2];
+ assertEquals("len", FIRST.length(), in.read(bytes, 0, FIRST.length()));
+ if (!(in instanceof BufferedInputStream)) {
+ assertMessages();
+ }
+ in.read(bytes);
+ assertMessages(FIRST);
+ }
+
+ @Test
+ public void testRead_IgnoresWindowsNewline() throws IOException {
+ final byte[] bytes = new byte[1024];
+ int len = in.read(bytes);
+ read.write(bytes, 0, len);
+ assertMessages(FIRST);
+ assertEquals(FIRST + "\r\n" + LAST, read.toString());
+ in.close();
+ assertMessages(FIRST, LAST);
+ }
+
+ @Test
+ public void testRead_MultipleLines() throws IOException {
+ wrapped = new ByteArrayInputStream((FIRST + "\n" + LAST + '\n').getBytes());
+ in = new LoggerInputStream(wrapped, getLogger(), LEVEL);
+
+ final byte[] bytes = new byte[1024];
+ int len = in.read(bytes);
+ read.write(bytes, 0, len);
+ assertMessages(FIRST, LAST);
+ assertEquals(FIRST + '\n' + LAST + '\n', read.toString());
+ }
+
+ @Test
+ public void testClose_NoRemainingData() throws IOException {
+ wrapped = new ByteArrayInputStream((FIRST + '\n').getBytes());
+ in = new LoggerInputStream(wrapped, getLogger(), LEVEL);
+
+ final byte[] bytes = new byte[1024];
+ in.read(bytes);
+ assertMessages(FIRST);
+ in.close();
+ assertMessages(FIRST);
+ }
+
+ @Test
+ public void testClose_HasRemainingData() throws IOException {
+ final byte[] bytes = new byte[1024];
+ in.read(bytes);
+ assertMessages(FIRST);
+ in.close();
+ assertMessages(FIRST, LAST);
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,50 @@
+/*
+ * 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.logging.log4j.streams;
+
+import org.apache.logging.log4j.Level;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoggerOutputStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+
+ private LoggerOutputStream logOut;
+
+ @Before
+ public void setupStreams() {
+ logOut = new LoggerOutputStream(getLogger(), Level.WARN);
+ }
+
+ @Test
+ public void write() throws Exception {
+ logOut.write('a');
+ assertMessages("before write int", 0, "write");
+ logOut.write('\n');
+ assertMessages("after write int", 1, "write");
+
+ logOut.write("b\n".getBytes());
+ assertMessages("after write byte array", 2, "write");
+
+ logOut.write("c\n".getBytes(), 0, 2);
+ assertMessages("after write byte array offset size", 3, "write");
+
+ logOut.write('d');
+ assertMessages("before close size", 3, "write");
+ logOut.close();
+ assertMessages("after close size", 4, "write");
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,125 @@
+/*
+ * 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.logging.log4j.streams;
+
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.logging.log4j.Level;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoggerOutputStreamTest extends StreamTesting {
+ protected ByteArrayOutputStream wrapped;
+ protected OutputStream out;
+
+ @Before
+ public void createStream() {
+ wrapped = new ByteArrayOutputStream();
+ out = createOutputStream();
+ }
+
+ protected OutputStream createOutputStream() {
+ return new LoggerOutputStream(wrapped, getLogger(), Level.ERROR);
+ }
+
+ @Test
+ public void testWrite_Int() throws Exception {
+ for (byte b : "int".getBytes()) {
+ out.write(b);
+ assertMessages();
+ }
+ out.write('\n');
+ assertMessages("int");
+ assertEquals("int" + '\n', wrapped.toString());
+ }
+
+ @Test
+ public void testWrite_ByteArray() throws Exception {
+ final byte[] bytes = "byte[]".getBytes();
+ out.write(bytes);
+ assertMessages();
+ out.write('\n');
+ assertMessages("byte[]");
+ assertEquals("byte[]\n", wrapped.toString());
+ }
+
+ @Test
+ public void testWrite_ByteArray_Offset_Length() throws Exception {
+ final byte[] bytes = "byte[]".getBytes();
+ int middle = bytes.length/2;
+ int length = bytes.length - middle;
+ final String right = new String(bytes, middle, length);
+ out.write(bytes, middle, length);
+ assertMessages();
+ out.write('\n');
+ assertMessages(right);
+ assertEquals("byte[]".substring(middle, bytes.length) + '\n', wrapped.toString());
+ }
+
+ @Test
+ public void testWrite_IgnoresWindowsNewline() throws IOException {
+ out.write(FIRST.getBytes());
+ out.write("\r\n".getBytes());
+ out.write(LAST.getBytes());
+ out.close();
+ assertMessages(FIRST, LAST);
+ assertEquals(FIRST + "\r\n" + LAST, wrapped.toString());
+ }
+
+ @Test
+ public void testWrite_MultipleLines() throws IOException {
+ out.write((FIRST + '\n' + LAST + '\n').getBytes());
+ assertMessages(FIRST, LAST);
+ assertEquals(FIRST + '\n' + LAST + '\n', wrapped.toString());
+ }
+
+ @Test
+ public void testFlush() throws IOException {
+ final OutputStream out = EasyMock.createMock("out", OutputStream.class);
+ out.flush(); // expect the flush to come through to the mocked OutputStream
+ out.close();
+ replay(out);
+
+ final LoggerOutputStream los = new LoggerOutputStream(out, getLogger(), LEVEL);
+ los.flush();
+ los.close();
+ verify(out);
+ }
+
+ @Test
+ public void testClose_NoRemainingData() throws IOException {
+ out.close();
+ assertMessages();
+ assertEquals("", wrapped.toString());
+ }
+
+ @Test
+ public void testClose_HasRemainingData() throws IOException {
+ out.write(FIRST.getBytes());
+ assertMessages();
+ out.close();
+ assertMessages(FIRST);
+ assertEquals(FIRST, wrapped.toString());
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,145 @@
+/*
+ * 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.logging.log4j.streams;
+
+import java.util.Locale;
+
+import org.apache.logging.log4j.Level;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoggerPrintStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+
+ private LoggerPrintStream logOut;
+
+ @Before
+ public void setupStreams() {
+ logOut = new LoggerPrintStream(getLogger(), Level.WARN);
+ }
+
+ @Test
+ public void write_int() throws Exception {
+ logOut.write('a');
+ assertMessages("write int", 0, "write_int");
+ logOut.write('\n');
+ assertMessages("write newline", 1, "write_int");
+ }
+
+ @Test
+ public void write_bytes() throws Exception {
+ logOut.write("b\n".getBytes());
+ assertMessages("write", 1, "write_bytes");
+ }
+
+ @Test
+ public void write_bytes_offset() throws Exception {
+ logOut.write("c\n".getBytes(), 0, 2);
+ assertMessages("write", 1, "write_bytes_offset");
+ }
+
+ @Test
+ public void print_boolean() throws Exception {
+ logOut.print(true);
+ assertMessages("print", 0, "print_boolean");
+ logOut.println(true);
+ assertMessages("println", 1, "print_boolean");
+ }
+
+ @Test
+ public void print_char() throws Exception {
+ logOut.print('a');
+ assertMessages("print", 0, "print_char");
+ logOut.println('b');
+ assertMessages("println", 1, "print_char");
+ }
+
+ @Test
+ public void print_chararray() throws Exception {
+ logOut.print("a".toCharArray());
+ assertMessages("print", 0, "print_chararray");
+ logOut.println("b".toCharArray());
+ assertMessages("println", 1, "print_chararray");
+ }
+
+ @Test
+ public void print_double() throws Exception {
+ logOut.print(1D);
+ assertMessages("print", 0, "print_double");
+ logOut.println(2D);
+ assertMessages("println", 1, "print_double");
+ }
+
+ @Test
+ public void print_float() throws Exception {
+ logOut.print(1f);
+ assertMessages("print", 0, "print_float");
+ logOut.println(2f);
+ assertMessages("println", 1, "print_float");
+ }
+
+ @Test
+ public void print_int() throws Exception {
+ logOut.print(1);
+ assertMessages("print", 0, "print_int");
+ logOut.println(2);
+ assertMessages("println", 1, "print_int");
+ }
+
+ @Test
+ public void print_long() throws Exception {
+ logOut.print(1L);
+ assertMessages("print", 0, "print_long");
+ logOut.println(2L);
+ assertMessages("println", 1, "print_long");
+ }
+
+ @Test
+ public void print_object() throws Exception {
+ logOut.print((Object) 'a');
+ assertMessages("print", 0, "print_object");
+ logOut.println((Object) 'b');
+ assertMessages("println", 1, "print_object");
+ }
+
+ @Test
+ public void print_string() throws Exception {
+ logOut.print("a");
+ assertMessages("print", 0, "print_string");
+ logOut.println("b");
+ assertMessages("println", 1, "print_string");
+ }
+
+ @Test
+ public void print_printf() throws Exception {
+ logOut.printf("a\n");
+ assertMessages("println", 1, "print_printf");
+ }
+
+ @Test
+ public void print_printf_locale() throws Exception {
+ logOut.printf(Locale.getDefault(), "a\n");
+ assertMessages("println", 1, "print_printf_locale");
+ }
+
+ @Test
+ public void close() throws Exception {
+ logOut.print("a\nb");
+ assertMessages("before close size", 1, "close");
+ logOut.close();
+ assertMessages("after close size", 2, "close");
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,116 @@
+/*
+ * 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.logging.log4j.streams;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.io.OutputStream;
+
+import org.junit.Test;
+
+public class LoggerPrintStreamTest extends LoggerOutputStreamTest {
+ private LoggerPrintStream print;
+
+ @Override
+ protected OutputStream createOutputStream() {
+ return this.print = new LoggerPrintStream(wrapped, getLogger(), LEVEL);
+ }
+
+ @Test
+ public void testPrint_boolean() throws Exception {
+ print.print(true);
+ assertMessages();
+ print.println();
+ assertMessages("true");
+ assertEquals("true" + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_char() throws Exception {
+ for (char c : FIRST.toCharArray()) {
+ print.print(c);
+ assertMessages();
+ }
+ print.println();
+ assertMessages(FIRST);
+ assertEquals(FIRST + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_int() throws Exception {
+ print.print(12);
+ assertMessages();
+ print.println();
+ assertMessages("12");
+ assertEquals("12" + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_long() throws Exception {
+ print.print(12L);
+ assertMessages();
+ print.println();
+ assertMessages("12");
+ assertEquals("12" + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_CharacterArray() throws Exception {
+ print.print(FIRST.toCharArray());
+ assertMessages();
+ print.println();
+ assertMessages(FIRST);
+ assertEquals(FIRST + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_String() throws Exception {
+ print.print(FIRST);
+ assertMessages();
+ print.println();
+ assertMessages(FIRST);
+ assertEquals(FIRST + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_Object() throws Exception {
+ print.print((Object) FIRST);
+ assertMessages();
+ print.println();
+ assertMessages(FIRST);
+ assertEquals(FIRST + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrintf() throws Exception {
+ assertSame(print, print.printf("<<<%s>>>", FIRST));
+ assertMessages();
+ print.println();
+ assertMessages("<<<" + FIRST + ">>>");
+ assertEquals("<<<" + FIRST + ">>>" + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testFormat() throws Exception {
+ assertSame(print, print.format("[%s]", FIRST));
+ assertMessages();
+ print.println();
+ assertMessages("[" + FIRST + "]");
+ assertEquals("[" + FIRST + "]" + NEWLINE, wrapped.toString());
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,145 @@
+/*
+ * 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.logging.log4j.streams;
+
+import java.util.Locale;
+
+import org.apache.logging.log4j.Level;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoggerPrintWriterCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+
+ private LoggerPrintWriter logOut;
+
+ @Before
+ public void setupStreams() {
+ logOut = new LoggerPrintWriter(getLogger(), Level.WARN);
+ }
+
+ @Test
+ public void write_int() throws Exception {
+ logOut.write('a');
+ assertMessages("write int", 0, "write_int");
+ logOut.write('\n');
+ assertMessages("write newline", 1, "write_int");
+ }
+
+ @Test
+ public void write_bytes() throws Exception {
+ logOut.write("b\n".toCharArray());
+ assertMessages("write", 1, "write_bytes");
+ }
+
+ @Test
+ public void write_bytes_offset() throws Exception {
+ logOut.write("c\n".toCharArray(), 0, 2);
+ assertMessages("write", 1, "write_bytes_offset");
+ }
+
+ @Test
+ public void print_boolean() throws Exception {
+ logOut.print(true);
+ assertMessages("print", 0, "print_boolean");
+ logOut.println(true);
+ assertMessages("println", 1, "print_boolean");
+ }
+
+ @Test
+ public void print_char() throws Exception {
+ logOut.print('a');
+ assertMessages("print", 0, "print_char");
+ logOut.println('b');
+ assertMessages("println", 1, "print_char");
+ }
+
+ @Test
+ public void print_chararray() throws Exception {
+ logOut.print("a".toCharArray());
+ assertMessages("print", 0, "print_chararray");
+ logOut.println("b".toCharArray());
+ assertMessages("println", 1, "print_chararray");
+ }
+
+ @Test
+ public void print_double() throws Exception {
+ logOut.print(1D);
+ assertMessages("print", 0, "print_double");
+ logOut.println(2D);
+ assertMessages("println", 1, "print_double");
+ }
+
+ @Test
+ public void print_float() throws Exception {
+ logOut.print(1f);
+ assertMessages("print", 0, "print_float");
+ logOut.println(2f);
+ assertMessages("println", 1, "print_float");
+ }
+
+ @Test
+ public void print_int() throws Exception {
+ logOut.print(1);
+ assertMessages("print", 0, "print_int");
+ logOut.println(2);
+ assertMessages("println", 1, "print_int");
+ }
+
+ @Test
+ public void print_long() throws Exception {
+ logOut.print(1L);
+ assertMessages("print", 0, "print_long");
+ logOut.println(2L);
+ assertMessages("println", 1, "print_long");
+ }
+
+ @Test
+ public void print_object() throws Exception {
+ logOut.print((Object) 'a');
+ assertMessages("print", 0, "print_object");
+ logOut.println((Object) 'b');
+ assertMessages("println", 1, "print_object");
+ }
+
+ @Test
+ public void print_string() throws Exception {
+ logOut.print("a");
+ assertMessages("print", 0, "print_string");
+ logOut.println("b");
+ assertMessages("println", 1, "print_string");
+ }
+
+ @Test
+ public void print_printf() throws Exception {
+ logOut.printf("a\n");
+ assertMessages("println", 1, "print_printf");
+ }
+
+ @Test
+ public void print_printf_locale() throws Exception {
+ logOut.printf(Locale.getDefault(), "a\n");
+ assertMessages("println", 1, "print_printf_locale");
+ }
+
+ @Test
+ public void close() throws Exception {
+ logOut.print("a\nb");
+ assertMessages("before close size", 1, "close");
+ logOut.close();
+ assertMessages("after close size", 2, "close");
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,118 @@
+/*
+ * 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.logging.log4j.streams;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.io.PrintWriter;
+import java.io.Writer;
+
+import org.junit.Test;
+
+public class LoggerPrintWriterTest extends LoggerWriterTest {
+ private PrintWriter print;
+
+ @Override
+ protected Writer createWriter() {
+ this.print = new LoggerPrintWriter(wrapped, getLogger(), LEVEL);
+ return this.print;
+ }
+
+ @Test
+ public void testPrint_boolean() throws Exception {
+ print.print(true);
+ assertMessages();
+ print.println();
+ assertMessages("true");
+ assertEquals("true" + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_char() throws Exception {
+ for (char c : FIRST.toCharArray()) {
+ print.print(c);
+ assertMessages();
+ }
+ print.println();
+ assertMessages(FIRST);
+ assertEquals(FIRST + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_int() throws Exception {
+ print.print(12);
+ assertMessages();
+ print.println();
+ assertMessages("12");
+ assertEquals("12" + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_long() throws Exception {
+ print.print(12L);
+ assertMessages();
+ print.println();
+ assertMessages("12");
+ assertEquals("12" + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_CharacterArray() throws Exception {
+ print.print(FIRST.toCharArray());
+ assertMessages();
+ print.println();
+ assertMessages(FIRST);
+ assertEquals(FIRST + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_String() throws Exception {
+ print.print(FIRST);
+ assertMessages();
+ print.println();
+ assertMessages(FIRST);
+ assertEquals(FIRST + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrint_Object() throws Exception {
+ print.print((Object) FIRST);
+ assertMessages();
+ print.println();
+ assertMessages(FIRST);
+ assertEquals(FIRST + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testPrintf() throws Exception {
+ assertSame(print, print.printf("<<<%s>>>", FIRST));
+ assertMessages();
+ print.println();
+ assertMessages("<<<" + FIRST + ">>>");
+ assertEquals("<<<" + FIRST + ">>>" + NEWLINE, wrapped.toString());
+ }
+
+ @Test
+ public void testFormat() throws Exception {
+ assertSame(print, print.format("[%s]", FIRST));
+ assertMessages();
+ print.println();
+ assertMessages("[" + FIRST + "]");
+ assertEquals("[" + FIRST + "]" + NEWLINE, wrapped.toString());
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,57 @@
+/*
+ * 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.logging.log4j.streams;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.nio.CharBuffer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoggerReaderCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+
+ LoggerReader logReader;
+
+ @Before
+ public void setupReader() {
+ final Reader srcReader = new StringReader("a\nb\nc\nd\ne");
+ logReader = new LoggerReader(srcReader, getLogger(), LEVEL);
+ }
+
+ @Test
+ public void read() throws Exception {
+ logReader.read();
+ assertMessages("before read int size", 0, "read");
+ logReader.read();
+ assertMessages("after read int size", 1, "read");
+
+ logReader.read(new char[2]);
+ assertMessages("after read bytes size", 2, "read");
+
+ logReader.read(new char[2], 0, 2);
+ assertMessages("after read bytes offset size", 3, "read");
+
+ logReader.read(CharBuffer.allocate(2));
+ assertMessages("after read charBuffer size", 4, "read");
+
+ logReader.read();
+ assertMessages("before close size", 4, "read");
+ logReader.close();
+ assertMessages("after close size", 5, "read");
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,141 @@
+/*
+ * 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.logging.log4j.streams;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.nio.CharBuffer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoggerReaderTest extends StreamTesting {
+ protected StringReader wrapped;
+ protected StringWriter read;
+ protected Reader reader;
+
+ @Before
+ public void createStream() {
+ wrapped = new StringReader(FIRST + "\r\n" + LAST);
+ read = new StringWriter();
+ reader = createReader();
+ }
+
+ protected Reader createReader() {
+ return new LoggerReader(wrapped, getLogger(), LEVEL);
+ }
+
+ @Test
+ public void testRead_int() throws Exception {
+ for (int i = 0; i < FIRST.length(); i++) {
+ read.write(reader.read());
+ }
+ if (!(reader instanceof BufferedReader)) {
+ assertMessages();
+ }
+ assertEquals("carriage return", '\r', reader.read());
+ if (!(reader instanceof BufferedReader)) {
+ assertMessages();
+ }
+ assertEquals("newline", '\n', reader.read());
+ assertMessages(FIRST);
+ }
+
+ @Test
+ public void testRead_CharArray() throws Exception {
+ final char[] chars = new char[FIRST.length()];
+ assertEquals("len", FIRST.length(), reader.read(chars));
+ if (!(reader instanceof BufferedReader)) {
+ assertMessages();
+ }
+ reader.read(chars);
+ assertMessages(FIRST);
+ }
+
+ @Test
+ public void testRead_CharArray_Offset_Length() throws Exception {
+ final char[] chars = new char[1024];
+ assertEquals("len", FIRST.length(), reader.read(chars, 0, FIRST.length()));
+ if (!(reader instanceof BufferedReader)) {
+ assertMessages();
+ }
+ reader.read(chars);
+ reader.close();
+ assertMessages(FIRST, LAST);
+ }
+
+ @Test
+ public void testRead_CharBuffer() throws Exception {
+ final CharBuffer chars = CharBuffer.allocate(1024);
+ assertEquals("len", FIRST.length() + LAST.length() + 2, reader.read(chars));
+ reader.close();
+ assertMessages(FIRST, LAST);
+ }
+
+ @Test
+ public void testRead_IgnoresWindowsNewline() throws IOException {
+ final char[] chars = new char[1024];
+ int len = reader.read(chars);
+ read.write(chars, 0, len);
+ if (!(reader instanceof BufferedReader)) {
+ assertMessages(FIRST);
+ }
+ assertEquals(FIRST + "\r\n" + LAST, read.toString());
+ reader.close();
+ assertMessages(FIRST, LAST);
+ }
+
+ @Test
+ public void testRead_MultipleLines() throws IOException {
+ wrapped = new StringReader(FIRST + "\n" + LAST + '\n');
+ reader = createReader();
+
+ final char[] chars = new char[1024];
+ int len = reader.read(chars);
+ read.write(chars, 0, len);
+ assertMessages(FIRST, LAST);
+ assertEquals(FIRST + '\n' + LAST + '\n', read.toString());
+ }
+
+ @Test
+ public void testClose_NoRemainingData() throws IOException {
+ wrapped = new StringReader(FIRST + '\n');
+ reader = createReader();
+
+ final char[] chars = new char[1024];
+ reader.read(chars);
+ assertMessages(FIRST);
+ reader.close();
+ assertMessages(FIRST);
+ }
+
+ @Test
+ public void testClose_HasRemainingData() throws IOException {
+ final char[] chars = new char[1024];
+ reader.read(chars);
+ if (!(reader instanceof BufferedReader)) {
+ assertMessages(FIRST);
+ }
+ reader.close();
+ assertMessages(FIRST, LAST);
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.logging.log4j.streams;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Before;
+import org.junit.ClassRule;
+
+public class LoggerStreamsCallerInfoTesting {
+
+ protected final static Level LEVEL = Level.WARN;
+
+ @ClassRule
+ public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-calling-info.xml");
+
+ protected static Logger getLogger() {
+ return ctx.getLogger("ClassAndMethodLogger");
+ }
+
+ @Before
+ public void clearAppender() {
+ ((ListAppender) ctx.getAppender("ClassAndMethod")).clear();
+ }
+
+ public void assertMessages(final String msg, int size, String methodName) {
+ ListAppender appender = (ListAppender) ctx.getAppender("ClassAndMethod");
+ assertEquals(msg + ".size", size, appender.getMessages().size());
+ for (final String message : appender.getMessages()) {
+ assertEquals(msg + " has incorrect caller info", this.getClass().getName() + '.' + methodName, message);
+ }
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,124 @@
+/*
+ * 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.logging.log4j.streams;
+
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoggerWriterTest extends StreamTesting {
+ protected StringWriter wrapped;
+ protected Writer writer;
+
+ @Before
+ public void createStream() {
+ wrapped = new StringWriter();
+ writer = createWriter();
+ }
+
+ protected Writer createWriter() {
+ return new LoggerWriter(wrapped, getLogger(), LEVEL);
+ }
+
+ @Test
+ public void testWrite_CharArray() throws Exception {
+ final char[] chars = FIRST.toCharArray();
+ writer.write(chars);
+ assertMessages();
+ writer.write('\n');
+ assertMessages(FIRST);
+ assertEquals(FIRST + '\n', wrapped.toString());
+ }
+
+ @Test
+ public void testWrite_CharArray_Offset_Length() throws Exception {
+ final char[] chars = FIRST.toCharArray();
+ int middle = chars.length / 2;
+ int length = chars.length - middle;
+ final String right = new String(chars, middle, length);
+ writer.write(chars, middle, length);
+ assertMessages();
+ writer.write('\n');
+ assertMessages(right);
+ assertEquals(FIRST.substring(middle, FIRST.length()) + '\n', wrapped.toString());
+ }
+
+ @Test
+ public void testWrite_Character() throws Exception {
+ for (char c : FIRST.toCharArray()) {
+ writer.write(c);
+ assertMessages();
+ }
+ writer.write('\n');
+ assertMessages(FIRST);
+ assertEquals(FIRST + '\n', wrapped.toString());
+ }
+
+ @Test
+ public void testWrite_IgnoresWindowsNewline() throws IOException {
+ writer.write(FIRST + "\r\n");
+ writer.write(LAST);
+ writer.close();
+ assertMessages(FIRST, LAST);
+ assertEquals(FIRST + "\r\n" + LAST, wrapped.toString());
+ }
+
+ @Test
+ public void testWrite_MultipleLines() throws IOException {
+ writer.write(FIRST + '\n' + LAST + '\n');
+ assertMessages(FIRST, LAST);
+ assertEquals(FIRST + '\n' + LAST + '\n', wrapped.toString());
+ }
+
+ @Test
+ public void testFlush() throws IOException {
+ final OutputStream out = EasyMock.createMock(OutputStream.class);
+ out.flush(); // expect the flush to come through to the mocked OutputStream
+ out.close();
+ replay(out);
+
+ final LoggerOutputStream los = new LoggerOutputStream(out, getLogger(), LEVEL);
+ los.flush();
+ los.close();
+ verify(out);
+ }
+
+ @Test
+ public void testClose_NoRemainingData() throws IOException {
+ writer.close();
+ assertMessages();
+ assertEquals("", wrapped.toString());
+ }
+
+ @Test
+ public void testClose_HasRemainingData() throws IOException {
+ writer.write(FIRST);
+ assertMessages();
+ writer.close();
+ assertMessages(FIRST);
+ assertEquals(FIRST, wrapped.toString());
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java Tue Apr 15 03:44:59 2014
@@ -0,0 +1,61 @@
+/*
+ * 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.logging.log4j.streams;
+
+import static org.hamcrest.core.StringStartsWith.startsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+
+@Ignore
+public class StreamTesting {
+ protected final static String NEWLINE = System.getProperty("line.separator");
+ protected final static Level LEVEL = Level.ERROR;
+ protected final static String FIRST = "first";
+ protected final static String LAST = "last";
+
+ @ClassRule
+ public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-unit-test.xml");
+
+ protected static Logger getLogger() {
+ return ctx.getLogger("UnitTestLogger");
+ }
+
+ @Before
+ public void clearAppender() {
+ ((ListAppender) ctx.getAppender("UnitTest")).clear();
+ }
+
+ protected void assertMessages(final String... messages) {
+ List<String> actualMsgs = ((ListAppender) ctx.getAppender("UnitTest")).getMessages();
+ assertEquals("Unexpected number of results.", messages.length, actualMsgs.size());
+ for (int i = 0; i < messages.length; i++) {
+ final String start = LEVEL.name() + ' ' + messages[i];
+ assertThat(actualMsgs.get(i), startsWith(start));
+ }
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml Tue Apr 15 03:44:59 2014
@@ -0,0 +1,30 @@
+<?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.
+ -->
+<Configuration name="CallerInformationTest" status="error" packages="org.apache.logging.log4j.test">
+ <Appenders>
+ <List name="ClassAndMethod">
+ <PatternLayout pattern="%class.%method"/>
+ </List>
+ </Appenders>
+ <Loggers>
+ <Logger name="ClassAndMethodLogger" level="info">
+ <AppenderRef ref="ClassAndMethod"/>
+ </Logger>
+ <Root level="off"/>
+ </Loggers>
+</Configuration>
\ No newline at end of file
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml?rev=1587396&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml (added)
+++ logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml Tue Apr 15 03:44:59 2014
@@ -0,0 +1,30 @@
+<?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.
+ -->
+<Configuration name="UnitTest" status="error" packages="org.apache.logging.log4j.test">
+ <Appenders>
+ <List name="UnitTest">
+ <PatternLayout pattern="%level %m%n"/>
+ </List>
+ </Appenders>
+ <Loggers>
+ <Logger name="UnitTestLogger" level="info">
+ <AppenderRef ref="UnitTest"/>
+ </Logger>
+ <Root level="off"/>
+ </Loggers>
+</Configuration>
\ No newline at end of file
Propchange: logging/log4j/log4j2/trunk/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: logging/log4j/log4j2/trunk/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/pom.xml?rev=1587396&r1=1587395&r2=1587396&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/pom.xml (original)
+++ logging/log4j/log4j2/trunk/pom.xml Tue Apr 15 03:44:59 2014
@@ -930,6 +930,7 @@
<module>log4j-samples</module>
<module>log4j-bom</module>
<module>log4j-plugin-processor</module>
+ <module>log4j-streams</module>
</modules>
<profiles>
<profile>