Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vga91 committed Dec 15, 2024
1 parent bd9c66b commit 155c8f0
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static apoc.util.ExtendedTestContainerUtil.dbIsWriter;
import static apoc.util.ExtendedTestContainerUtil.getBoltAddress;
import static apoc.util.ExtendedTestContainerUtil.getDriverIfNotReplica;
import static apoc.util.MapUtil.map;
import static apoc.util.SystemDbUtil.PROCEDURE_NOT_ROUTED_ERROR;
import static apoc.util.TestContainerUtil.importFolder;
import static apoc.util.TestContainerUtil.testCall;
Expand Down Expand Up @@ -76,8 +77,8 @@ public void testVirtualizeCSV() {
);

Node node = result.single().get(NODE_KEY).asNode();
assertEquals(PERSON_NAME, node.get(NAME_KEY).asString());
assertEquals(PERSON_AGE, node.get(AGE_KEY).asString());
assertEquals(NAME_VALUE, node.get(NAME_KEY).asString());
assertEquals(AGE_VALUE, node.get(AGE_KEY).asString());
assertEquals(List.of(LABELS_VALUE), node.labels());

return result.consume();
Expand All @@ -87,12 +88,14 @@ public void testVirtualizeCSV() {
clusterSession.executeWrite(tx -> tx.run(CREATE_HOOK_QUERY, CREATE_HOOK_PARAMS).consume());

clusterSession.executeRead(tx -> {
final Result result = tx.run(APOC_DV_QUERY_AND_LINK_QUERY, APOC_DV_QUERY_AND_LINK_QUERY_PARAMS);
final Result result = tx.run(APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, CSV_NAME_VALUE, APOC_DV_QUERY_PARAMS_KEY, APOC_DV_QUERY_PARAMS, RELTYPE_KEY, RELTYPE_VALUE, CONFIG_KEY, CONFIG_VALUE)
);

Path path = result.single().get("path").asPath();
Node node = path.end();
assertEquals(PERSON_NAME, node.get(NAME_KEY).asString());
assertEquals(PERSON_AGE, node.get(AGE_KEY).asString());
assertEquals(NAME_VALUE, node.get(NAME_KEY).asString());
assertEquals(AGE_VALUE, node.get(AGE_KEY).asString());
assertEquals(List.of(LABELS_VALUE), node.labels());

Node hook = path.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Result;
import org.neo4j.test.TestDatabaseManagementServiceBuilder;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MySQLContainer;

import java.io.File;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static apoc.ApocConfig.APOC_IMPORT_FILE_ENABLED;
import static apoc.ApocConfig.apocConfig;
import static apoc.custom.CypherProcedureTestUtil.startDbWithCustomApocConfigs;
import static apoc.dv.DataVirtualizationCatalog.DIRECTION_CONF_KEY;
import static apoc.dv.DataVirtualizationCatalogTestUtil.*;

Expand All @@ -52,10 +53,13 @@ public class DataVirtualizationCatalogNewProcedureTest {

@Before
public void setUp() throws Exception {
databaseManagementService = startDbWithCustomApocConfigs(storeDir);
databaseManagementService = new TestDatabaseManagementServiceBuilder(storeDir.getRoot().toPath())
.build();
db = databaseManagementService.database(GraphDatabaseSettings.DEFAULT_DATABASE_NAME);
sysDb = databaseManagementService.database(GraphDatabaseSettings.SYSTEM_DATABASE_NAME);

FileUtils.copyFile(new File(new URI(FILE_URL).toURL().getPath()), new File(storeDir.getRoot(), CSV_TEST_FILE));

TestUtil.registerProcedure(sysDb, DataVirtualizationCatalogNewProcedures.class);
TestUtil.registerProcedure(db, DataVirtualizationCatalog.class, Jdbc.class, LoadCsv.class, Create.class);
apocConfig().setProperty(APOC_IMPORT_FILE_ENABLED, true);
Expand All @@ -65,8 +69,6 @@ public void setUp() throws Exception {
public static void setUpContainer() {
mysql = new MySQLContainer().withInitScript("init_mysql.sql");
mysql.start();

// url = getVirtualizeJDBCUrl(mysql);
}

@AfterClass
Expand All @@ -76,103 +78,78 @@ public static void tearDownContainer() {

@Test
public void testVirtualizeCSV() {
getCsvCommonResult(db,
APOC_DV_INSTALL_QUERY, APOC_DV_SHOW_QUERY, APOC_DV_QUERY, CSV_TEST_FILE, sysDb);
getVirtualizeCSVCommonResult(db,
APOC_DV_INSTALL_QUERY, APOC_DV_SHOW_QUERY, CSV_TEST_FILE, sysDb);

testCall(db, APOC_DV_QUERY_AND_LINK_QUERY, APOC_DV_QUERY_AND_LINK_QUERY_PARAMS,
testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, CSV_NAME_VALUE, APOC_DV_QUERY_PARAMS_KEY, APOC_DV_QUERY_PARAMS, RELTYPE_KEY, RELTYPE_VALUE, CONFIG_KEY, CONFIG_VALUE),
DataVirtualizationCatalogTestUtil::assertVirtualizeCSVQueryAndLinkContent);

}

@Test
public void testVirtualizeCSVWithCustomDirectionIN() {
getCsvCommonResult(db,
APOC_DV_INSTALL_QUERY, APOC_DV_SHOW_QUERY, APOC_DV_QUERY, CSV_TEST_FILE, sysDb);
getVirtualizeCSVCommonResult(db,
APOC_DV_INSTALL_QUERY, APOC_DV_SHOW_QUERY, CSV_TEST_FILE, sysDb);

Map<String, Object> params = APOC_DV_QUERY_AND_LINK_QUERY_PARAMS;
Map map = (Map) params.get(CONFIG_KEY);
map.put("direction", "IN");
testCall(db, APOC_DV_QUERY_AND_LINK_QUERY, params,
Map<String, Object> config = new HashMap<>(CONFIG_VALUE);
config.put(DIRECTION_CONF_KEY, DataVirtualizationCatalog.Direction.IN.name());
testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, CSV_NAME_VALUE, APOC_DV_QUERY_PARAMS_KEY, APOC_DV_QUERY_PARAMS, RELTYPE_KEY, RELTYPE_VALUE, CONFIG_KEY, config),
DataVirtualizationCatalogTestUtil::assertVirtualizeCSVQueryAndLinkContentDirectionIN);
}

@Test
public void testVirtualizeJDBC() {

getVirtualizeJdbcCommonResult(db, mysql,
APOC_DV_INSTALL_QUERY, APOC_DV_QUERY_WITH_PARAM, APOC_DV_QUERY, sysDb);
getVirtualizeJDBCCommonResult(db, mysql,
APOC_DV_INSTALL_QUERY, sysDb);

testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_APOC_PARAMS, RELTYPE_KEY, VIRTUALIZE_JDBC_WITH_PARAMS_RELTYPE,
CONFIG_KEY, map(CREDENTIALS_KEY, getJdbcCredentials(mysql))),
DataVirtualizationCatalogTestUtil::assertDvQueryAndLinkContent);
DataVirtualizationCatalogTestUtil::assertVirtualizeJDBCQueryAndLinkContent);
}

@Test
public void testVirtualizeJDBCWithCustomDirectionIN() {

getVirtualizeJdbcCommonResult(db, mysql,
APOC_DV_INSTALL_QUERY, APOC_DV_QUERY_WITH_PARAM, APOC_DV_QUERY, sysDb);
getVirtualizeJDBCCommonResult(db, mysql,
APOC_DV_INSTALL_QUERY, sysDb);

testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_APOC_PARAMS, RELTYPE_KEY, VIRTUALIZE_JDBC_WITH_PARAMS_RELTYPE,
CONFIG_KEY, map(
DIRECTION_CONF_KEY, DataVirtualizationCatalog.Direction.IN.name(),
CREDENTIALS_KEY, getJdbcCredentials(mysql)
)),
DataVirtualizationCatalogTestUtil::assertDvQueryAndLinkContentDirectionIN);
DataVirtualizationCatalogTestUtil::assertVirtualizeJDBCQueryAndLinkContentDirectionIN);
}

@Test
public void testVirtualizeJDBCWithParameterMap() {

getVirtualizeJdbcWithParamsCommonResult(db, mysql, APOC_DV_INSTALL_QUERY, sysDb);
getVirtualizeJDBCWithParamsCommonResult(db, mysql, APOC_DV_INSTALL_QUERY, sysDb);

testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_QUERY_PARAMS, RELTYPE_KEY, VIRTUALIZE_JDBC_WITH_PARAMS_RELTYPE,
CONFIG_KEY, map(
CREDENTIALS_KEY, getJdbcCredentials(mysql)
)),
DataVirtualizationCatalogTestUtil::assertDvQueryAndLinkContent);
//
// testCall(sysDb, APOC_DV_INSTALL_QUERY,
// map(DATABASE_NAME, GraphDatabaseSettings.DEFAULT_DATABASE_NAME,NAME_KEY, JDBC_NAME,
// "map", getVirtualizeJDBCParameterMap(mysql, VIRTUALIZE_JDBC_WITH_PARAMS_QUERY)),
// (row) -> assertDvCatalogAddOrInstall(row, url));
//
// testCallEmpty(db, APOC_DV_JDBC_WITH_PARAMS_QUERY,
// map(NAME_KEY, JDBC_NAME, CONFIG_KEY, getJdbcCredentials(mysql)));
//
//
// testCall(db, APOC_DV_QUERY,
// map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_QUERY_PARAMS,
// CONFIG_KEY, getJdbcCredentials(mysql)),
// (row) -> {
// Node node = (Node) row.get(NODE_KEY);
// assertEquals(VIRTUALIZE_JDBC_COUNTRY, node.getProperty("Name"));
// assertEquals(JDBC_LABELS, node.getLabels());
// });
//
// db.executeTransactionally(CREATE_HOOK_QUERY, map(HOOK_NODE_NAME_KEY, HOOK_NODE_NAME_VALUE));
//
// testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
// map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_QUERY_PARAMS, RELTYPE_KEY, VIRTUALIZE_JDBC_WITH_PARAMS_RELTYPE,
// CONFIG_KEY, getJdbcCredentials(mysql)),
// DataVirtualizationCatalogTestUtil::assertDvQueryAndLinkContent);
DataVirtualizationCatalogTestUtil::assertVirtualizeJDBCQueryAndLinkContent);
}

@Test
public void testVirtualizeJDBCWithParameterMapAndDirectionIN() {

getVirtualizeJdbcWithParamsCommonResult(db, mysql, APOC_DV_INSTALL_QUERY, sysDb);
getVirtualizeJDBCWithParamsCommonResult(db, mysql, APOC_DV_INSTALL_QUERY, sysDb);

testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_QUERY_PARAMS, RELTYPE_KEY, VIRTUALIZE_JDBC_WITH_PARAMS_RELTYPE,
CONFIG_KEY, map(
DIRECTION_CONF_KEY, DataVirtualizationCatalog.Direction.IN.name(),
CREDENTIALS_KEY, getJdbcCredentials(mysql)
)),
DataVirtualizationCatalogTestUtil::assertDvQueryAndLinkContentDirectionIN);
DataVirtualizationCatalogTestUtil::assertVirtualizeJDBCQueryAndLinkContentDirectionIN);
}

@Test
Expand Down Expand Up @@ -227,7 +204,7 @@ public void testVirtualizeJDBCWithDifferentParameterMap() {
try {
db.executeTransactionally(APOC_DV_QUERY,
map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_QUERY_WRONG_PARAMS,
CONFIG_KEY, map("credentials", getJdbcCredentials(mysql))),
CONFIG_KEY, map(CREDENTIALS_KEY, getJdbcCredentials(mysql))),
Result::resultAsString);
Assert.fail("Exception is expected");
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MySQLContainer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -60,108 +61,73 @@ public static void tearDownContainer() {
@Test
public void testVirtualizeCSV() {
final String url = getUrlFileName("test.csv").toString();
getCsvCommonResult(db, url);
getVirtualizeCSVCommonResult(db, APOC_DV_ADD_QUERY, APOC_DV_LIST, url, db);

final String relType = "LINKED_TO";
testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
APOC_DV_QUERY_AND_LINK_QUERY_PARAMS,
// map("name", result.name(), "queryParams", result.queryParams(), "relType", relType, "config", map("header", true)),
map(NAME_KEY, CSV_NAME_VALUE, APOC_DV_QUERY_PARAMS_KEY, APOC_DV_QUERY_PARAMS, RELTYPE_KEY, RELTYPE_VALUE, CONFIG_KEY, CONFIG_VALUE),
DataVirtualizationCatalogTestUtil::assertVirtualizeCSVQueryAndLinkContent);
// (row) -> {
// Path path = (Path) row.get("path");
// Node node = path.endNode();
// assertEquals(result.personName(), node.getProperty("name"));
// assertEquals(result.personAge(), node.getProperty("age"));
// assertEquals(List.of(Label.label("Person")), node.getLabels());
//
// Node hook = path.startNode();
// assertEquals(result.hookNodeName(), hook.getProperty("name"));
// assertEquals(List.of(Label.label("Hook")), hook.getLabels());
//
// Relationship relationship = path.lastRelationship();
// assertEquals(hook, relationship.getStartNode());
// assertEquals(node, relationship.getEndNode());
// assertEquals(relType, relationship.getType().name());
// });

}

@Test
public void testVirtualizeCSVWithCustomDirectionIN() {
final String url = getUrlFileName("test.csv").toString();
getCsvCommonResult(db, url);
getVirtualizeCSVCommonResult(db, APOC_DV_ADD_QUERY, APOC_DV_LIST, url, db);

Map<String, Object> config = withDirectionIn(CONFIG_VALUE);
Map<String, Object> config = new HashMap<>(CONFIG_VALUE);
config.put(DIRECTION_CONF_KEY, DataVirtualizationCatalog.Direction.IN.name());

testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, CSV_NAME_VALUE, APOC_DV_QUERY_PARAMS_KEY, APOC_DV_QUERY_PARAMS, RELTYPE_KEY, RELTYPE_VALUE, CONFIG_KEY, config),
DataVirtualizationCatalogTestUtil::assertVirtualizeCSVQueryAndLinkContentDirectionIN);
// (row) -> {
// Path path = (Path) row.get("path");
// Node hook = path.endNode();
// assertEquals(result.hookNodeName(), hook.getProperty("name"));
// assertEquals(List.of(Label.label("Hook")), hook.getLabels());
// Node node = path.startNode();
//
// assertEquals(result.personName(), node.getProperty("name"));
// assertEquals(result.personAge(), node.getProperty("age"));
// assertEquals(List.of(Label.label("Person")), node.getLabels());
//
// Relationship relationship = path.lastRelationship();
// assertEquals(node, relationship.getStartNode());
// assertEquals(hook, relationship.getEndNode());
// assertEquals(relType, relationship.getType().name());
// });

}

@Test
public void testVirtualizeJDBC() {
getVirtualizeJdbcCommonResult(db, mysql, APOC_DV_ADD_QUERY, APOC_DV_QUERY_WITH_PARAM, APOC_DV_QUERY, db);
getVirtualizeJDBCCommonResult(db, mysql, APOC_DV_ADD_QUERY, db);

testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_APOC_PARAMS, RELTYPE_KEY, VIRTUALIZE_JDBC_WITH_PARAMS_RELTYPE,
CONFIG_KEY, map(CREDENTIALS_KEY, getJdbcCredentials(mysql))),
DataVirtualizationCatalogTestUtil::assertDvQueryAndLinkContent);
DataVirtualizationCatalogTestUtil::assertVirtualizeJDBCQueryAndLinkContent);
}

@Test
public void testVirtualizeJDBCWithCustomDirectionIN() {
getVirtualizeJdbcCommonResult(db, mysql, APOC_DV_ADD_QUERY, APOC_DV_QUERY_WITH_PARAM, APOC_DV_QUERY, db);

Map<String, Object> config = getJdbcCredentials(mysql);
withDirectionIn(config);
getVirtualizeJDBCCommonResult(db, mysql, APOC_DV_ADD_QUERY, db);


testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_APOC_PARAMS, RELTYPE_KEY, VIRTUALIZE_JDBC_WITH_PARAMS_RELTYPE,
CONFIG_KEY, map(
DIRECTION_CONF_KEY, DataVirtualizationCatalog.Direction.IN.name(),
CREDENTIALS_KEY, getJdbcCredentials(mysql)
)),
DataVirtualizationCatalogTestUtil::assertDvQueryAndLinkContentDirectionIN);
DataVirtualizationCatalogTestUtil::assertVirtualizeJDBCQueryAndLinkContentDirectionIN);
}

@Test
public void testVirtualizeJDBCWithParameterMap() {
getVirtualizeJdbcWithParamsCommonResult(db, mysql, APOC_DV_ADD_QUERY, db);
getVirtualizeJDBCWithParamsCommonResult(db, mysql, APOC_DV_ADD_QUERY, db);

testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_QUERY_PARAMS, RELTYPE_KEY, VIRTUALIZE_JDBC_WITH_PARAMS_RELTYPE,
CONFIG_KEY, map(CREDENTIALS_KEY, getJdbcCredentials(mysql))
),
DataVirtualizationCatalogTestUtil::assertDvQueryAndLinkContent);
DataVirtualizationCatalogTestUtil::assertVirtualizeJDBCQueryAndLinkContent);
}

@Test
public void testVirtualizeJDBCWithParameterMapAndDirectionIN() {
getVirtualizeJdbcWithParamsCommonResult(db, mysql, APOC_DV_ADD_QUERY, db);
getVirtualizeJDBCWithParamsCommonResult(db, mysql, APOC_DV_ADD_QUERY, db);

testCall(db, APOC_DV_QUERY_AND_LINK_QUERY,
map(NAME_KEY, JDBC_NAME, APOC_DV_QUERY_PARAMS_KEY, VIRTUALIZE_JDBC_QUERY_PARAMS, RELTYPE_KEY, VIRTUALIZE_JDBC_WITH_PARAMS_RELTYPE,
CONFIG_KEY, map(
DIRECTION_CONF_KEY, DataVirtualizationCatalog.Direction.IN.name(),
CREDENTIALS_KEY, getJdbcCredentials(mysql)
)),
DataVirtualizationCatalogTestUtil::assertDvQueryAndLinkContentDirectionIN);
DataVirtualizationCatalogTestUtil::assertVirtualizeJDBCQueryAndLinkContentDirectionIN);
}

@Test
Expand Down
Loading

0 comments on commit 155c8f0

Please sign in to comment.