Skip to content

Commit

Permalink
[ZEPPELIN-5949] Update testcontainers and migrate neo4j to Junit5 (#4643
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Reamer authored Sep 11, 2023
1 parent c4b2499 commit 0a48d99
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
7 changes: 7 additions & 0 deletions neo4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>neo4j</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.zeppelin.graph.neo4j;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
import org.apache.zeppelin.graph.neo4j.Neo4jConnectionManager.Neo4jAuthType;
Expand All @@ -25,37 +26,38 @@
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.interpreter.graph.GraphResult;
import org.apache.zeppelin.tabledata.Node;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.MethodOrderer;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Session;
import org.testcontainers.containers.Neo4jContainer;
import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException;
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Testcontainers
@TestMethodOrder(MethodOrderer.MethodName.class)
public class Neo4jCypherInterpreterTest {

private Neo4jCypherInterpreter interpreter;

private InterpreterContext context;

@ClassRule
@Container
public static Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.1.1")
.withoutAuthentication();

Expand All @@ -75,7 +77,7 @@ public class Neo4jCypherInterpreterTest {
private static final String TABLE_RESULT_PREFIX = "%table ";
private static final String NETWORK_RESULT_PREFIX = "%network ";

@BeforeClass
@BeforeAll
public static void setUpNeo4jServer() {
try (Driver driver = GraphDatabase.driver(neo4jContainer.getBoltUrl());
Session session = driver.session()) {
Expand All @@ -84,7 +86,7 @@ public static void setUpNeo4jServer() {
}
}

@Before
@BeforeEach
public void setUpZeppelin() {
Properties p = new Properties();
p.setProperty(Neo4jConnectionManager.NEO4J_SERVER_URL, neo4jContainer.getBoltUrl());
Expand All @@ -97,13 +99,13 @@ public void setUpZeppelin() {
.build();
}

@After
@AfterEach
public void tearDownZeppelin() throws Exception {
interpreter.close();
}

@Test
public void testTableWithArray() {
void testTableWithArray() {
interpreter.open();
InterpreterResult result = interpreter.interpret(
"return 'a' as colA, 'b' as colB, [1, 2, 3] as colC", context);
Expand All @@ -121,15 +123,15 @@ public void testTableWithArray() {
}

@Test
public void testCreateIndex() {
void testCreateIndex() {
interpreter.open();
InterpreterResult result = interpreter.interpret("CREATE INDEX ON :Person(name)", context);
assertEquals(Code.SUCCESS, result.code());
assertEquals(StringUtils.EMPTY, result.toString());
}

@Test
public void testRenderTable() {
void testRenderTable() {
interpreter.open();
InterpreterResult result = interpreter.interpret("MATCH (n:Person) "
+ "WHERE n.name IN ['name1', 'name2', 'name3'] "
Expand All @@ -144,7 +146,7 @@ public void testRenderTable() {
}

@Test
public void testRenderMap() {
void testRenderMap() {
interpreter.open();
final String jsonQuery =
"RETURN {key: \"value\", listKey: [{inner: \"Map1\"}, {inner: \"Map2\"}]} as object";
Expand Down Expand Up @@ -231,7 +233,7 @@ public void testRenderMap() {
}

@Test
public void testRenderNetwork() {
void testRenderNetwork() {
interpreter.open();
InterpreterResult result = interpreter.interpret(
"MATCH (n)-[r:KNOWS]-(m) RETURN n, r, m LIMIT 1", context);
Expand All @@ -249,7 +251,7 @@ public void testRenderNetwork() {
}

@Test
public void testFallingQuery() {
void testFallingQuery() {
interpreter.open();
final String errorMsgEmpty = "";
InterpreterResult result = interpreter.interpret(StringUtils.EMPTY, context);
Expand All @@ -266,7 +268,7 @@ public void testFallingQuery() {
}

@Test
public void testDates() {
void testDates() {
InterpreterResult result = interpreter.interpret(
"RETURN datetime('2015-06-24T12:50:35.556+0100') AS theDateTime", context);
assertEquals(Code.SUCCESS, result.code());
Expand Down Expand Up @@ -296,7 +298,7 @@ public void testDates() {
}

@Test
public void testDuration() {
void testDuration() {
InterpreterResult result = interpreter.interpret(
"RETURN duration('P14DT16H12M') AS theDuration", context);
assertEquals(Code.SUCCESS, result.code());
Expand All @@ -305,7 +307,7 @@ public void testDuration() {
}

@Test
public void testPoint() {
void testPoint() {
InterpreterResult result = interpreter.interpret("RETURN point({ x:3, y:0 }) AS cartesian_2d,"
+ "point({ x:0, y:4, z:1 }) AS cartesian_3d,"
+ "point({ latitude: 12, longitude: 56 }) AS geo_2d,"
Expand All @@ -327,7 +329,7 @@ public void testPoint() {
}

@Test
public void testMultiLineInterpreter() {
void testMultiLineInterpreter() {
Properties p = new Properties();
p.setProperty(Neo4jConnectionManager.NEO4J_SERVER_URL, neo4jContainer.getBoltUrl());
p.setProperty(Neo4jConnectionManager.NEO4J_AUTH_TYPE, Neo4jAuthType.NONE.toString());
Expand Down Expand Up @@ -358,7 +360,7 @@ public void testMultiLineInterpreter() {
}

@Test
public void testNodeDataTypes() throws JsonProcessingException {
void testNodeDataTypes() throws IOException {
InterpreterResult result = interpreter.interpret(
"CREATE (n:NodeTypes{" +
"dateTime: datetime('2015-06-24T12:50:35.556+0100')," +
Expand Down
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
<plugin.surefire.version>2.22.2</plugin.surefire.version>
<plugin.os.version>1.4.1.Final</plugin.os.version>

<testcontainers.version>1.15.1</testcontainers.version>
<testcontainers.version>1.19.0</testcontainers.version>

<MaxMetaspace>512m</MaxMetaspace>

Expand Down Expand Up @@ -1177,6 +1177,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
Expand Down

0 comments on commit 0a48d99

Please sign in to comment.