Add log4j2 agent tests
[lttng-ust-java-tests.git] / lttng-ust-java-tests-log4j2 / src / test / java / org / lttng / ust / agent / integration / context / Log4j2AppContextIT.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.context;
20
21import java.io.IOException;
22
23import org.apache.logging.log4j.core.Logger;
24
25import org.junit.After;
26import org.junit.AfterClass;
27import org.junit.Before;
28import org.junit.BeforeClass;
29import org.lttng.tools.ILttngSession.Domain;
30import org.lttng.ust.agent.ILttngHandler;
31import org.lttng.ust.agent.utils.Log4j2TestContext;
32import org.lttng.ust.agent.utils.Log4j2TestUtils;
33
34/**
35 * Enabled app contexts test for the LTTng-UST Log4j 2.x log handler.
36 */
37public class Log4j2AppContextIT extends AppContextITBase {
38
39 private static final Domain DOMAIN = Domain.LOG4J;
40
41 private Log4j2TestContext testContext;
42 private Logger logger;
43
44 /**
45 * Class setup
46 */
47 @BeforeClass
48 public static void log4j2ClassSetup() {
49 Log4j2TestUtils.testClassSetup();
50 }
51
52 /**
53 * Class cleanup
54 */
55 @AfterClass
56 public static void log4j2ClassCleanup() {
57 Log4j2TestUtils.testClassCleanup();
58 }
59
60 /**
61 * Test setup
62 *
63 * @throws SecurityException
64 * @throws IOException
65 */
66 @Before
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 */
80 @After
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}
This page took 0.025489 seconds and 4 git commands to generate.