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  */
  23 import java.util.Arrays;
  24 import java.util.List;
  25 import java.util.logging.Logger;
  26 
  27 /**
  28  * @test
  29  * @bug 7184195
  30  * @summary checks that java.util.logging.Logger.getGlobal().info() logs without configuration
  31  * @build TestGetGlobal testgetglobal.HandlerImpl testgetglobal.LogManagerImpl1 testgetglobal.LogManagerImpl2 testgetglobal.LogManagerImpl3 testgetglobal.BadLogManagerImpl testgetglobal.DummyLogManagerImpl
  32  * @run main/othervm/timeout=10 TestGetGlobal
  33  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager TestGetGlobal
  34  * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobal
  35  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobal
  36  * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobal
  37  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobal
  38  * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobal
  39  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobal
  40  * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobal
  41  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobal
  42  * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobal
  43  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobal
  44  * @author danielfuchs
  45  */
  46 public class TestGetGlobal {
  47 
  48     final static 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.getGlobal().info(messages[1]); // calling getGlobal() 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 }
--- EOF ---