Search in sources :

Example 6 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testClose_SufficientPrivilege_DirectClose.

/*
	 * Test close() when having sufficient privilege, and no record has been
	 * written to the output stream.
	 */
public void testClose_SufficientPrivilege_DirectClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    h.close();
    assertEquals("flush", CallVerificationStack.getInstance().getCurrentSourceMethod());
    assertNull(CallVerificationStack.getInstance().pop());
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 7 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testConstructor_InvalidProperties.

/*
	 * Test the constructor with invalid relevant log manager properties are
	 * set.
	 */
public void testConstructor_InvalidProperties() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.level", INVALID_LEVEL);
    p.put("java.util.logging.ConsoleHandler.filter", className);
    p.put("java.util.logging.ConsoleHandler.formatter", className);
    p.put("java.util.logging.ConsoleHandler.encoding", "XXXX");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    assertEquals(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.level"), INVALID_LEVEL);
    assertEquals(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.encoding"), "XXXX");
    ConsoleHandler h = new ConsoleHandler();
    assertSame(h.getLevel(), Level.INFO);
    assertTrue(h.getFormatter() instanceof SimpleFormatter);
    assertNull(h.getFilter());
    assertNull(h.getEncoding());
    h.publish(new LogRecord(Level.SEVERE, "test"));
    assertNull(h.getEncoding());
}
Also used : LogRecord(java.util.logging.LogRecord) SimpleFormatter(java.util.logging.SimpleFormatter) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 8 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testClose_SufficientPrivilege_NormalClose.

/*
	 * Test close() when having sufficient privilege, and a record has been
	 * written to the output stream.
	 */
public void testClose_SufficientPrivilege_NormalClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    h.publish(new LogRecord(Level.SEVERE, "testClose_SufficientPrivilege_NormalClose msg"));
    h.close();
    assertEquals("flush", CallVerificationStack.getInstance().getCurrentSourceMethod());
    assertNull(CallVerificationStack.getInstance().pop());
    h.close();
}
Also used : LogRecord(java.util.logging.LogRecord) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 9 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testClose_SufficientPrivilege_Exception.

/*
	 * Test close() when having sufficient privilege, and an output stream that
	 * always throws exceptions.
	 */
public void testClose_SufficientPrivilege_Exception() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    h.publish(new LogRecord(Level.SEVERE, "testClose_SufficientPrivilege_Exception msg"));
    h.flush();
    h.close();
}
Also used : LogRecord(java.util.logging.LogRecord) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 10 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testConstructor_ValidProperties.

/*
	 * Test the constructor with insufficient privilege.
	 *
	public void testConstructor_InsufficientPrivilege() {
		assertNull(LogManager.getLogManager().getProperty(
				"java.util.logging.ConsoleHandler.level"));
		assertNull(LogManager.getLogManager().getProperty(
				"java.util.logging.ConsoleHandler.filter"));
		assertNull(LogManager.getLogManager().getProperty(
				"java.util.logging.ConsoleHandler.formatter"));
		assertNull(LogManager.getLogManager().getProperty(
				"java.util.logging.ConsoleHandler.encoding"));

		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());
		// set a normal value
		try {
			ConsoleHandler h = new ConsoleHandler();
			assertSame(h.getLevel(), Level.INFO);
			assertTrue(h.getFormatter() instanceof SimpleFormatter);
			assertNull(h.getFilter());
			assertSame(h.getEncoding(), null);
		} finally {
			System.setSecurityManager(oldMan);
		}
	}
	*/
/*
	 * Test the constructor with valid relevant log manager properties are set.
	 */
public void testConstructor_ValidProperties() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.level", "FINE");
    p.put("java.util.logging.ConsoleHandler.filter", className + "$MockFilter");
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    p.put("java.util.logging.ConsoleHandler.encoding", "iso-8859-1");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    assertEquals(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.level"), "FINE");
    assertEquals(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.encoding"), "iso-8859-1");
    ConsoleHandler h = new ConsoleHandler();
    assertSame(h.getLevel(), Level.parse("FINE"));
    assertTrue(h.getFormatter() instanceof MockFormatter);
    assertTrue(h.getFilter() instanceof MockFilter);
    assertEquals(h.getEncoding(), "iso-8859-1");
}
Also used : Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Aggregations

ConsoleHandler (java.util.logging.ConsoleHandler)49 Handler (java.util.logging.Handler)19 Logger (java.util.logging.Logger)15 LogRecord (java.util.logging.LogRecord)13 Properties (java.util.Properties)12 IOException (java.io.IOException)5 PrintStream (java.io.PrintStream)5 FileHandler (java.util.logging.FileHandler)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SimpleFormatter (java.util.logging.SimpleFormatter)4 File (java.io.File)3 ArrayList (java.util.ArrayList)2 Formatter (java.util.logging.Formatter)2 CommandCenterLogic (alma.acs.commandcenter.app.CommandCenterLogic)1 StartupOptions (alma.acs.commandcenter.app.CommandCenterLogic.StartupOptions)1 JmeFormatter (com.jme3.util.JmeFormatter)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1 Rectangle (java.awt.Rectangle)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1