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