Merge "Netconf-cli compilable and included in project"
[controller.git] / opendaylight / config / logback-config-loader / src / test / java / org / opendaylight / controller / logback / config / loader / test / LogbackConfigurationLoaderTest.java
1 /**
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.logback.config.loader.test;
9
10 import java.io.File;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.junit.runners.JUnit4;
17 import org.opendaylight.controller.logback.config.loader.impl.LogbackConfigUtil;
18 import org.opendaylight.controller.logback.config.loader.impl.LogbackConfigurationLoader;
19 import org.opendaylight.controller.logback.config.loader.test.logwork.Debugger;
20 import org.opendaylight.controller.logback.config.loader.test.logwork.Errorer;
21 import org.opendaylight.controller.logback.config.loader.test.logwork.Informer;
22 import org.opendaylight.controller.logback.config.loader.test.logwork.Tracer;
23 import org.opendaylight.controller.logback.config.loader.test.logwork.Warner;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * test of logging config loader - {@link LogbackConfigurationLoader}
29  */
30 @RunWith(JUnit4.class)
31 public class LogbackConfigurationLoaderTest {
32
33     /** logback config root */
34     private static final String LOGBACK_D = "/logback.d";
35     private static final Logger LOG = LoggerFactory
36             .getLogger(LogbackConfigurationLoaderTest.class);
37
38     /**
39      * Test of method {@link LogbackConfigurationLoader#load(boolean, Object[])}
40      *
41      * @throws Exception
42      */
43     @Test
44     public void testLoad() throws Exception {
45         File logConfigRoot = new File(LogbackConfigurationLoaderTest.class
46                 .getResource(LOGBACK_D).getFile());
47         List<File> sortedConfigFiles = LogbackConfigUtil.harvestSortedConfigFiles(logConfigRoot);
48         LogbackConfigurationLoader.load(true, sortedConfigFiles.toArray());
49
50         LOG.info("LOGBACK ready -> about to use it");
51
52         Tracer.doSomeAction();
53         Debugger.doSomeAction();
54         Informer.doSomeAction();
55         Warner.doSomeAction();
56         Errorer.doSomeAction();
57
58         // check logs
59         String[] expectedLogs = new String[] {
60             "LoggingEvent -> [INFO] org.opendaylight.controller.logback.config.loader.test.LogbackConfigurationLoaderTest: LOGBACK ready -> about to use it",
61             "LoggingEvent -> [TRACE] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: tracing",
62             "LoggingEvent -> [DEBUG] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: debugging",
63             "LoggingEvent -> [INFO] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: infoing",
64             "LoggingEvent -> [WARN] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: warning",
65             "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: erroring",
66             "LoggingEvent -> [DEBUG] org.opendaylight.controller.logback.config.loader.test.logwork.Debugger: debugging",
67             "LoggingEvent -> [INFO] org.opendaylight.controller.logback.config.loader.test.logwork.Debugger: infoing",
68             "LoggingEvent -> [WARN] org.opendaylight.controller.logback.config.loader.test.logwork.Debugger: warning",
69             "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Debugger: erroring",
70             "LoggingEvent -> [INFO] org.opendaylight.controller.logback.config.loader.test.logwork.Informer: infoing",
71             "LoggingEvent -> [WARN] org.opendaylight.controller.logback.config.loader.test.logwork.Informer: warning",
72             "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Informer: erroring",
73             "LoggingEvent -> [WARN] org.opendaylight.controller.logback.config.loader.test.logwork.Warner: warning",
74             "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Warner: erroring",
75             "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Errorer: erroring"
76         };
77
78         List<String> logSnapshot = new ArrayList<>(TestAppender.getLogRecord());
79         for (String logLine : logSnapshot) {
80             LOG.info("\"{}\",", logLine);
81         }
82
83         Assert.assertArrayEquals(expectedLogs, logSnapshot.toArray());
84     }
85 }