-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#124 PageQueryIterable doesn't escape special characters
- switches to named parameters in `PageQueryIterable` instead of param concatenation - adds new test class `PageQueryIterableTest` to demonstrate the handling of `'` characters with "Moore's law" as example - adjusts existing test cases to reflect the added data element in the TestDB script
- Loading branch information
Showing
6 changed files
with
157 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
dkpro-jwpl-api/src/test/java/org/dkpro/jwpl/api/PageQueryIterableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.dkpro.jwpl.api; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.dkpro.jwpl.api.exception.WikiApiException; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
public class PageQueryIterableTest | ||
extends BaseJWPLTest | ||
{ | ||
|
||
private PageQuery pq; | ||
|
||
@BeforeAll | ||
public static void setupWikipedia() | ||
{ | ||
DatabaseConfiguration db = obtainHSDLDBConfiguration(); | ||
try { | ||
wiki = new Wikipedia(db); | ||
} | ||
catch (Exception e) { | ||
fail("Wikipedia could not be initialized: " + e.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
@BeforeEach | ||
public void setup() { | ||
pq = new PageQuery(); | ||
} | ||
|
||
// Shows now exception occurs during creation | ||
@Test | ||
public void testCreatePageQueryIterable() throws WikiApiException | ||
{ | ||
PageQueryIterable pqi = new PageQueryIterable(wiki, pq); | ||
assertNotNull(pqi); | ||
} | ||
|
||
// Example with ' character in titlePattern verifies issue #124 | ||
@ParameterizedTest | ||
@ValueSource(strings = {"Wikipedia%", "Wiki_edia%", "Moore'%"}) | ||
public void testIteratorWithValidTitlePattern(String input) throws WikiApiException | ||
{ | ||
pq.setTitlePattern(input); | ||
pq.setOnlyArticlePages(true); | ||
PageQueryIterable pqi = new PageQueryIterable(wiki, pq); | ||
assertNotNull(pqi); | ||
Iterator<Page> it = pqi.iterator(); | ||
assertNotNull(it); | ||
int count = 0; | ||
while (it.hasNext()) { | ||
count++; | ||
assertNotNull(it.next()); | ||
} | ||
assertTrue(count >= 1); | ||
} | ||
|
||
// Example with null or blank titlePattern => should fetch all ID's in DB | ||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@ValueSource(strings = {" ", "\t", "\n"}) | ||
public void testIteratorWithEmptyTitlePattern(String input) throws WikiApiException | ||
{ | ||
pq.setTitlePattern(input); | ||
PageQueryIterable pqi = new PageQueryIterable(wiki, pq); | ||
assertNotNull(pqi); | ||
Iterator<Page> it = pqi.iterator(); | ||
assertNotNull(it); | ||
int count = 0; | ||
while (it.hasNext()) { | ||
count++; | ||
assertNotNull(it.next()); | ||
} | ||
assertEquals(34, count); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"Wikipedia%", "Wiki_edia%", "Moore'%"}) | ||
public void testIteratorWithMaTokens(String input) throws WikiApiException | ||
{ | ||
pq.setTitlePattern(input); | ||
pq.setMaxTokens(20); | ||
PageQueryIterable pqi = new PageQueryIterable(wiki, pq); | ||
assertNotNull(pqi); | ||
Iterator<Page> it = pqi.iterator(); | ||
assertNotNull(it); | ||
int count = 0; | ||
while (it.hasNext()) { | ||
count++; | ||
assertNotNull(it.next()); | ||
} | ||
assertTrue(count >= 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#HSQL Database Engine 2.4.0 | ||
#Tue Aug 21 12:43:37 CEST 2018 | ||
version=2.4.0 | ||
#HSQL Database Engine 2.7.2 | ||
#Mon Nov 06 15:01:36 CET 2023 | ||
tx_timestamp=119 | ||
modified=no | ||
tx_timestamp=0 | ||
version=2.7.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters