TestGetGlobalByName.java revision 12745:f068a4ffddd2
1/* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23import java.util.Arrays; 24import java.util.List; 25import java.util.logging.Logger; 26 27/** 28 * @test 29 * @bug 7184195 30 * @summary checks that java.util.logging.Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info() logs without configuration 31 * @build TestGetGlobalByName testgetglobal.HandlerImpl testgetglobal.LogManagerImpl1 testgetglobal.LogManagerImpl2 testgetglobal.LogManagerImpl3 testgetglobal.BadLogManagerImpl testgetglobal.DummyLogManagerImpl 32 * @run main/othervm TestGetGlobalByName 33 * @run main/othervm/policy=policy -Djava.security.manager TestGetGlobalByName 34 * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobalByName 35 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl TestGetGlobalByName 36 * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalByName 37 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalByName 38 * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobalByName 39 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobalByName 40 * @run main/othervm -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobalByName 41 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobalByName 42 * @run main/othervm -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobalByName 43 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobalByName 44 * @author danielfuchs 45 */ 46public class TestGetGlobalByName { 47 48 static final String[] messages = { 49 "1. This message should not appear on the console.", 50 "2. This message should appear on the console.", 51 "3. This message should now appear on the console too." 52 }; 53 54 static { 55 System.setProperty("java.util.logging.config.file", 56 System.getProperty("test.src", ".") + java.io.File.separator + "logging.properties"); 57 } 58 59 public static void main(String... args) { 60 61 Logger.global.info(messages[0]); // at this point LogManager is not 62 // initialized yet, so this message should not appear. 63 Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(messages[1]); // calling getLogger() will 64 // initialize the LogManager - and thus this message should appear. 65 Logger.global.info(messages[2]); // Now that the LogManager is 66 // initialized, this message should appear too. 67 68 final List<String> expected = Arrays.asList(Arrays.copyOfRange(messages, 1, messages.length)); 69 if (!testgetglobal.HandlerImpl.received.equals(expected)) { 70 throw new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected); 71 } 72 } 73} 74