Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vga91 committed Dec 12, 2024
1 parent bd9c66b commit 9b6190a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;

Expand Down Expand Up @@ -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,8 +78,8 @@ 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,
DataVirtualizationCatalogTestUtil::assertVirtualizeCSVQueryAndLinkContent);
Expand All @@ -86,8 +88,8 @@ public void testVirtualizeCSV() {

@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);
Expand All @@ -99,8 +101,8 @@ public void testVirtualizeCSVWithCustomDirectionIN() {
@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,
Expand All @@ -111,8 +113,8 @@ CONFIG_KEY, map(CREDENTIALS_KEY, getJdbcCredentials(mysql))),
@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,
Expand All @@ -126,45 +128,20 @@ CREDENTIALS_KEY, getJdbcCredentials(mysql)
@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);
}

@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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,63 +60,28 @@ 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)),
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);
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,
Expand All @@ -126,7 +91,7 @@ CONFIG_KEY, map(CREDENTIALS_KEY, getJdbcCredentials(mysql))),

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

Map<String, Object> config = getJdbcCredentials(mysql);
withDirectionIn(config);
Expand All @@ -142,7 +107,7 @@ CREDENTIALS_KEY, getJdbcCredentials(mysql)

@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,
Expand All @@ -153,7 +118,7 @@ CONFIG_KEY, map(CREDENTIALS_KEY, getJdbcCredentials(mysql))

@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,
Expand Down
Loading

0 comments on commit 9b6190a

Please sign in to comment.