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;
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;
28 * test of logging config loader - {@link LogbackConfigurationLoader}
30 @RunWith(JUnit4.class)
31 public class LogbackConfigurationLoaderTest {
33 /** logback config root */
34 private static final String LOGBACK_D = "/logback.d";
35 private static final Logger LOG = LoggerFactory
36 .getLogger(LogbackConfigurationLoaderTest.class);
39 * Test of method {@link LogbackConfigurationLoader#load(boolean, Object[])}
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());
50 LOG.info("LOGBACK ready -> about to use it");
52 Tracer.doSomeAction();
53 Debugger.doSomeAction();
54 Informer.doSomeAction();
55 Warner.doSomeAction();
56 Errorer.doSomeAction();
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"
78 List<String> logSnapshot = new ArrayList<>(TestAppender.getLogRecord());
79 for (String logLine : logSnapshot) {
80 LOG.info("\"{}\",", logLine);
83 Assert.assertArrayEquals(expectedLogs, logSnapshot.toArray());