Add log4j2 agent tests
[lttng-ust-java-tests.git] / lttng-ust-java-tests-log4j2 / src / test / java / org / lttng / ust / agent / integration / events / Log4j2ListEventsIT.java
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.events;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertTrue;
23
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.List;
27
28 import org.apache.logging.log4j.Logger;
29 import org.junit.After;
30 import org.junit.AfterClass;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.TestName;
36 import org.lttng.tools.ILttngSession;
37 import org.lttng.ust.agent.utils.Log4j2TestContext;
38 import org.lttng.ust.agent.utils.Log4j2TestUtils;
39
40 /**
41 * Test suite for the list events command for the log4j domain
42 */
43 public class Log4j2ListEventsIT {
44
45 protected static final String LOGGER_NAME_1 = "org.lttng.somecomponent";
46 protected static final String LOGGER_NAME_2 = "org.lttng.mycomponent";
47 protected static final String LOGGER_NAME_3 = "org.lttng.myothercomponent-àéç";
48
49 private Logger logger1;
50 private Logger logger2;
51 private Logger logger3;
52
53 private ILttngSession session;
54 private Log4j2TestContext testContext;
55
56 @Rule
57 public TestName testName = new TestName();
58
59 /**
60 * Class setup
61 */
62 @BeforeClass
63 public static void log4j2ClassSetup() {
64 Log4j2TestUtils.testClassSetup();
65 }
66
67 /**
68 * Class cleanup
69 */
70 @AfterClass
71 public static void log4j2ClassCleanup() {
72 Log4j2TestUtils.testClassCleanup();
73 }
74
75 /**
76 * Create a new session before each test.
77 */
78 @Before
79 public void testSetup() {
80 session = ILttngSession.createSession("Log4j2ListEventsIT", ILttngSession.Domain.LOG4J);
81
82 testContext = new Log4j2TestContext("log4j2." + testName.getMethodName() + ".xml");
83
84 testContext.beforeTest();
85
86 logger1 = testContext.getLoggerContext().getLogger(LOGGER_NAME_1);
87 logger2 = testContext.getLoggerContext().getLogger(LOGGER_NAME_2);
88 logger3 = testContext.getLoggerContext().getLogger(LOGGER_NAME_3);
89 }
90
91 /**
92 * Close the current session after each test.
93 */
94 @After
95 public void testTeardown() {
96 session.close();
97 testContext.afterTest();
98 }
99
100 /**
101 * Test with many loggers existing, but none of them having a LTTng handler
102 * attached.
103 */
104 @Test
105 public void testManyLoggersNoneAttached() {
106
107 /* Don't attach anything */
108 List<String> actualEvents = session.listEvents();
109 assertTrue(actualEvents.isEmpty());
110 }
111
112 /**
113 * Test with many loggers existing, but only a subset of them has a LTTng
114 * handler attached.
115 */
116 @Test
117 public void testManyLoggersSomeAttached() {
118
119 List<String> expectedEvents = Arrays.asList(LOGGER_NAME_1);
120 List<String> actualEvents = session.listEvents();
121
122 Collections.sort(expectedEvents);
123 Collections.sort(actualEvents);
124
125 assertEquals(expectedEvents, actualEvents);
126 }
127
128 /**
129 * Test with many loggers existing, and all of them having a LTTng handler
130 * attached.
131 */
132 @Test
133 public void testManyLoggersAllAttached() {
134
135 List<String> expectedEvents = Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2, LOGGER_NAME_3);
136 List<String> actualEvents = session.listEvents();
137
138 Collections.sort(expectedEvents);
139 Collections.sort(actualEvents);
140
141 assertEquals(expectedEvents, actualEvents);
142 }
143 }
This page took 0.031688 seconds and 4 git commands to generate.