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