Add copyright header to all source files
[lttng-ust-java-tests.git] / src / test / java / org / lttng / ust / agent / integration / log4j / Log4jEnabledEventsTest.java
CommitLineData
2b408e85
AM
1/*
2 * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
c5524c71
AM
19package org.lttng.ust.agent.integration.log4j;
20
21import static org.junit.Assume.assumeTrue;
22
23import java.io.IOException;
c5524c71
AM
24
25import org.apache.log4j.Appender;
26import org.apache.log4j.Level;
27import org.apache.log4j.Logger;
28import org.junit.After;
29import org.junit.AfterClass;
30import org.junit.Before;
31import org.junit.BeforeClass;
24b260d9 32import org.lttng.ust.agent.integration.EnabledEventsTestBase;
c5524c71 33import org.lttng.ust.agent.log4j.LttngLogAppender;
8576633f
AM
34import org.lttng.ust.agent.utils.LttngSession;
35import org.lttng.ust.agent.utils.LttngSession.Domain;
24b260d9 36import org.lttng.ust.agent.utils.MiscTestUtils;
c5524c71 37
24b260d9 38public class Log4jEnabledEventsTest extends EnabledEventsTestBase {
c5524c71
AM
39
40 private static final Domain DOMAIN = Domain.LOG4J;
41
42 private Logger loggerA;
43 private Logger loggerB;
44 private Logger loggerC;
45 private Logger loggerD;
46
47 @BeforeClass
e41ec02a 48 public static void log4jClassSetup() {
c5524c71 49 /* Skip tests if we can't find the JNI library or lttng-tools */
24b260d9
AM
50 assumeTrue(MiscTestUtils.checkForLog4jLibrary());
51 assumeTrue(MiscTestUtils.checkForLttngTools(Domain.LOG4J));
e41ec02a
AM
52
53 LttngSession.destroyAllSessions();
c5524c71
AM
54 }
55
56 @AfterClass
e41ec02a 57 public static void log4jClassCleanup() {
8576633f 58 LttngSession.deleteAllTracee();
c5524c71
AM
59 }
60
61 @Before
e41ec02a 62 public void log4jSetup() throws SecurityException, IOException {
c5524c71
AM
63 loggerA = Logger.getLogger(EVENT_NAME_A);
64 loggerB = Logger.getLogger(EVENT_NAME_B);
65 loggerC = Logger.getLogger(EVENT_NAME_C);
66 loggerD = Logger.getLogger(EVENT_NAME_D);
67
68 loggerA.setLevel(Level.ALL);
69 loggerB.setLevel(Level.ALL);
70 loggerC.setLevel(Level.ALL);
71 loggerD.setLevel(Level.ALL);
72
73 handlerA = new LttngLogAppender();
74 handlerB = new LttngLogAppender();
75 handlerC = new LttngLogAppender();
76
77 loggerA.addAppender((Appender) handlerA);
78 loggerB.addAppender((Appender) handlerB);
79 loggerC.addAppender((Appender) handlerC);
80 }
81
82 @After
e41ec02a 83 public void log4jTeardown() {
c5524c71
AM
84 loggerA.removeAppender((Appender) handlerA);
85 loggerB.removeAppender((Appender) handlerB);
86 loggerC.removeAppender((Appender) handlerC);
87
88 loggerA = null;
89 loggerB = null;
90 loggerC = null;
91 loggerD = null;
92 }
93
94 @Override
95 protected Domain getDomain() {
96 return DOMAIN;
97 }
98
99 @Override
100 protected void sendEventsToLoggers() {
8576633f
AM
101 Log4jTestUtils.send10Events(loggerA);
102 Log4jTestUtils.send10Events(loggerB);
103 Log4jTestUtils.send10Events(loggerC);
104 Log4jTestUtils.send10Events(loggerD);
c5524c71
AM
105 }
106}
This page took 0.02717 seconds and 4 git commands to generate.