From 9b6190a53f9bb8ca5354c390d74ab8e88be59539 Mon Sep 17 00:00:00 2001 From: vga91 Date: Thu, 12 Dec 2024 16:36:51 +0100 Subject: [PATCH] cleanup --- ...VirtualizationCatalogNewProcedureTest.java | 53 +++------- .../dv/DataVirtualizationCatalogTest.java | 47 ++------- .../dv/DataVirtualizationCatalogTestUtil.java | 98 ++----------------- 3 files changed, 28 insertions(+), 170 deletions(-) diff --git a/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogNewProcedureTest.java b/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogNewProcedureTest.java index 8ef339552a..a04b878ea0 100644 --- a/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogNewProcedureTest.java +++ b/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogNewProcedureTest.java @@ -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; @@ -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); @@ -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 @@ -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); @@ -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 params = APOC_DV_QUERY_AND_LINK_QUERY_PARAMS; Map map = (Map) params.get(CONFIG_KEY); @@ -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, @@ -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, @@ -126,7 +128,7 @@ 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, @@ -134,37 +136,12 @@ 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, diff --git a/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogTest.java b/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogTest.java index 140def8fb8..f1b3b11149 100644 --- a/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogTest.java +++ b/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogTest.java @@ -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 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, @@ -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 config = getJdbcCredentials(mysql); withDirectionIn(config); @@ -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, @@ -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, diff --git a/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogTestUtil.java b/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogTestUtil.java index 311013ca90..ef68f3c36b 100644 --- a/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogTestUtil.java +++ b/extended-it/src/test/java/apoc/dv/DataVirtualizationCatalogTestUtil.java @@ -110,14 +110,6 @@ public static Map withDirectionIn(Map config) { return config; } - - public static Map getAddQueryConfigMap(String url) { - return map("type", "CSV", - "url", url, "query", QUERY_VALUE, - "desc", DESC_VALUE, - "labels", LABELS); - } - public static Map getJdbcCredentials(JdbcDatabaseContainer mysql) { return map("user", mysql.getUsername(), "password", mysql.getPassword()); } @@ -216,13 +208,6 @@ public static void assertVirtualizeCSVQueryAndLinkContentDirectionIN(Map row) { - Node node = (Node) row.get(NODE_KEY); - assertEquals(PERSON_NAME, node.getProperty(NAME_KEY)); - assertEquals(PERSON_AGE, node.getProperty(AGE_KEY)); - assertEquals(List.of(Label.label("Person")), node.getLabels()); - } - public static String getVirtualizeJDBCUrl(JdbcDatabaseContainer mysql) { return mysql.getJdbcUrl() + JDBC_SSL_CONFIG; } @@ -235,16 +220,8 @@ public static Map getVirtualizeJDBCParameterMap(JdbcDatabaseCont DESC_KEY, JDBC_DESC, LABELS_KEY, JDBC_LABELS_AS_STRING); } - - - record CsvTestResult(String name, String personName, String personAge, String hookNodeName, Map queryParams) { } - - static void getCsvCommonResult(GraphDatabaseService db, String csvUrl) { - // TODO - getCsvCommonResult(db, APOC_DV_ADD_QUERY, APOC_DV_LIST, APOC_DV_QUERY, csvUrl, db); - } - static void getCsvCommonResult(GraphDatabaseService dbRead, String dvAdd, String dvList, String dvQuery, String csvUrl, GraphDatabaseService dbWrite) { + static void getVirtualizeCSVCommonResult(GraphDatabaseService dbRead, String dvAdd, String dvList, String csvUrl, GraphDatabaseService dbWrite) { testCallEventually(dbWrite, dvAdd, map(DATABASE_NAME, GraphDatabaseSettings.DEFAULT_DATABASE_NAME, "name", CSV_NAME_VALUE, "map", @@ -253,80 +230,37 @@ static void getCsvCommonResult(GraphDatabaseService dbRead, String dvAdd, String "query", QUERY_VALUE, "desc", DESC_VALUE, "labels", LABELS)), -// APOC_DV_INSTALL_PARAMS, (row) -> assertCatalogContent(row, csvUrl), TIMEOUT); testCallEventually(dbWrite, dvList, (row) -> assertCatalogContent(row, csvUrl), TIMEOUT); - testCallEventually(dbRead, dvQuery, + testCallEventually(dbRead, APOC_DV_QUERY, map(NAME_KEY, CSV_NAME_VALUE, APOC_DV_QUERY_PARAMS_KEY, APOC_DV_QUERY_PARAMS, RELTYPE_KEY, RELTYPE_VALUE, CONFIG_KEY, CONFIG_VALUE), -// APOC_DV_QUERY_AND_LINK_QUERY_PARAMS, (row) -> { Node node = (Node) row.get(NODE_KEY); assertEquals(PERSON_NAME, node.getProperty(NAME_KEY)); assertEquals(PERSON_AGE, node.getProperty(AGE_KEY)); assertEquals(List.of(Label.label(LABELS_VALUE)), node.getLabels()); }, TIMEOUT); - -// final String name = "csv_vr"; -// final String url = getUrlFileName("test.csv").toString(); -// final String desc = "person's details"; -// final String query = "map.name = $name and map.age = $age"; -// List labels = List.of("Person"); -// Map map = map("type", "CSV", -// "url", url, "query", query, -// "desc", desc, -// "labels", labels); -// -// String personName = "Rana"; -// String personAge = "11"; -// String hookNodeName = "node to test linking"; - -// testCall(dbWrite, dvAdd, -// APOC_DV_INSTALL_PARAMS, -//// map(DATABASE_NAME, dbRead.databaseName(), "name", CSV_NAME_VALUE, "map", MAP_VALUE), -// (row) -> assertCatalogContent(row, CSV_TEST_FILE)); -// -// testCall(dbWrite, dvList, -// (row) -> assertCatalogContent(row, CSV_TEST_FILE)); -// -// -// testCall(dbRead, dvQuery, -// APOC_DV_QUERY_AND_LINK_QUERY_PARAMS, -//// map(DATABASE_NAME, dbRead.databaseName(), "name", CSV_NAME_VALUE, "queryParams", queryParams, "config", map("header", true)), -// (row) -> { -// Node node = (Node) row.get("node"); -// assertEquals(PERSON_NAME, node.getProperty(NAME_KEY)); -// assertEquals(PERSON_AGE, node.getProperty(AGE_KEY)); -// assertEquals(List.of(Label.label(LABELS_VALUE)), node.getLabels()); -// }); - dbRead.executeTransactionally(CREATE_HOOK_QUERY, CREATE_HOOK_PARAMS); -// "create (:Hook {name: $hookNodeName})", -// map(HOOK_NODE_NAME_KEY, HOOK_NODE_NAME_VALUE) -// ); -// return new CsvTestResult(name, personName, personAge, hookNodeName, queryParams); } - record VirtualizeJdbcResult(String name, List