Skip to content

Commit 394e4aa

Browse files
committed
Use alternative route to check logs
1 parent b503166 commit 394e4aa

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

extensions/indexes/range/pom.xml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
-->
2525
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2626
<modelVersion>4.0.0</modelVersion>
27-
27+
2828
<parent>
2929
<groupId>org.exist-db</groupId>
3030
<artifactId>exist-parent</artifactId>
@@ -42,8 +42,8 @@
4242
<connection>scm:git:https://github.com/exist-db/exist.git</connection>
4343
<developerConnection>scm:git:https://github.com/exist-db/exist.git</developerConnection>
4444
<url>scm:git:https://github.com/exist-db/exist.git</url>
45-
<tag>HEAD</tag>
46-
</scm>
45+
<tag>HEAD</tag>
46+
</scm>
4747

4848
<dependencies>
4949
<dependency>
@@ -67,7 +67,7 @@
6767
<artifactId>lucene-core</artifactId>
6868
<version>${lucene.version}</version>
6969
</dependency>
70-
70+
7171
<dependency>
7272
<groupId>org.apache.lucene</groupId>
7373
<artifactId>lucene-analyzers-common</artifactId>
@@ -113,6 +113,13 @@
113113
<scope>test</scope>
114114
</dependency>
115115

116+
<dependency>
117+
<groupId>io.github.hakky54</groupId>
118+
<artifactId>logcaptor</artifactId>
119+
<version>2.9.3</version>
120+
<scope>test</scope>
121+
</dependency>
122+
116123
</dependencies>
117124

118125
<build>
@@ -128,6 +135,26 @@
128135
</testResources>
129136

130137
<plugins>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-surefire-plugin</artifactId>
141+
<configuration>
142+
<classpathDependencyExcludes>
143+
<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j-impl</classpathDependencyExclude>
144+
<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j2-impl</classpathDependencyExclude>
145+
</classpathDependencyExcludes>
146+
</configuration>
147+
</plugin>
148+
<plugin>
149+
<groupId>org.apache.maven.plugins</groupId>
150+
<artifactId>maven-failsafe-plugin</artifactId>
151+
<configuration>
152+
<classpathDependencyExcludes>
153+
<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j-impl</classpathDependencyExclude>
154+
<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j2-impl</classpathDependencyExclude>
155+
</classpathDependencyExcludes>
156+
</configuration>
157+
</plugin>
131158
<plugin>
132159
<groupId>org.apache.maven.plugins</groupId>
133160
<artifactId>maven-dependency-plugin</artifactId>

extensions/indexes/range/src/test/java/org/exist/indexing/range/RangeIndexConfigTest.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,23 @@
2121
*/
2222
package org.exist.indexing.range;
2323

24+
import nl.altindag.log.LogCaptor;
2425
import org.apache.logging.log4j.Logger;
2526
import org.easymock.Capture;
26-
import org.exist.util.JDKCompatibility;
2727
import org.junit.Test;
2828
import org.w3c.dom.Document;
2929
import org.w3c.dom.Element;
3030
import org.w3c.dom.Node;
3131
import org.w3c.dom.NodeList;
3232

33-
import java.lang.reflect.Field;
34-
import java.lang.reflect.Modifier;
3533
import java.util.HashMap;
3634
import java.util.Map;
3735

38-
import static junit.framework.TestCase.assertTrue;
3936
import static org.easymock.EasyMock.*;
4037
import static org.exist.collections.CollectionConfiguration.DEFAULT_COLLECTION_CONFIG_FILE;
4138
import static org.exist.indexing.lucene.LuceneIndexConfig.MATCH_ATTR;
4239
import static org.exist.indexing.lucene.LuceneIndexConfig.QNAME_ATTR;
40+
import static org.junit.Assert.assertTrue;
4341

4442
public class RangeIndexConfigTest {
4543

@@ -88,30 +86,20 @@ public void errorsHaveSourceContext() throws NoSuchFieldException, IllegalAccess
8886
replay(mockConfigNodes, mockConfigNode, mockCreates, mockCreateDocument, mockCreate, mockEmptyNodeList, mockLogger);
8987

9088

91-
9289
final Map<String, String> namespaces = new HashMap<>();
9390
namespaces.put("tei", "http://www.tei-c.org/ns/1.0");
9491

95-
overrideLogger(RangeIndexConfig.class, mockLogger);
96-
final RangeIndexConfig config = new RangeIndexConfig(mockConfigNodes, namespaces);
97-
98-
assertTrue(errorMsgCapture.getValue().contains("Illegal QName: '" + badCreateQName + "'.. QName is invalid: INVALID_LOCAL_PART"));
99-
assertTrue(errorMsgCapture.getValue().contains("(" + mockCollectionXConfUri + ")"));
92+
LogCaptor logCaptor = LogCaptor.forClass(RangeIndexConfig.class);
10093

101-
verify(mockConfigNodes, mockConfigNode, mockCreates, mockCreateDocument, mockCreate, mockEmptyNodeList, mockLogger);
102-
}
103-
104-
private void overrideLogger(final Class clazz, final Logger logger) throws NoSuchFieldException, IllegalAccessException {
105-
final Field loggerField = clazz.getDeclaredField("LOG");
94+
final RangeIndexConfig config = new RangeIndexConfig(mockConfigNodes, namespaces);
10695

107-
// allow access to private field
108-
loggerField.setAccessible(true);
96+
assertTrue(logCaptor.getLogs().get(0)
97+
.contains("Illegal QName: '" + badCreateQName + "'.. QName is invalid: INVALID_LOCAL_PART"));
10998

110-
// remove final modifier
111-
final Field modifiersField = JDKCompatibility.getModifiersField();
112-
modifiersField.setAccessible(true);
113-
modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL);
99+
assertTrue(logCaptor.getLogs().get(0)
100+
.contains("(" + mockCollectionXConfUri + ")"));
114101

115-
loggerField.set(null, logger);
102+
verify(mockConfigNodes, mockConfigNode, mockCreates, mockCreateDocument, mockCreate, mockEmptyNodeList);
116103
}
104+
117105
}

0 commit comments

Comments
 (0)