Migrate to Junit 5 Jupiter
[lttng-ust-java-tests.git] / lttng-ust-java-tests-jul / src / test / java / org / lttng / ust / agent / integration / events / JulLegacyApiLoggerHierarchyListIT.java
CommitLineData
fe6a3925
AM
1/*
2 * Copyright (C) 2016, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
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.events;
20
7a4f0255 21import static org.junit.jupiter.api.Assertions.assertEquals;
fe6a3925
AM
22
23import java.io.IOException;
24import java.util.ArrayList;
25import java.util.Collections;
26import java.util.List;
27import java.util.logging.LogManager;
28import java.util.logging.Logger;
29
7a4f0255
MJ
30import org.junit.jupiter.api.AfterAll;
31import org.junit.jupiter.api.AfterEach;
32import org.junit.jupiter.api.BeforeAll;
33import org.junit.jupiter.api.BeforeEach;
34import org.junit.jupiter.params.ParameterizedTest;
35import org.junit.jupiter.params.provider.MethodSource;
fe6a3925
AM
36import org.lttng.tools.ILttngSession.Domain;
37import org.lttng.ust.agent.LTTngAgent;
38import org.lttng.ust.agent.utils.JulTestUtils;
39
40/**
41 * Implementation of {@link LoggerHierachyListITBase} for the JUL part of the
42 * legacy LTTngAgent API.
43 *
44 * @author Alexandre Montplaisir
45 */
46@SuppressWarnings("deprecation")
7a4f0255 47//@RunWith(Parameterized.class)
fe6a3925
AM
48public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase {
49
50 private LTTngAgent agent;
51 private Logger parentLogger;
52 private Logger childLogger;
53
fe6a3925
AM
54 // ------------------------------------------------------------------------
55 // Maintenance
56 // ------------------------------------------------------------------------
57
58 /**
59 * Class setup
60 */
7a4f0255 61 @BeforeAll
fe6a3925
AM
62 public static void julClassSetup() {
63 JulTestUtils.testClassSetup();
64 }
65
66 /**
67 * Class cleanup
68 */
7a4f0255 69 @AfterAll
fe6a3925
AM
70 public static void julClassCleanup() {
71 JulTestUtils.testClassCleanup();
72 }
73
74 /**
75 * Test setup
76 */
77 @SuppressWarnings("static-method")
7a4f0255 78 @BeforeEach
fe6a3925
AM
79 public void setup() {
80 LogManager.getLogManager().reset();
81 System.gc();
82 }
83
84 /**
85 * Test cleanup
86 */
7a4f0255 87 @AfterEach
fe6a3925
AM
88 public void cleanup() {
89 agent.dispose();
90
91 if (parentLogger != null) {
92 parentLogger = null;
93 }
94
95 if (childLogger != null) {
96 childLogger = null;
97 }
98
99 LogManager.getLogManager().reset();
100 System.gc();
101 }
102
103 // ------------------------------------------------------------------------
104 // Abstract methods
105 // ------------------------------------------------------------------------
106
107 @Override
108 protected Domain getDomain() {
109 return Domain.JUL;
110 }
111
112 @Override
7a4f0255
MJ
113 protected void activateLoggers(boolean parentLoggerActive,
114 boolean parentLoggerHasHandler,
115 boolean childLoggerActive,
116 boolean childLoggerHasHandler) throws IOException {
fe6a3925
AM
117 agent = LTTngAgent.getLTTngAgent();
118
119 /*
120 * There is no notion of "hasHandler" for the legacy API: there is only
121 * one log handler attached to the root logger, so there are no handlers
122 * to specific events/loggers.
123 */
124
125 if (parentLoggerActive) {
126 parentLogger = Logger.getLogger(PARENT_LOGGER);
127 }
128
129 if (childLoggerActive) {
130 childLogger = Logger.getLogger(CHILD_LOGGER);
131 }
132 }
133
134 // ------------------------------------------------------------------------
135 // Overridden tests
136 // ------------------------------------------------------------------------
137
138 /**
139 * Due to how the legacy agent works, there is no notion of "hasHandler". If
140 * the logger exists, it will be visible in "lttng list" because the single
141 * log handler is attached to the root logger.
142 */
7a4f0255 143 @SuppressWarnings("resource")
fe6a3925 144 @Override
7a4f0255
MJ
145 @ParameterizedTest
146 @MethodSource("provideArguments")
147 public void testList(boolean parentLoggerActive,
148 boolean parentLoggerHasHandler,
149 boolean childLoggerActive,
150 boolean childLoggerHasHandler) throws IOException {
151
152 activateLoggers(parentLoggerActive,
153 parentLoggerHasHandler,
154 childLoggerActive,
155 childLoggerHasHandler);
fe6a3925
AM
156
157 List<String> enabledEvents = getSession().listEvents();
158 List<String> expectedEvents = new ArrayList<>();
159
160 if (parentLoggerActive) {
161 expectedEvents.add(PARENT_LOGGER);
162 }
163 if (childLoggerActive) {
164 expectedEvents.add(CHILD_LOGGER);
165 }
166
167 Collections.sort(enabledEvents);
168 Collections.sort(expectedEvents);
169 assertEquals(expectedEvents, enabledEvents);
170 }
171
172}
This page took 0.028811 seconds and 4 git commands to generate.