/*
 * 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.config.builder;

import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.config.AbstractConfiguration;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ConfigurationBuilderTest {

    private final static String expectedXml1 =
            "<?xml version='1.0' encoding='UTF-8'?>" + System.lineSeparator() +
            "<Configuration name=\"config name\" status=\"ERROR\">" + System.lineSeparator() +
            "\t<Properties>" + System.lineSeparator() +
            "\t\t<Property name=\"MyKey\">MyValue</Property>" + System.lineSeparator() +
            "\t</Properties>" + System.lineSeparator() +
            "\t<Scripts>" + System.lineSeparator() +
            "\t\t<ScriptFile path=\"target/test-classes/scripts/filter.groovy\" name=\"target/test-classes/scripts/filter.groovy\" isWatched=\"true\"/>" + System.lineSeparator() +
            "\t</Scripts>" + System.lineSeparator() +
            "\t<CustomLevels>" + System.lineSeparator() +
            "\t\t<CustomLevel intLevel=\"17\" name=\"Panic\"/>" + System.lineSeparator() +
            "\t</CustomLevels>" + System.lineSeparator() +
            "\t<ThresholdFilter onMatch=\"ACCEPT\" level=\"DEBUG\" onMisMatch=\"NEUTRAL\"/>" + System.lineSeparator() +
            "\t<Appenders>" + System.lineSeparator() +
            "\t\t<CONSOLE name=\"Stdout\" target=\"SYSTEM_OUT\">" + System.lineSeparator() +
            "\t\t\t<PatternLayout pattern=\"%d [%t] %-5level: %msg%n%throwable\"/>" + System.lineSeparator() +
            "\t\t\t<MarkerFilter onMatch=\"DENY\" onMisMatch=\"NEUTRAL\" marker=\"FLOW\"/>" + System.lineSeparator() +
            "\t\t</CONSOLE>" + System.lineSeparator() +
            "\t</Appenders>" + System.lineSeparator() +
            "\t<Loggers>" + System.lineSeparator() +
            "\t\t<Logger additivity=\"false\" level=\"DEBUG\" includeLocation=\"true\" name=\"org.apache.logging.log4j\">" + System.lineSeparator() +
            "\t\t\t<AppenderRef ref=\"Stdout\"/>" + System.lineSeparator() +
            "\t\t</Logger>" + System.lineSeparator() +
            "\t\t<Root level=\"ERROR\" includeLocation=\"true\">" + System.lineSeparator() +
            "\t\t\t<AppenderRef ref=\"Stdout\"/>" + System.lineSeparator() +
            "\t\t</Root>" + System.lineSeparator() +
            "\t</Loggers>" + System.lineSeparator() +
            "</Configuration>" + System.lineSeparator();

    @Test
    public void testXmlConstructing() throws Exception {
        final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
        CustomConfigurationFactory.addTestFixtures("config name", builder);
        builder.addProperty("MyKey", "MyValue");
        builder.add(builder.newCustomLevel("Panic", 17));
        final String xmlConfiguration = builder.toXmlConfiguration();
        assertEquals(expectedXml1, xmlConfiguration);
    }

    private final static String expectedXml2 =
            "<?xml version='1.0' encoding='UTF-8'?>" + System.lineSeparator() +
            "<Configuration name=\"config name\" status=\"ERROR\">" + System.lineSeparator() +
            "\t<Properties>" + System.lineSeparator() +
            "\t\t<Property name=\"MyKey\">MyValue</Property>" + System.lineSeparator() +
            "\t</Properties>" + System.lineSeparator() +
            "\t<Scripts>" + System.lineSeparator() +
            "\t\t<ScriptFile name=\"target/test-classes/scripts/filter.groovy\" path=\"target/test-classes/scripts/filter.groovy\" isWatched=\"true\"/>" + System.lineSeparator() +
            "\t</Scripts>" + System.lineSeparator() +
            "\t<CustomLevels>" + System.lineSeparator() +
            "\t\t<CustomLevel name=\"Panic\" intLevel=\"17\"/>" + System.lineSeparator() +
            "\t</CustomLevels>" + System.lineSeparator() +
            "\t<ThresholdFilter onMatch=\"ACCEPT\" level=\"DEBUG\" onMisMatch=\"NEUTRAL\"/>" + System.lineSeparator() +
            "\t<Appenders>" + System.lineSeparator() +
            "\t\t<CONSOLE name=\"Stdout\" target=\"SYSTEM_OUT\">" + System.lineSeparator() +
            "\t\t\t<PatternLayout pattern=\"%d [%t] %-5level: %msg%n%throwable\"/>" + System.lineSeparator() +
            "\t\t\t<MarkerFilter onMatch=\"DENY\" onMisMatch=\"NEUTRAL\" marker=\"FLOW\"/>" + System.lineSeparator() +
            "\t\t</CONSOLE>" + System.lineSeparator() +
            "\t</Appenders>" + System.lineSeparator() +
            "\t<Loggers>" + System.lineSeparator() +
            "\t\t<Logger name=\"org.apache.logging.log4j\" additivity=\"false\" level=\"DEBUG\" includeLocation=\"true\">" + System.lineSeparator() +
            "\t\t\t<AppenderRef ref=\"Stdout\"/>" + System.lineSeparator() +
            "\t\t</Logger>" + System.lineSeparator() +
            "\t\t<Root level=\"ERROR\" includeLocation=\"true\">" + System.lineSeparator() +
            "\t\t\t<AppenderRef ref=\"Stdout\"/>" + System.lineSeparator() +
            "\t\t</Root>" + System.lineSeparator() +
            "\t</Loggers>" + System.lineSeparator() +
            "</Configuration>" + System.lineSeparator();

    @Test
    public void testXmlConstructingWithAbstractConfiguration() throws Exception {
        final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
        CustomConfigurationFactory.addTestFixtures("config name", builder);
        builder.addProperty("MyKey", "MyValue");
        builder.add(builder.newCustomLevel("Panic", 17));
        AbstractConfiguration configuration = builder.build(false);
        configuration.setup();
        final String xmlConfiguration = configuration.toXmlConfiguration();
        assertEquals(expectedXml2, xmlConfiguration);
    }
}

@@ -1496,32 +1496,53 @@
 status=%5C%22ERROR%5C%22
+ packages=%5C%22foo,bar%5C%22
 %3E%22 + System.line
@@ -1547,32 +1547,32 @@
 neSeparator() +%0A
-
             %22%5Ct%3C
@@ -3894,32 +3894,72 @@
 (%22Panic%22, 17));%0A
+        builder.setPackages(%22foo,bar%22);%0A
         final St
@@ -4265,16 +4265,37 @@
 %22ERROR%5C%22
+ packages=%5C%22foo,bar%5C%22
 %3E%22 + Sys
@@ -6622,32 +6622,32 @@
 y%22, %22MyValue%22);%0A
-
         builder.
@@ -6680,32 +6680,72 @@
 (%22Panic%22, 17));%0A
+        builder.setPackages(%22foo,bar%22);%0A
         Abstract

Test packages configuration attribute