Commit | Line | Data |
---|---|---|
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 | ||
19 | package org.lttng.ust.agent.integration.context; | |
20 | ||
21 | import java.io.IOException; | |
22 | ||
23 | import org.apache.logging.log4j.core.Logger; | |
7a4f0255 MJ |
24 | import org.junit.jupiter.api.AfterAll; |
25 | import org.junit.jupiter.api.AfterEach; | |
26 | import org.junit.jupiter.api.BeforeAll; | |
27 | import org.junit.jupiter.api.BeforeEach; | |
eca1a136 MJ |
28 | import org.lttng.tools.ILttngSession.Domain; |
29 | import org.lttng.ust.agent.ILttngHandler; | |
30 | import org.lttng.ust.agent.utils.Log4j2TestContext; | |
31 | import org.lttng.ust.agent.utils.Log4j2TestUtils; | |
32 | ||
33 | /** | |
34 | * Enabled app contexts test for the LTTng-UST Log4j 2.x log handler. | |
35 | */ | |
36 | public class Log4j2AppContextIT extends AppContextITBase { | |
37 | ||
38 | private static final Domain DOMAIN = Domain.LOG4J; | |
39 | ||
40 | private Log4j2TestContext testContext; | |
41 | private Logger logger; | |
42 | ||
43 | /** | |
44 | * Class setup | |
45 | */ | |
7a4f0255 | 46 | @BeforeAll |
eca1a136 MJ |
47 | public static void log4j2ClassSetup() { |
48 | Log4j2TestUtils.testClassSetup(); | |
49 | } | |
50 | ||
51 | /** | |
52 | * Class cleanup | |
53 | */ | |
7a4f0255 | 54 | @AfterAll |
eca1a136 MJ |
55 | public static void log4j2ClassCleanup() { |
56 | Log4j2TestUtils.testClassCleanup(); | |
57 | } | |
58 | ||
59 | /** | |
60 | * Test setup | |
61 | * | |
62 | * @throws SecurityException | |
63 | * @throws IOException | |
64 | */ | |
7a4f0255 MJ |
65 | @SuppressWarnings("resource") |
66 | @BeforeEach | |
eca1a136 MJ |
67 | public void log4j2Setup() throws SecurityException, IOException { |
68 | testContext = new Log4j2TestContext("log4j2.Log4j2AppContextIT.xml"); | |
69 | ||
70 | testContext.beforeTest(); | |
71 | ||
72 | logger = testContext.getLoggerContext().getLogger(EVENT_NAME); | |
73 | ||
74 | logHandler = (ILttngHandler) logger.getAppenders().get("Lttng"); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Test teardown | |
79 | */ | |
7a4f0255 | 80 | @AfterEach |
eca1a136 MJ |
81 | public void log4j2Teardown() { |
82 | testContext.afterTest(); | |
83 | logger = null; | |
84 | } | |
85 | ||
86 | @Override | |
87 | protected Domain getDomain() { | |
88 | return DOMAIN; | |
89 | } | |
90 | ||
91 | @Override | |
92 | protected boolean closeHandlers() | |
93 | { | |
94 | return false; | |
95 | } | |
96 | ||
97 | @Override | |
98 | protected void sendEventsToLoggers() { | |
99 | Log4j2TestUtils.send10Events(logger); | |
100 | } | |
101 | } |