/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache license, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the license for the specific language governing permissions and
 * limitations under the license.
 */
package org.apache.logging.log4j.core;

import static org.junit.Assert.assertNotNull;

import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.message.MapMessage;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Work in progress.
 */
public class CollectionLoggingTest {

    private static final String CONFIG = "log4j-collectionLogging.xml";
    private static LoggerContext ctx;
    private ListAppender app;


    @BeforeClass
    public static void beforeClass() {
        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
        ctx = (LoggerContext) LogManager.getContext();
        ctx.reconfigure();
    }

    @Before
    public void before() {
        Configuration config = ctx.getConfiguration();
        for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet()) {
            if (entry.getKey().equals("List")) {
                app = (ListAppender) entry.getValue();
            }
        }
        assertNotNull("No Appender", app);
        app.clear();
    }

    @Test
    public void testSystemProperties() {
        final Logger logger = LogManager.getLogger(CollectionLoggingTest.class.getName());
        logger.error(System.getProperties());
        // logger.error(new MapMessage(System.getProperties()));
    }

    @Test
    public void testSimpleMap() {
        final Logger logger = LogManager.getLogger(CollectionLoggingTest.class.getName());
        logger.error(System.getProperties());
        final Map<String, String> map = new HashMap<String, String>();
        map.put("MyKey1", "MyValue1");
        map.put("MyKey2", "MyValue2");
        logger.error(new MapMessage(map));
        logger.error(map);
    }

    @Test
    public void testNetworkInterfaces() throws SocketException {
        final Logger logger = LogManager.getLogger(CollectionLoggingTest.class.getName());
        logger.error(NetworkInterface.getNetworkInterfaces());
    }

    @Test
    public void testAvailableCharsets() throws SocketException {
        final Logger logger = LogManager.getLogger(CollectionLoggingTest.class.getName());
        logger.error(Charset.availableCharsets());
    }

}

@@ -838,55 +838,8 @@
 e;%0A%0A
-import static org.junit.Assert.assertNotNull;%0A%0A
 impo
@@ -1018,20 +1018,16 @@
 og4j.Log
-Mana
 ger;%0Aimp
@@ -1059,139 +1059,34 @@
 g4j.
-Logger;%0Aimport org.apache.logging.log4j.core.config.Configuration;%0Aimport org.apache.logging.log4j.core.config.ConfigurationFactory
+junit.InitialLoggerContext
 ;%0Aim
@@ -1237,27 +1237,25 @@
 g.junit.
-Before
 Class
+Rule
 ;%0Aimport
@@ -1278,16 +1278,22 @@
 %0A%0A/**%0A *
+ TODO:
  Work in
@@ -1421,46 +1421,8 @@
 l%22;%0A
-    private static LoggerContext ctx;%0A
     
@@ -1452,25 +1452,22 @@
 p;%0A%0A
-%0A
     @
-Before
 Class
+Rule
 %0A   
@@ -1485,557 +1485,176 @@
 tic 
-void beforeClass() %7B%0A        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);%0A        ctx = (LoggerContext) LogManager.getContext();%0A        ctx.reconfigure();%0A    %7D%0A%0A    @Before%0A    public void before() %7B%0A        Configuration config = ctx.getConfiguration();%0A        for (final Map.Entry%3CString, Appender%3E entry : config.getAppenders().entrySet()) %7B%0A            if (entry.getKey().equals(%22List%22)) %7B%0A                app = (ListAppender) entry.getValue();%0A            %7D%0A        %7D%0A        assertNotNull(%22No Appender%22, app
+InitialLoggerContext context = new InitialLoggerContext(CONFIG);%0A%0A    @Before%0A    public void before() %7B%0A        app = (ListAppender) context.getRequiredAppender(%22List%22
 );%0A 
@@ -1757,34 +1757,31 @@
 er logger = 
-LogManager
+context
 .getLogger(C
@@ -2007,34 +2007,31 @@
 er logger = 
-LogManager
+context
 .getLogger(C
@@ -2442,34 +2442,31 @@
 er logger = 
-LogManager
+context
 .getLogger(C
@@ -2683,18 +2683,15 @@
 r = 
-LogManager
+context
 .get

Refactor test to use InitialLoggerContext rule.