use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testSetEncoding_Null.
/*
* Test setEncoding() method with supported encoding.
*
public void testSetEncoding_Normal() throws Exception {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.setEncoding("iso-8859-1");
assertEquals("iso-8859-1", h.getEncoding());
LogRecord r = new LogRecord(Level.INFO, "梁衍轩");
h.publish(r);
h.flush();
byte[] bytes = encoder.encode(
CharBuffer.wrap("MockFormatter_Head" + "梁衍轩"))
.array();
assertTrue(Arrays.equals(bytes, aos.toByteArray()));
}
/*
* Test setEncoding() method with supported encoding, after a log record
* has been written.
*
public void testSetEncoding_AfterPublish() throws Exception {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.setEncoding("iso-8859-1");
assertEquals("iso-8859-1", h.getEncoding());
LogRecord r = new LogRecord(Level.INFO, "梁衍轩");
h.publish(r);
h.flush();
assertTrue(Arrays.equals(aos.toByteArray(), encoder.encode(
CharBuffer.wrap("MockFormatter_Head" + "梁衍轩"))
.array()));
h.setEncoding("iso8859-1");
assertEquals("iso8859-1", h.getEncoding());
r = new LogRecord(Level.INFO, "梁衍轩");
h.publish(r);
h.flush();
assertFalse(Arrays.equals(aos.toByteArray(), encoder.encode(
CharBuffer.wrap("MockFormatter_Head" + "梁衍轩"
+ "testSetEncoding_Normal2")).array()));
byte[] b0 = aos.toByteArray();
byte[] b1 = encoder.encode(
CharBuffer.wrap("MockFormatter_Head" + "梁衍轩"))
.array();
byte[] b2 = encoder.encode(CharBuffer.wrap("梁衍轩"))
.array();
byte[] b3 = new byte[b1.length + b2.length];
System.arraycopy(b1, 0, b3, 0, b1.length);
System.arraycopy(b2, 0, b3, b1.length, b2.length);
assertTrue(Arrays.equals(b0, b3));
}
/*
* Test setEncoding() methods with null.
*/
public void testSetEncoding_Null() throws Exception {
StreamHandler h = new StreamHandler();
h.setEncoding(null);
assertNull(h.getEncoding());
}
use of java.util.logging.StreamHandler in project android_frameworks_base by ResurrectionRemix.
the class CookiesTest method testCookiesAreNotLogged.
/**
* Test that we don't log potentially sensitive cookie values.
* http://b/3095990
*/
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
// enqueue an HTTP response with a cookie that will be rejected
server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
server.play();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Logger logger = Logger.getLogger("org.apache.http");
StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
logger.addHandler(handler);
try {
HttpClient client = new DefaultHttpClient();
client.execute(new HttpGet(server.getUrl("/").toURI()));
handler.close();
String log = out.toString("UTF-8");
assertTrue(log, log.contains("password"));
assertTrue(log, log.contains("fake.domain"));
assertFalse(log, log.contains("secret"));
} finally {
logger.removeHandler(handler);
}
}
use of java.util.logging.StreamHandler in project geode by apache.
the class GemcachedDevelopmentJUnitTest method setUp.
@Before
public void setUp() throws Exception {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT, "0");
PORT = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
this.server = new GemFireMemcachedServer("", PORT, getProtocol());
server.start();
logger.addHandler(new StreamHandler());
}
use of java.util.logging.StreamHandler in project android_frameworks_base by crdroidandroid.
the class CookiesTest method testCookiesAreNotLogged.
/**
* Test that we don't log potentially sensitive cookie values.
* http://b/3095990
*/
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
// enqueue an HTTP response with a cookie that will be rejected
server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
server.play();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Logger logger = Logger.getLogger("org.apache.http");
StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
logger.addHandler(handler);
try {
HttpClient client = new DefaultHttpClient();
client.execute(new HttpGet(server.getUrl("/").toURI()));
handler.close();
String log = out.toString("UTF-8");
assertTrue(log, log.contains("password"));
assertTrue(log, log.contains("fake.domain"));
assertFalse(log, log.contains("secret"));
} finally {
logger.removeHandler(handler);
}
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testIsLoggable_Null_NoOutputStream.
/*
* Test isLoggable(), null log record, without output stream
*/
public void testIsLoggable_Null_NoOutputStream() {
StreamHandler h = new StreamHandler();
assertFalse(h.isLoggable(null));
}
Aggregations