2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.logback.config.loader.test;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.junit.runners.JUnit4;
18 import org.opendaylight.controller.logback.config.loader.impl.LogbackConfigUtil;
19 import org.opendaylight.controller.logback.config.loader.impl.LogbackConfigurationLoader;
20 import org.opendaylight.controller.logback.config.loader.test.logwork.Debugger;
21 import org.opendaylight.controller.logback.config.loader.test.logwork.Errorer;
22 import org.opendaylight.controller.logback.config.loader.test.logwork.Informer;
23 import org.opendaylight.controller.logback.config.loader.test.logwork.Tracer;
24 import org.opendaylight.controller.logback.config.loader.test.logwork.Warner;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * test of logging config loader - {@link LogbackConfigurationLoader}
31 @RunWith(JUnit4.class)
32 public class LogbackConfigurationLoaderTest {
34 /** logback config root */
35 private static final String LOGBACK_D = "/logback.d";
36 private static Logger LOG = LoggerFactory
37 .getLogger(LogbackConfigurationLoaderTest.class);
40 * Test of method {@link LogbackConfigurationLoader#load(boolean, Object[])}
45 public void testLoad() throws Exception {
46 File logConfigRoot = new File(LogbackConfigurationLoaderTest.class
47 .getResource(LOGBACK_D).getFile());
48 List<File> sortedConfigFiles = LogbackConfigUtil.harvestSortedConfigFiles(logConfigRoot);
49 LogbackConfigurationLoader.load(true, sortedConfigFiles.toArray());
51 LOG.info("LOGBACK ready -> about to use it");
53 Tracer.doSomeAction();
54 Debugger.doSomeAction();
55 Informer.doSomeAction();
56 Warner.doSomeAction();
57 Errorer.doSomeAction();
60 String[] expectedLogs = new String[] {
61 "LoggingEvent -> [INFO] org.opendaylight.controller.logback.config.loader.test.LogbackConfigurationLoaderTest: LOGBACK ready -> about to use it",
62 "LoggingEvent -> [TRACE] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: tracing",
63 "LoggingEvent -> [DEBUG] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: debugging",
64 "LoggingEvent -> [INFO] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: infoing",
65 "LoggingEvent -> [WARN] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: warning",
66 "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Tracer: erroring",
67 "LoggingEvent -> [DEBUG] org.opendaylight.controller.logback.config.loader.test.logwork.Debugger: debugging",
68 "LoggingEvent -> [INFO] org.opendaylight.controller.logback.config.loader.test.logwork.Debugger: infoing",
69 "LoggingEvent -> [WARN] org.opendaylight.controller.logback.config.loader.test.logwork.Debugger: warning",
70 "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Debugger: erroring",
71 "LoggingEvent -> [INFO] org.opendaylight.controller.logback.config.loader.test.logwork.Informer: infoing",
72 "LoggingEvent -> [WARN] org.opendaylight.controller.logback.config.loader.test.logwork.Informer: warning",
73 "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Informer: erroring",
74 "LoggingEvent -> [WARN] org.opendaylight.controller.logback.config.loader.test.logwork.Warner: warning",
75 "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Warner: erroring",
76 "LoggingEvent -> [ERROR] org.opendaylight.controller.logback.config.loader.test.logwork.Errorer: erroring"
80 List<String> logSnapshot = new ArrayList<>(TestAppender.getLogRecord());
81 for (String logLine : logSnapshot) {
82 LOG.info("\"{}\",", logLine);
85 Assert.assertArrayEquals(expectedLogs, logSnapshot.toArray());