TestGetGlobalByName.java revision 12745:f068a4ffddd2
118334Speter/*
290075Sobrien * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3169689Skan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
418334Speter *
590075Sobrien * This code is free software; you can redistribute it and/or modify it
618334Speter * under the terms of the GNU General Public License version 2 only, as
790075Sobrien * published by the Free Software Foundation.
890075Sobrien *
990075Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT
1090075Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1118334Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1290075Sobrien * version 2 for more details (a copy is included in the LICENSE file that
1390075Sobrien * accompanied this code).
1490075Sobrien *
1590075Sobrien * You should have received a copy of the GNU General Public License version
1618334Speter * 2 along with this work; if not, write to the Free Software Foundation,
1718334Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1890075Sobrien *
19169689Skan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20169689Skan * or visit www.oracle.com if you need additional information or have any
2118334Speter * questions.
22169689Skan */
23169689Skanimport java.util.Arrays;
2418334Speterimport java.util.List;
2550397Sobrienimport java.util.logging.Logger;
26169689Skan
27117395Skan/**
28117395Skan * @test
2918334Speter * @bug 7184195
3018334Speter * @summary checks that java.util.logging.Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info() logs without configuration
3118334Speter * @build TestGetGlobalByName testgetglobal.HandlerImpl testgetglobal.LogManagerImpl1 testgetglobal.LogManagerImpl2 testgetglobal.LogManagerImpl3 testgetglobal.BadLogManagerImpl testgetglobal.DummyLogManagerImpl
3290075Sobrien * @run main/othervm TestGetGlobalByName
3390075Sobrien * @run main/othervm/policy=policy -Djava.security.manager TestGetGlobalByName
3490075Sobrien * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobalByName
3590075Sobrien * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl TestGetGlobalByName
3618334Speter * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalByName
3790075Sobrien * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalByName
3890075Sobrien * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobalByName
3990075Sobrien * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobalByName
4018334Speter * @run main/othervm -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobalByName
4150397Sobrien * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobalByName
4250397Sobrien * @run main/othervm -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobalByName
4350397Sobrien * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobalByName
4450397Sobrien * @author danielfuchs
4518334Speter */
4618334Speterpublic class TestGetGlobalByName {
4718334Speter
4818334Speter    static final String[] messages = {
4950397Sobrien        "1. This message should not appear on the console.",
5090075Sobrien        "2. This message should appear on the console.",
5190075Sobrien        "3. This message should now appear on the console too."
5250397Sobrien    };
5350397Sobrien
5450397Sobrien    static {
5590075Sobrien        System.setProperty("java.util.logging.config.file",
5650397Sobrien            System.getProperty("test.src", ".") + java.io.File.separator + "logging.properties");
5750397Sobrien    }
5850397Sobrien
5950397Sobrien    public static void main(String... args) {
6090075Sobrien
6150397Sobrien        Logger.global.info(messages[0]); // at this point LogManager is not
6250397Sobrien             // initialized yet, so this message should not appear.
6350397Sobrien        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(messages[1]); // calling getLogger() will
64161651Skan             // initialize the LogManager - and thus this message should appear.
6550397Sobrien        Logger.global.info(messages[2]); // Now that the LogManager is
6650397Sobrien             // initialized, this message should appear too.
6750397Sobrien
68169689Skan        final List<String> expected = Arrays.asList(Arrays.copyOfRange(messages, 1, messages.length));
6950397Sobrien        if (!testgetglobal.HandlerImpl.received.equals(expected)) {
70169689Skan            throw new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected);
71169689Skan        }
72169689Skan    }
73169689Skan}
74169689Skan