Skip to content

Commit

Permalink
[NOID] removed duplicated test and format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vga91 committed Dec 18, 2024
1 parent 1e77ce4 commit d5ee5c0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 43 deletions.
14 changes: 10 additions & 4 deletions full/src/main/java/apoc/load/Jdbc.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,25 @@ private Stream<RowResult> executeUpdate(
throw logsErrorAndThrowsException(e, query, log);
}
}

private static RuntimeException logsErrorAndThrowsException(Exception e, String query, Log log) {
String errorMessage = "Cannot execute SQL statement `%s`.%nError:%n%s";
String exceptionMsg = e.getMessage();
if(e.getMessage().contains("No suitable driver")) {
if (e.getMessage().contains("No suitable driver")) {
errorMessage = "Cannot execute SQL statement `%s`.%nError:%n%s%n%s";
exceptionMsg = obfuscateJdbcUrl(e.getMessage());
}
Exception ex = new Exception(exceptionMsg);
log.error(String.format("Cannot execute SQL statement `%s`.%nError:%n%s", query, exceptionMsg), ex);
return new RuntimeException(String.format(errorMessage, query, exceptionMsg, "Please download and copy the JDBC driver into $NEO4J_HOME/plugins, more details at https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_load_jdbc_resources"), ex);
return new RuntimeException(
String.format(
errorMessage,
query,
exceptionMsg,
"Please download and copy the JDBC driver into $NEO4J_HOME/plugins, more details at https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_load_jdbc_resources"),
ex);
}

static void closeIt(Log log, AutoCloseable... closeables) {
for (AutoCloseable c : closeables) {
try {
Expand Down
21 changes: 9 additions & 12 deletions full/src/test/java/apoc/load/JdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@
import org.neo4j.internal.helpers.collection.Iterators;
import org.neo4j.internal.helpers.collection.MapUtil;
import org.neo4j.test.TestDatabaseManagementServiceBuilder;
import org.neo4j.test.rule.DbmsRule;
import org.neo4j.test.rule.ImpermanentDbmsRule;

public class JdbcTest extends AbstractJdbcTest {

@Rule
public TemporaryFolder STORE_DIR = new TemporaryFolder();

private GraphDatabaseService db;
private DatabaseManagementService dbms;

Expand All @@ -76,7 +74,7 @@ public class JdbcTest extends AbstractJdbcTest {
public void setUp() throws Exception {
dbms = new TestDatabaseManagementServiceBuilder(STORE_DIR.getRoot().toPath()).build();
db = dbms.database(GraphDatabaseSettings.DEFAULT_DATABASE_NAME);

apocConfig().setProperty("apoc.jdbc.derby.url", "jdbc:derby:derbyDB");
apocConfig().setProperty("apoc.jdbc.test.sql", "SELECT * FROM PERSON");
apocConfig().setProperty("apoc.jdbc.testparams.sql", "SELECT * FROM PERSON WHERE NAME = ?");
Expand Down Expand Up @@ -153,16 +151,15 @@ public void testExceptionAndLogWithObfuscatedUrl() {
String errorMsgWithObfuscatedUrl = "No suitable driver found for jdbc:ajeje://*******";

// obfuscated exception
assertFails(db, "CALL apoc.load.jdbc($url,'SELECT * FROM PERSON WHERE NAME = ?',['John'])",
assertFails(
db,
"CALL apoc.load.jdbc($url,'SELECT * FROM PERSON WHERE NAME = ?',['John'])",
Map.of("url", url),
errorMsgWithObfuscatedUrl
);

// obfuscated log in `debug.log`
errorMsgWithObfuscatedUrl);

// obfuscated log in `debug.log`
String fileContent = getLogFileContent();
assertTrue("Actual log content is: " + fileContent,
fileContent.contains(errorMsgWithObfuscatedUrl)
);
assertTrue("Actual log content is: " + fileContent, fileContent.contains(errorMsgWithObfuscatedUrl));
}

@Test
Expand Down
4 changes: 0 additions & 4 deletions full/src/test/java/apoc/load/LoadLdapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import apoc.util.FileUtils;
import apoc.util.TestUtil;
import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPSearchResults;
import com.unboundid.ldap.sdk.LDAPConnection;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import org.junit.AfterClass;
Expand Down
22 changes: 0 additions & 22 deletions full/src/test/java/apoc/periodic/PeriodicExtendedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import apoc.nlp.gcp.GCPProcedures;
import apoc.nodes.NodesExtended;
import apoc.util.TestUtil;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -222,27 +221,6 @@ public void testIterateErrors() {
});
}

@Test
public void testIterateJDBC() {
TestUtil.ignoreException(
() -> {
testResult(
db,
"CALL apoc.periodic.iterate('call apoc.load.jdbc(\"jdbc:mysql://localhost:3306/northwind?user=root\",\"customers\")', 'create (c:Customer) SET c += $row', {batchSize:10,parallel:true})",
result -> {
Map<String, Object> row = Iterators.single(result);
assertEquals(3L, row.get("batches"));
assertEquals(29L, row.get("total"));
});

testCall(
db,
"MATCH (p:Customer) return count(p) as count",
row -> assertEquals(29L, row.get("count")));
},
SQLException.class);
}

@Test
public void testRock_n_roll_while() {
// setup
Expand Down
3 changes: 2 additions & 1 deletion full/src/test/java/apoc/util/ExtendedTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public static void testResultEventually(
TimeUnit.SECONDS);
}

public static void assertFails(GraphDatabaseService db, String query, Map<String,Object> params, String expectedErrMsg) {
public static void assertFails(
GraphDatabaseService db, String query, Map<String, Object> params, String expectedErrMsg) {
try {
testCall(db, query, params, r -> fail("Should fail due to " + expectedErrMsg));
} catch (Exception e) {
Expand Down

0 comments on commit d5ee5c0

Please sign in to comment.