Add 'log4j2' domain tests to the Log4j 2.x agent
[lttng-ust-java-tests.git] / lttng-ust-java-tests-jul / src / test / java / org / lttng / ust / agent / integration / events / JulEnabledEventsIT.java
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
19 package org.lttng.ust.agent.integration.events;
20
21 import java.io.IOException;
22 import java.util.logging.Handler;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25
26 import org.junit.jupiter.api.AfterAll;
27 import org.junit.jupiter.api.AfterEach;
28 import org.junit.jupiter.api.BeforeAll;
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Tag;
31 import org.lttng.tools.ILttngSession.Domain;
32 import org.lttng.ust.agent.jul.LttngLogHandler;
33 import org.lttng.ust.agent.utils.JulTestUtils;
34
35 /**
36 * Enabled events test for the LTTng-UST JUL log handler.
37 */
38 @Tag("agent:jul")
39 @Tag("domain:jul")
40 public class JulEnabledEventsIT extends EnabledEventsITBase {
41
42 private static final Domain DOMAIN = Domain.JUL;
43
44 private Logger loggerA;
45 private Logger loggerB;
46 private Logger loggerC;
47 private Logger loggerD;
48
49 /**
50 * Class setup
51 */
52 @BeforeAll
53 public static void julClassSetup() {
54 JulTestUtils.testClassSetup();
55 }
56
57 /**
58 * Class cleanup
59 */
60 @AfterAll
61 public static void julClassCleanup() {
62 JulTestUtils.testClassCleanup();
63 }
64
65 /**
66 * Test setup
67 *
68 * @throws SecurityException
69 * @throws IOException
70 */
71 @BeforeEach
72 public void julSetup() throws SecurityException, IOException {
73 loggerA = Logger.getLogger(EVENT_NAME_A);
74 loggerB = Logger.getLogger(EVENT_NAME_B);
75 loggerC = Logger.getLogger(EVENT_NAME_C);
76 loggerD = Logger.getLogger(EVENT_NAME_D);
77
78 loggerA.setLevel(Level.ALL);
79 loggerB.setLevel(Level.ALL);
80 loggerC.setLevel(Level.ALL);
81 loggerD.setLevel(Level.ALL);
82
83 handlerA = new LttngLogHandler();
84 handlerB = new LttngLogHandler();
85 handlerC = new LttngLogHandler();
86
87 loggerA.addHandler((Handler) handlerA);
88 loggerB.addHandler((Handler) handlerB);
89 loggerC.addHandler((Handler) handlerC);
90 }
91
92 /**
93 * Test teardown
94 */
95 @AfterEach
96 public void julTeardown() {
97 loggerA.removeHandler((Handler) handlerA);
98 loggerB.removeHandler((Handler) handlerB);
99 loggerC.removeHandler((Handler) handlerC);
100
101 loggerA = null;
102 loggerB = null;
103 loggerC = null;
104 loggerD = null;
105 }
106
107 @Override
108 protected Domain getDomain() {
109 return DOMAIN;
110 }
111
112 @Override
113 protected boolean closeHandlers()
114 {
115 return true;
116 }
117
118 @Override
119 protected void sendEventsToLoggers() {
120 JulTestUtils.send10EventsTo(loggerA);
121 JulTestUtils.send10EventsTo(loggerB);
122 JulTestUtils.send10EventsTo(loggerC);
123 JulTestUtils.send10EventsTo(loggerD);
124 }
125
126 @Override
127 protected void sendLocalizedEvent(String rawString, Object[] params) {
128 loggerA.log(Level.SEVERE, rawString, params);
129 }
130 }
This page took 0.032666 seconds and 4 git commands to generate.