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

Exports tests #2746

Merged
merged 1 commit into from
Apr 21, 2022
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
2 changes: 1 addition & 1 deletion core/import/testCypherShellWithCompoundConstraint.cypher
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:begin
CREATE CONSTRAINT FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;
CREATE CONSTRAINT PersonRequiresNamesConstraint FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;
:commit
CALL db.awaitIndexes(300);
:begin
Expand Down
2 changes: 1 addition & 1 deletion core/import/testNeo4jShellWithCompoundConstraint.cypher
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BEGIN
CREATE CONSTRAINT FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;
CREATE CONSTRAINT PersonRequiresNamesConstraint FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;
COMMIT
SCHEMA AWAIT
BEGIN
Expand Down
2 changes: 1 addition & 1 deletion core/import/testPlainFormatWithCompoundConstraint.cypher
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE CONSTRAINT FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;
CREATE CONSTRAINT PersonRequiresNamesConstraint FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;
UNWIND [{surname:"Snow", name:"John", properties:{}}, {surname:"Jackson", name:"Matt", properties:{}}, {surname:"White", name:"Jenny", properties:{}}, {surname:"Brown", name:"Susan", properties:{}}, {surname:"Taylor", name:"Tom", properties:{}}] AS row
CREATE (n:Person{surname: row.surname, name: row.name}) SET n += row.properties;
UNWIND [{start: {name:"John", surname:"Snow"}, end: {name:"Matt", surname:"Jackson"}, properties:{}}] AS row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@
import org.neo4j.driver.Session;

import java.io.File;
import java.util.Map;
import java.util.stream.Stream;

import static apoc.export.cypher.ExportCypherTest.ExportCypherResults.*;
import static apoc.util.MapUtil.map;
import static apoc.util.TestContainerUtil.*;
import static apoc.util.TestUtil.isRunningInCI;
import static apoc.util.TestUtil.readFileToString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue;

/**
* @author as
Expand All @@ -35,23 +30,14 @@ public class ExportCypherEnterpriseFeaturesTest {

@BeforeClass
public static void beforeAll() {
assumeFalse(isRunningInCI());
TestUtil.ignoreException(() -> {
// We build the project, the artifact will be placed into ./build/libs
neo4jContainer = createEnterpriseDB(!TestUtil.isRunningInCI())
.withInitScript("init_neo4j_export_csv.cypher");
neo4jContainer.start();
}, Exception.class);
assumeNotNull(neo4jContainer);
assumeTrue("Neo4j Instance should be up-and-running", neo4jContainer.isRunning());
neo4jContainer = createEnterpriseDB(!TestUtil.isRunningInCI()).withInitScript("init_neo4j_export_csv.cypher");
neo4jContainer.start();
session = neo4jContainer.getSession();
}

@AfterClass
public static void afterAll() {
if (neo4jContainer != null && neo4jContainer.isRunning()) {
neo4jContainer.close();
}
neo4jContainer.close();
}

private static void beforeTwoLabelsWithOneCompoundConstraintEach() {
Expand Down Expand Up @@ -87,7 +73,7 @@ public void testExportWithCompoundConstraintCypherShell() {
String fileName = "testCypherShellWithCompoundConstraint.cypher";
testCall(session, "CALL apoc.export.cypher.all($file, $config)",
map("file", fileName, "config", Util.map("format", "cypher-shell")), (r) -> {
assertExportStatement(EXPECTED_CYPHER_SHELL_WITH_COMPOUND_CONSTRAINT, r, fileName);
assertExportStatement(EXPECTED_CYPHER_SHELL_WITH_COMPOUND_CONSTRAINT, fileName);
});
}

Expand All @@ -96,15 +82,15 @@ public void testExportWithCompoundConstraintPlain() {
String fileName = "testPlainFormatWithCompoundConstraint.cypher";
testCall(session, "CALL apoc.export.cypher.all($file, $config)",
map("file", fileName, "config", Util.map("format", "plain")),
(r) -> assertExportStatement(EXPECTED_PLAIN_FORMAT_WITH_COMPOUND_CONSTRAINT, r, fileName));
(r) -> assertExportStatement(EXPECTED_PLAIN_FORMAT_WITH_COMPOUND_CONSTRAINT, fileName));
}

@Test
public void testExportWithCompoundConstraintNeo4jShell() {
String fileName = "testNeo4jShellWithCompoundConstraint.cypher";
testCall(session, "CALL apoc.export.cypher.all($file, $config)",
map("file", fileName, "config", Util.map("format", "neo4j-shell")),
(r) -> assertExportStatement(EXPECTED_NEO4J_SHELL_WITH_COMPOUND_CONSTRAINT, r, fileName));
(r) -> assertExportStatement(EXPECTED_NEO4J_SHELL_WITH_COMPOUND_CONSTRAINT, fileName));
}

@Test
Expand Down Expand Up @@ -141,7 +127,7 @@ public void shouldHandleTwoLabelsWithOneCompoundConstraintEach() {
}
}

private void assertExportStatement(String expectedStatement, Map<String, Object> result, String fileName) {
assertEquals(expectedStatement, isRunningInCI() ? result.get("cypherStatements") : readFileToString(new File(directory, fileName)));
private void assertExportStatement(String expectedStatement, String fileName) {
assertEquals(expectedStatement, readFileToString(new File(directory, fileName)));
}
}
26 changes: 3 additions & 23 deletions core/src/test/java/apoc/export/cypher/ExportCypherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1250,28 +1250,8 @@ static class ExportCypherResults {
static final String EXPECTED_ONLY_SCHEMA_CYPHER_SHELL = EXPECTED_ONLY_SCHEMA_NEO4J_SHELL.replace(NEO4J_SHELL.begin(), CYPHER_SHELL.begin())
.replace(NEO4J_SHELL.commit(), CYPHER_SHELL.commit()).replace(NEO4J_SHELL.schemaAwait(), CYPHER_SHELL.schemaAwait()) + EXPECTED_INDEXES_AWAIT;


static final String EXPECTED_NODES_COMPOUND_CONSTRAINT = String.format("BEGIN%n" +
"CREATE (:`Person` {`name`:\"John\", `surname`:\"Snow\"});%n" +
"CREATE (:`Person` {`name`:\"Matt\", `surname`:\"Jackson\"});%n" +
"CREATE (:`Person` {`name`:\"Jenny\", `surname`:\"White\"});%n" +
"CREATE (:`Person` {`name`:\"Susan\", `surname`:\"Brown\"});%n" +
"CREATE (:`Person` {`name`:\"Tom\", `surname`:\"Taylor\"});%n" +
"COMMIT%n");

static final String EXPECTED_SCHEMA_COMPOUND_CONSTRAINT = String.format("BEGIN%n" +
"CREATE CONSTRAINT uniqueConstraint FOR (node:`Person`) REQUIRE (node.`name`, node.`surname`) IS NODE KEY;%n" +
"COMMIT%n" +
"SCHEMA AWAIT%n");

static final String EXPECTED_RELATIONSHIP_COMPOUND_CONSTRAINT = String.format(("BEGIN%n" +
"MATCH (n1:`Person`{`surname`:\"Snow\", `name`:\"John\"}), (n2:`Person`{`surname`:\"Jackson\", `name`:\"Matt\"}) CREATE (n1)-[r:`KNOWS`]->(n2);%n" +
"COMMIT%n"));

static final String EXPECTED_INDEX_AWAIT_COMPOUND_CONSTRAINT = String.format("CALL db.awaitIndex(':`Person`(`name`,`surname`)');%n");

static final String EXPECTED_NEO4J_SHELL_WITH_COMPOUND_CONSTRAINT = String.format("BEGIN%n" +
"CREATE CONSTRAINT uniqueConstraint FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;%n" +
"CREATE CONSTRAINT PersonRequiresNamesConstraint FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;%n" +
"COMMIT%n" +
"SCHEMA AWAIT%n" +
"BEGIN%n" +
Expand All @@ -1286,7 +1266,7 @@ static class ExportCypherResults {
"COMMIT%n");

static final String EXPECTED_CYPHER_SHELL_WITH_COMPOUND_CONSTRAINT = String.format(":begin%n" +
"CREATE CONSTRAINT uniqueConstraint FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;%n" +
"CREATE CONSTRAINT PersonRequiresNamesConstraint FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;%n" +
":commit%n" +
"CALL db.awaitIndexes(300);%n" +
":begin%n" +
Expand All @@ -1300,7 +1280,7 @@ static class ExportCypherResults {
"CREATE (start)-[r:KNOWS]->(end) SET r += row.properties;%n" +
":commit%n");

static final String EXPECTED_PLAIN_FORMAT_WITH_COMPOUND_CONSTRAINT = String.format("CREATE CONSTRAINT uniqueConstraint FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;%n" +
static final String EXPECTED_PLAIN_FORMAT_WITH_COMPOUND_CONSTRAINT = String.format("CREATE CONSTRAINT PersonRequiresNamesConstraint FOR (node:Person) REQUIRE (node.name, node.surname) IS NODE KEY;%n" +
"UNWIND [{surname:\"Snow\", name:\"John\", properties:{}}, {surname:\"Jackson\", name:\"Matt\", properties:{}}, {surname:\"White\", name:\"Jenny\", properties:{}}, {surname:\"Brown\", name:\"Susan\", properties:{}}, {surname:\"Taylor\", name:\"Tom\", properties:{}}] AS row%n" +
"CREATE (n:Person{surname: row.surname, name: row.name}) SET n += row.properties;%n" +
"UNWIND [{start: {name:\"John\", surname:\"Snow\"}, end: {name:\"Matt\", surname:\"Jackson\"}, properties:{}}] AS row%n" +
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/init_neo4j_export_csv.cypher
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE CONSTRAINT FOR (t:Person) REQUIRE (t.name, t.surname) IS NODE KEY;
CREATE CONSTRAINT PersonRequiresNamesConstraint FOR (t:Person) REQUIRE (t.name, t.surname) IS NODE KEY;

CREATE (a:Person {name: 'John', surname: 'Snow'})
CREATE (b:Person {name: 'Matt', surname: 'Jackson'})
Expand Down