Add 'log4j2' domain tests to the Log4j 2.x agent
[lttng-ust-java-tests.git] / lttng-ust-java-tests-log4j2 / src / main / java / org / lttng / ust / agent / integration / context / Log4j2AppContextOrderingITBase.java
CommitLineData
9db2c69a
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
21
22import org.apache.logging.log4j.core.Logger;
23import org.junit.jupiter.api.AfterAll;
24import org.junit.jupiter.api.AfterEach;
25import org.junit.jupiter.api.BeforeAll;
26import org.junit.jupiter.api.TestInstance;
27import org.junit.jupiter.api.TestInstance.Lifecycle;
28import org.lttng.ust.agent.ILttngHandler;
29import org.lttng.ust.agent.utils.Log4j2TestContext;
30import org.lttng.ust.agent.utils.Log4j2TestUtils;
31
32/**
33 * Implementation of {@link AppContextOrderingITBase} for the log4j API.
34 */
35@TestInstance(Lifecycle.PER_CLASS)
36public abstract class Log4j2AppContextOrderingITBase extends AppContextOrderingITBase {
37
38 private Log4j2TestContext testContext;
39 private Logger logger;
40
41 /**
42 * Class setup
43 */
44 @BeforeAll
45 public void log4j2ClassSetup() {
46 Log4j2TestUtils.testClassSetup(getDomain());
47 }
48
49 /**
50 * Class cleanup
51 */
52 @AfterAll
53 public static void log4j2ClassCleanup() {
54 Log4j2TestUtils.testClassCleanup();
55 }
56
57 /**
58 * Test teardown
59 */
60 @AfterEach
61 public void log4j2Teardown() {
62 logger = null;
63 logHandler = null;
64
65 testContext.afterTest();
66 }
67
68 @SuppressWarnings("resource")
69 @Override
70 protected void registerAgent() {
71 testContext = new Log4j2TestContext("log4j2." + this.getClass().getSimpleName() + ".xml");
72
73 testContext.beforeTest();
74
75 logger = testContext.getLoggerContext().getLogger(EVENT_NAME);
76
77 logHandler = (ILttngHandler) logger.getAppenders().get("Lttng");
78 }
79
80 @Override
81 protected void sendEventsToLoggers() {
82 Log4j2TestUtils.send10Events(logger);
83 }
84}
This page took 0.025896 seconds and 4 git commands to generate.