|
30 | 30 |
|
31 | 31 | package com.amazon.opendistroforelasticsearch.security.test;
|
32 | 32 |
|
33 |
| -import io.netty.handler.ssl.OpenSsl; |
34 |
| - |
35 | 33 | import java.net.InetSocketAddress;
|
36 | 34 | import java.nio.charset.StandardCharsets;
|
37 | 35 | import java.util.Arrays;
|
|
44 | 42 | import org.apache.http.message.BasicHeader;
|
45 | 43 | import org.apache.logging.log4j.LogManager;
|
46 | 44 | import org.apache.logging.log4j.Logger;
|
| 45 | +import org.apache.logging.log4j.junit.LoggerContextRule; |
| 46 | +import org.apache.logging.log4j.test.appender.ListAppender; |
47 | 47 | import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
|
48 | 48 | import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
49 | 49 | import org.elasticsearch.action.get.GetRequest;
|
|
57 | 57 | import org.elasticsearch.threadpool.ThreadPool;
|
58 | 58 | import org.elasticsearch.transport.Netty4Plugin;
|
59 | 59 | import org.junit.Assert;
|
| 60 | +import org.junit.Before; |
| 61 | +import org.junit.BeforeClass; |
| 62 | +import org.junit.ClassRule; |
60 | 63 | import org.junit.Rule;
|
61 | 64 | import org.junit.rules.TemporaryFolder;
|
62 | 65 | import org.junit.rules.TestName;
|
63 |
| -import org.junit.rules.TestWatcher; |
64 | 66 |
|
65 | 67 | import com.amazon.opendistroforelasticsearch.security.OpenDistroSecurityPlugin;
|
66 | 68 | import com.amazon.opendistroforelasticsearch.security.action.configupdate.ConfigUpdateAction;
|
|
72 | 74 | import com.amazon.opendistroforelasticsearch.security.test.helper.cluster.ClusterInfo;
|
73 | 75 | import com.amazon.opendistroforelasticsearch.security.test.helper.file.FileHelper;
|
74 | 76 | import com.amazon.opendistroforelasticsearch.security.test.helper.rest.RestHelper.HttpResponse;
|
75 |
| -import com.amazon.opendistroforelasticsearch.security.test.helper.rules.OpenDistroSecurityTestWatcher; |
| 77 | + |
| 78 | +import io.netty.handler.ssl.OpenSsl; |
76 | 79 |
|
77 | 80 | public abstract class AbstractSecurityUnitTest {
|
78 | 81 |
|
@@ -106,8 +109,8 @@ public abstract class AbstractSecurityUnitTest {
|
106 | 109 | @Rule
|
107 | 110 | public final TemporaryFolder repositoryPath = new TemporaryFolder();
|
108 | 111 |
|
109 |
| - @Rule |
110 |
| - public final TestWatcher testWatcher = new OpenDistroSecurityTestWatcher(); |
| 112 | + //@Rule |
| 113 | + //public final TestWatcher testWatcher = new OpenDistroSecurityTestWatcher(); |
111 | 114 |
|
112 | 115 | public static Header encodeBasicHeader(final String username, final String password) {
|
113 | 116 | return new BasicHeader("Authorization", "Basic "+Base64.getEncoder().encodeToString(
|
@@ -253,4 +256,27 @@ protected final void assertNotContains(HttpResponse res, String pattern) {
|
253 | 256 | protected String getResourceFolder() {
|
254 | 257 | return null;
|
255 | 258 | }
|
| 259 | + |
| 260 | + protected static ListAppender appender; |
| 261 | + |
| 262 | + @ClassRule |
| 263 | + public static LoggerContextRule init = new LoggerContextRule("log4j2-test.properties"); |
| 264 | + |
| 265 | + @BeforeClass |
| 266 | + public static void setupLogging() { |
| 267 | + try { |
| 268 | + appender = init.getListAppender("list"); |
| 269 | + } catch (Throwable e) { |
| 270 | + //ignore |
| 271 | + } |
| 272 | + } |
| 273 | + |
| 274 | + @Before |
| 275 | + public void clearAppender() { |
| 276 | + |
| 277 | + if(appender != null) { |
| 278 | + appender.clear(); |
| 279 | + } |
| 280 | + } |
| 281 | + |
256 | 282 | }
|
0 commit comments