Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to solve TC 5.22 errors #4163

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions extended-it/src/test/java/apoc/s3/LoadS3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import org.junit.jupiter.api.AfterAll;

import org.neo4j.driver.internal.util.Iterables;
import org.neo4j.graphdb.Result;
import org.neo4j.test.rule.DbmsRule;
import org.neo4j.test.rule.ImpermanentDbmsRule;

import java.util.Map;

import static apoc.ApocConfig.APOC_IMPORT_FILE_ENABLED;
import static apoc.ApocConfig.APOC_IMPORT_FILE_USE_NEO4J_CONFIG;
import static apoc.ApocConfig.apocConfig;
import static apoc.load.LoadCsvTest.assertRow;
import static apoc.util.ExtendedITUtil.EXTENDED_PATH;
import static apoc.util.MapUtil.map;
import static apoc.util.TestUtil.testCall;
Expand Down Expand Up @@ -82,6 +84,12 @@ public void testLoadCsvS3() {
private String removeRegionFromUrl(String url) {
return url.replace(s3Container.getEndpointConfiguration().getSigningRegion() + ".", "");
}


public static void assertRow(Result r, String name, String age, long lineNo) {
Map<String, Object> row = r.next();
assertEquals(map("name", name,"age", age), row.get("map"));
assertEquals(asList(name, age), row.get("list"));
assertEquals(lineNo, row.get("lineNo"));
}

}
18 changes: 11 additions & 7 deletions extended/src/test/java/apoc/load/LoadCsvTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.mockserver.client.MockServerClient;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.Header;
import org.mockserver.socket.PortFactory;
import org.neo4j.configuration.GraphDatabaseSettings;
import org.neo4j.graphdb.QueryExecutionException;
import org.neo4j.graphdb.Result;
Expand Down Expand Up @@ -45,6 +46,7 @@

public class LoadCsvTest {

private static final int PORT = PortFactory.findFreePort();
private static ClientAndServer mockServer;

private static final List<Map<String, Object>> RESPONSE_BODY = List.of(
Expand All @@ -55,7 +57,7 @@ public class LoadCsvTest {

@BeforeClass
public static void startServer() {
mockServer = startClientAndServer(1080);
mockServer = startClientAndServer(PORT);
}

@AfterClass
Expand Down Expand Up @@ -492,7 +494,7 @@ public void testLoadCsvWithUserPassInUrl() throws JsonProcessingException {
String userPass = "user:password";
String token = Util.encodeUserColonPassToBase64(userPass);

new MockServerClient("localhost", 1080)
new MockServerClient("localhost", PORT)
.when(
request()
.withPath("/docs/csv")
Expand All @@ -508,8 +510,9 @@ public void testLoadCsvWithUserPassInUrl() throws JsonProcessingException {
.withDelay(TimeUnit.SECONDS, 1)
);

String url = "http://%s@localhost:%s/docs/csv".formatted(userPass, PORT);
testResult(db, "CALL apoc.load.csv($url, {results:['map']}) YIELD map",
map("url", "http://" + userPass + "@localhost:1080/docs/csv"),
map("url", url),
(row) -> assertEquals(RESPONSE_BODY, row.stream().map(i->i.get("map")).collect(Collectors.toList()))
);
}
Expand All @@ -519,7 +522,7 @@ public void testLoadCsvParamsWithUserPassInUrl() throws JsonProcessingException
String userPass = "user:password";
String token = Util.encodeUserColonPassToBase64(userPass);

new MockServerClient("localhost", 1080)
new MockServerClient("localhost", PORT)
.when(
request()
.withMethod("POST")
Expand All @@ -536,8 +539,9 @@ public void testLoadCsvParamsWithUserPassInUrl() throws JsonProcessingException
.withDelay(TimeUnit.SECONDS, 1)
);

String url = "http://%s@localhost:%s/docs/csv".formatted(userPass, PORT);
testResult(db, "CALL apoc.load.csvParams($url, $header, $payload, {results:['map','list','stringMap','strings']})",
map("url", "http://" + userPass + "@localhost:1080/docs/csv",
map("url", url,
"header", map("method", "POST"),
"payload", "{\"query\":\"pagecache\",\"version\":\"3.5\"}"),
(row) -> assertEquals(RESPONSE_BODY, row.stream().map(i->i.get("map")).collect(Collectors.toList()))
Expand All @@ -549,7 +553,7 @@ public void testLoadCsvParamsWithBasicAuth() throws JsonProcessingException {
String userPass = "user:password";
String token = Util.encodeUserColonPassToBase64(userPass);

new MockServerClient("localhost", 1080)
new MockServerClient("localhost", PORT)
.when(
request()
.withMethod("POST")
Expand All @@ -568,7 +572,7 @@ public void testLoadCsvParamsWithBasicAuth() throws JsonProcessingException {
);

testResult(db, "CALL apoc.load.csvParams($url, $header, $payload, {results:['map','list','stringMap','strings']})",
map("url", "http://localhost:1080/docs/csv",
map("url", "http://localhost:%s/docs/csv".formatted(PORT),
"header", map("method",
"POST", "Authorization", "Basic " + token,
"Content-Type", "application/json"),
Expand Down
7 changes: 5 additions & 2 deletions extended/src/test/java/apoc/ml/WatsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.Test;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.Header;
import org.mockserver.socket.PortFactory;
import org.neo4j.test.rule.DbmsRule;
import org.neo4j.test.rule.ImpermanentDbmsRule;

Expand All @@ -33,6 +34,7 @@

public class WatsonTest {

private static final int PORT = PortFactory.findFreePort();
private static ClientAndServer mockServer;

@ClassRule
Expand All @@ -45,14 +47,15 @@ public static void startServer() throws Exception {
TestUtil.registerProcedure(db, Watson.class);

String path = "/generation/text";
apocConfig().setProperty(APOC_ML_WATSON_URL, "http://localhost:1080" + path);
apocConfig().setProperty(APOC_ML_WATSON_URL, "http://localhost:" + PORT + path);
apocConfig().setProperty(APOC_IMPORT_FILE_ENABLED, true);
apocConfig().setProperty(APOC_ML_WATSON_PROJECT_ID, "fakeProjectId");

File urlFileName = new File(getUrlFileName("watson.json").getFile());
String body = FileUtils.readFileToString(urlFileName, UTF_8);

mockServer = startClientAndServer(1080);

mockServer = startClientAndServer(PORT);
mockServer.when(
request()
.withMethod("POST")
Expand Down
Loading