Skip to content

Commit 1ab86b8

Browse files
committed
[bugfix] Remove LogCaptor dependency from RangeIndex as it causes problems with Log4j
1 parent c443fe7 commit 1ab86b8

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

extensions/indexes/range/pom.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,6 @@
137137
<scope>test</scope>
138138
</dependency>
139139

140-
<dependency>
141-
<groupId>io.github.hakky54</groupId>
142-
<artifactId>logcaptor</artifactId>
143-
<version>2.11.0</version>
144-
<scope>test</scope>
145-
</dependency>
146-
147140
</dependencies>
148141

149142
<build>
@@ -195,6 +188,7 @@
195188
<include>src/test/resources/log4j2.xml</include>
196189
<include>src/test/xquery/range/conditions.xql</include>
197190
<include>src/main/java/org/exist/indexing/range/RangeIndexAnalyzer.java</include>
191+
<include>src/main/java/org/exist/indexing/range/RangeIndexConfig.java</include>
198192
<include>src/main/java/org/exist/indexing/range/RangeIndexConfigAttributeCondition.java</include>
199193
<include>src/main/java/org/exist/indexing/range/RangeIndexConfigElement.java</include>
200194
<include>src/main/java/org/exist/indexing/range/RangeIndexConfigField.java</include>
@@ -213,6 +207,7 @@
213207
<exclude>src/test/resources/log4j2.xml</exclude>
214208
<exclude>src/test/xquery/range/conditions.xql</exclude>
215209
<exclude>src/main/java/org/exist/indexing/range/RangeIndexAnalyzer.java</exclude>
210+
<exclude>src/main/java/org/exist/indexing/range/RangeIndexConfig.java</exclude>
216211
<exclude>src/main/java/org/exist/indexing/range/RangeIndexConfigAttributeCondition.java</exclude>
217212
<exclude>src/main/java/org/exist/indexing/range/RangeIndexConfigElement.java</exclude>
218213
<exclude>src/main/java/org/exist/indexing/range/RangeIndexConfigField.java</exclude>

extensions/indexes/range/src/main/java/org/exist/indexing/range/RangeIndexConfig.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -135,9 +159,9 @@ private void parseChildren(NodeList configNodes, Map<String, String> namespaces)
135159
}
136160

137161
if(uri != null) {
138-
LOG.error("Invalid range index configuration (" + uri + "): " + e.getMessage());
162+
getLogger().error("Invalid range index configuration (" + uri + "): " + e.getMessage());
139163
} else {
140-
LOG.error("Invalid range index configuration: " + e.getMessage());
164+
getLogger().error("Invalid range index configuration: " + e.getMessage());
141165
}
142166
}
143167
}
@@ -266,4 +290,13 @@ public void remove() {
266290
}
267291

268292
}
269-
}
293+
294+
/**
295+
* Designed to be overridable so that we can observe logging in tests.
296+
*
297+
* @return the logger.
298+
*/
299+
Logger getLogger() {
300+
return LOG;
301+
}
302+
}

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
*/
4646
package org.exist.indexing.range;
4747

48-
import nl.altindag.log.LogCaptor;
4948
import org.apache.logging.log4j.Logger;
5049
import org.easymock.Capture;
5150
import org.junit.Test;
@@ -104,7 +103,6 @@ public void errorsHaveSourceContext() throws NoSuchFieldException, IllegalAccess
104103
expect(mockCreateDocument.getDocumentURI()).andReturn(mockCollectionXConfUri);
105104

106105
final Capture<String> errorMsgCapture = newCapture();
107-
108106
mockLogger.error(capture(errorMsgCapture));
109107

110108
replay(mockConfigNodes, mockConfigNode, mockCreates, mockCreateDocument, mockCreate, mockEmptyNodeList, mockLogger);
@@ -113,15 +111,15 @@ public void errorsHaveSourceContext() throws NoSuchFieldException, IllegalAccess
113111
final Map<String, String> namespaces = new HashMap<>();
114112
namespaces.put("tei", "http://www.tei-c.org/ns/1.0");
115113

116-
LogCaptor logCaptor = LogCaptor.forClass(RangeIndexConfig.class);
117-
118-
final RangeIndexConfig config = new RangeIndexConfig(mockConfigNodes, namespaces);
119-
120-
assertTrue(logCaptor.getLogs().get(0)
121-
.contains("Illegal QName: '" + badCreateQName + "'.. QName is invalid: INVALID_LOCAL_PART"));
114+
final RangeIndexConfig config = new RangeIndexConfig(mockConfigNodes, namespaces) {
115+
@Override
116+
Logger getLogger() {
117+
return mockLogger;
118+
}
119+
};
122120

123-
assertTrue(logCaptor.getLogs().get(0)
124-
.contains("(" + mockCollectionXConfUri + ")"));
121+
assertTrue(errorMsgCapture.getValue().contains("Illegal QName: '" + badCreateQName + "'.. QName is invalid: INVALID_LOCAL_PART"));
122+
assertTrue(errorMsgCapture.getValue().contains("(" + mockCollectionXConfUri + ")"));
125123

126124
verify(mockConfigNodes, mockConfigNode, mockCreates, mockCreateDocument, mockCreate, mockEmptyNodeList);
127125
}

0 commit comments

Comments
 (0)