Add log4j2 agent tests
[lttng-ust-java-tests.git] / lttng-ust-java-tests-log4j2 / src / test / java / org / lttng / ust / agent / integration / events / Log4j2EnabledEventsIT.java
CommitLineData
eca1a136
MJ
1/*
2 * Copyright (C) 2022, EfficiOS Inc.
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
19package org.lttng.ust.agent.integration.events;
20
21import java.io.IOException;
22import java.util.Map;
23
24import org.apache.logging.log4j.core.Appender;
25import org.apache.logging.log4j.core.Logger;
26import org.junit.After;
27import org.junit.AfterClass;
28import org.junit.Before;
29import org.junit.BeforeClass;
30import org.junit.Test;
31import org.lttng.tools.ILttngSession.Domain;
32import org.lttng.ust.agent.ILttngHandler;
33import org.lttng.ust.agent.log4j2.LttngLogAppender;
34import org.lttng.ust.agent.utils.Log4j2TestContext;
35import org.lttng.ust.agent.utils.Log4j2TestUtils;
36
37/**
38 * Enabled events test for the LTTng-UST Log4j log handler.
39 */
40public class Log4j2EnabledEventsIT extends EnabledEventsITBase {
41
42 private static final String APPENDER_NAME_A = "LttngA";
43 private static final String APPENDER_NAME_B = "LttngB";
44 private static final String APPENDER_NAME_C = "LttngC";
45
46 private static final Domain DOMAIN = Domain.LOG4J;
47
48 private Log4j2TestContext testContext;
49
50 private Logger loggerA;
51 private Logger loggerB;
52 private Logger loggerC;
53 private Logger loggerD;
54
55 /**
56 * Class setup
57 */
58 @BeforeClass
59 public static void log4j2ClassSetup() {
60 Log4j2TestUtils.testClassSetup();
61 }
62
63 /**
64 * Class cleanup
65 */
66 @AfterClass
67 public static void log4j2ClassCleanup() {
68 Log4j2TestUtils.testClassCleanup();
69 }
70
71 /**
72 * Test setup
73 *
74 * @throws SecurityException
75 * @throws IOException
76 */
77 @SuppressWarnings("resource")
78 @Before
79 public void log4j2Setup() throws SecurityException, IOException {
80
81 testContext = new Log4j2TestContext("log4j2.Log4j2EnabledEventsIT.xml");
82
83 testContext.beforeTest();
84
85 loggerA = testContext.getLoggerContext().getLogger(EVENT_NAME_A);
86 loggerB = testContext.getLoggerContext().getLogger(EVENT_NAME_B);
87 loggerC = testContext.getLoggerContext().getLogger(EVENT_NAME_C);
88 loggerD = testContext.getLoggerContext().getLogger(EVENT_NAME_D);
89
90 handlerA = (ILttngHandler) loggerA.getAppenders().get(APPENDER_NAME_A);
91 handlerB = (ILttngHandler) loggerB.getAppenders().get(APPENDER_NAME_B);
92 handlerC = (ILttngHandler) loggerC.getAppenders().get(APPENDER_NAME_C);
93 }
94
95 /**
96 * Test teardown
97 */
98 @After
99 public void log4j2Teardown() {
100 loggerA = null;
101 loggerB = null;
102 loggerC = null;
103 loggerD = null;
104
105 testContext.afterTest();
106 }
107
108 @Override
109 protected Domain getDomain() {
110 return DOMAIN;
111 }
112
113 @Override
114 protected boolean closeHandlers()
115 {
116 return false;
117 }
118
119 @Override
120 protected void sendEventsToLoggers() {
121 Log4j2TestUtils.send10Events(loggerA);
122 Log4j2TestUtils.send10Events(loggerB);
123 Log4j2TestUtils.send10Events(loggerC);
124 Log4j2TestUtils.send10Events(loggerD);
125 }
126
127 @Override
128 protected void sendLocalizedEvent(String rawString, Object[] params) {
129 throw new UnsupportedOperationException();
130 }
131
132 @Override
133 @Test
134 public void testLocalizedMessage() {
135 /* Does not apply to log4j 1.2.x */
136 }
137}
This page took 0.027034 seconds and 4 git commands to generate.