Skip to content

Commit

Permalink
lucene 10.0.0 fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tarzanek committed Oct 23, 2024
1 parent 08d62e7 commit aedb48a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1671,20 +1671,20 @@ public static String completeUrl(String url, HttpServletRequest req) {

/**
* Parses the specified URL and returns its query params.
* @param url URL to retrieve the query params from
* @param uri URI to retrieve the query params from
* @return query params of {@code url}
*/
public static Map<String, List<String>> getQueryParams(final URL url) {
if (url == null) {
public static Map<String, List<String>> getQueryParams(final URI uri) {
if (uri == null) {
throw new IllegalArgumentException("Cannot get query params from the null url");
}
Map<String, List<String>> returnValue = new HashMap<>();

if (url.getQuery() == null) {
if (uri.getQuery() == null) {
return returnValue;
}

Arrays.stream(url.getQuery().split("&"))
Arrays.stream(uri.getQuery().split("&"))
.filter(pair -> !pair.isEmpty())
.forEach(pair -> {
int idx = pair.indexOf('=');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOBooleanSupplier;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -109,6 +110,11 @@ public boolean seekExact(BytesRef bytesRef) throws IOException {
return false;
}

@Override
public IOBooleanSupplier prepareSeekExact(BytesRef bytesRef) throws IOException {
return null;
}

@Override
public SeekStatus seekCeil(BytesRef bytesRef) throws IOException {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import java.io.StringWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -553,31 +553,31 @@ void getQueryParamsNullTest() {
}

@Test
void getQueryParamsEmptyTest() throws MalformedURLException {
URL url = new URL("http://test.com/test");
void getQueryParamsEmptyTest() throws URISyntaxException {
URI url = new URI("http://test.com/test");
assertTrue(Util.getQueryParams(url).isEmpty());
}

@Test
void getQueryParamsEmptyTest2() throws MalformedURLException {
URL url = new URL("http://test.com/test?");
assertTrue(Util.getQueryParams(url).isEmpty());
void getQueryParamsEmptyTest2() throws URISyntaxException {
URI uri = new URI("http://test.com/test?");
assertTrue(Util.getQueryParams(uri).isEmpty());
}

@Test
void getQueryParamsSingleTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=value1");
Map<String, List<String>> params = Util.getQueryParams(url);
void getQueryParamsSingleTest() throws URISyntaxException {
URI uri = new URI("http://test.com?param1=value1");
Map<String, List<String>> params = Util.getQueryParams(uri);

assertEquals(1, params.size());

assertThat(params.get("param1"), contains("value1"));
}

@Test
void getQueryParamsMultipleTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=value1&param2=value2");
Map<String, List<String>> params = Util.getQueryParams(url);
void getQueryParamsMultipleTest() throws URISyntaxException {
URI uri = new URI("http://test.com?param1=value1&param2=value2");
Map<String, List<String>> params = Util.getQueryParams(uri);

assertEquals(2, params.size());

Expand All @@ -586,39 +586,39 @@ void getQueryParamsMultipleTest() throws MalformedURLException {
}

@Test
void getQueryParamsMultipleSameTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=value1&param1=value2");
Map<String, List<String>> params = Util.getQueryParams(url);
void getQueryParamsMultipleSameTest() throws URISyntaxException {
URI uri = new URI("http://test.com?param1=value1&param1=value2");
Map<String, List<String>> params = Util.getQueryParams(uri);

assertEquals(1, params.size());

assertThat(params.get("param1"), contains("value1", "value2"));
}

@Test
void getQueryParamsEncodedTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=%3Fvalue%3F");
Map<String, List<String>> params = Util.getQueryParams(url);
void getQueryParamsEncodedTest() throws URISyntaxException {
URI uri = new URI("http://test.com?param1=%3Fvalue%3F");
Map<String, List<String>> params = Util.getQueryParams(uri);

assertEquals(1, params.size());

assertThat(params.get("param1"), contains("?value?"));
}

@Test
void getQueryParamsEmptyValueTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=");
void getQueryParamsEmptyValueTest() throws URISyntaxException {
URI uri = new URI("http://test.com?param1=");

Map<String, List<String>> params = Util.getQueryParams(url);
Map<String, List<String>> params = Util.getQueryParams(uri);

assertThat(params.get("param1"), contains(""));
}

@Test
void getQueryParamsEmptyAndNormalValuesCombinedTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=value1&param2=&param3&param4=value4");
void getQueryParamsEmptyAndNormalValuesCombinedTest() throws URISyntaxException {
URI uri = new URI("http://test.com?param1=value1&param2=&param3&param4=value4");

Map<String, List<String>> params = Util.getQueryParams(url);
Map<String, List<String>> params = Util.getQueryParams(uri);

assertThat(params.get("param1"), contains("value1"));
assertThat(params.get("param2"), contains(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void addSearchCountsQueries(final List<String> urls) {
for (String urlStr : urls) {
try {
var uri = new URI(urlStr);
var params = Util.getQueryParams(uri.toURL());
var params = Util.getQueryParams(uri);

var projects = params.get("project");

Expand All @@ -215,7 +215,7 @@ public void addSearchCountsQueries(final List<String> urls) {
}
}
}
} catch (MalformedURLException | URISyntaxException e) {
} catch (URISyntaxException e) {
logger.log(Level.WARNING, e, () -> "Could not add search counts for " + urlStr);
}
}
Expand Down

0 comments on commit aedb48a

Please sign in to comment.