Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Patouche committed May 26, 2020
1 parent f015dae commit 8e95b89
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>neo4j</artifactId>
<version>1.14.2</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -80,6 +87,20 @@
</reporting>

<profiles>
<profile>
<id>driver-neo4j-4</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>4.0.1</version>
<optional>true</optional>
</dependency>
</dependencies>
</profile>
<profile>
<id>coverage</id>
<activation>
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/org/assertj/neo4j/api/BaseDriverAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.assertj.neo4j.api;

import org.assertj.core.api.AbstractAssert;
import org.neo4j.driver.Driver;
import org.neo4j.driver.Result;
import org.neo4j.driver.Session;
import org.neo4j.driver.TransactionConfig;

import java.util.function.Consumer;

/**
* @author patouche - 5/26/20.
*/
public class BaseDriverAssert
extends AbstractAssert<BaseDriverAssert, Driver>
implements DriverAssert {

public BaseDriverAssert(final Driver driver) {
super(driver, Driver.class);
}

@Override
public Driver getDriver() {
return this.actual;
}

private DriverResultAssert executing(final String cypherQuery) {
try (Session session = this.getDriver().session()) {
final Result result = session.run(cypherQuery, TransactionConfig.builder()
.build());
return new DriverResultAssert(getDriver(), result);
}
}


public BaseDriverAssert executing(final String cypherQuery, final Consumer<DriverResultAssert> fn) {
final DriverResultAssert executing = this.executing(cypherQuery);
fn.accept(executing);
return myself;
}

}
20 changes: 20 additions & 0 deletions src/main/java/org/assertj/neo4j/api/DriverAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.assertj.neo4j.api;

import org.neo4j.driver.Driver;
import org.neo4j.driver.Result;
import org.neo4j.driver.Session;
import org.neo4j.driver.TransactionConfig;

import java.util.function.Consumer;

/**
* @author patouche - 5/26/20.
*/
interface DriverAssert {

Driver getDriver();




}
15 changes: 15 additions & 0 deletions src/main/java/org/assertj/neo4j/api/DriverAssertions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.assertj.neo4j.api;

import org.neo4j.driver.Driver;

/**
* @author patouche - 5/26/20.
*/
public class DriverAssertions {

public static BaseDriverAssert assertThat(Driver driver) {
return new BaseDriverAssert(driver);
}


}
59 changes: 59 additions & 0 deletions src/main/java/org/assertj/neo4j/api/DriverResultAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.assertj.neo4j.api;

import org.assertj.core.api.AbstractIterableAssert;
import org.assertj.core.api.MapAssert;
import org.neo4j.driver.Driver;
import org.neo4j.driver.Record;
import org.neo4j.driver.Result;

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

/**
* @author patouche - 5/26/20.
*/
public class DriverResultAssert
extends AbstractIterableAssert<DriverResultAssert,
Iterable<? extends Map<String, Object>>,
Map<String, Object>,
MapAssert<String, Object>>
implements DriverAssert {

private final Driver driver;

public DriverResultAssert(final Driver driver, final Result result) {
// List<Map<String, Object>>
this(driver, result.list(Record::asMap));
}

private DriverResultAssert(final Driver driver, final Iterable<? extends Map<String, Object>> result) {
// List<Map<String, Object>>
super(result, DriverResultAssert.class);
this.driver = driver;
}

@Override
public Driver getDriver() {
return this.driver;
}

@Override
protected MapAssert<String, Object> toAssert(final Map<String, Object> value, final String description) {
return new MapAssert<>(value).as(description);
}



@Override
protected DriverResultAssert newAbstractIterableAssert(final Iterable<? extends Map<String, Object>> iterable) {
return new DriverResultAssert(this.driver, iterable);
}

public MapAssert<String, Object> single() {
return hasSize(1).first();
}

public DriverResultAssert filteredOnKeys(final String... keys) {
return filteredOn(m -> Stream.of(keys).allMatch(m::containsKey));
}
}
43 changes: 43 additions & 0 deletions src/test/java/org/assertj/neo4j/api/IntegrationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.assertj.neo4j.api;

import org.junit.ClassRule;
import org.junit.Test;
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Record;
import org.testcontainers.containers.Neo4jContainer;

/**
* @author patouche - 5/26/20.
*/

public class IntegrationTest {

@ClassRule
public static Neo4jContainer NEO4J_CONTAINER = new Neo4jContainer<>("neo4j:3.4.18")
.withAdminPassword(null);

@Test
public void version_3_4() throws Exception {

// GIVEN
// WHEN
// THEN
final Driver driver = GraphDatabase.driver(NEO4J_CONTAINER.getBoltUrl());

DriverAssertions.assertThat(driver)
.executing("MATCH (n) RETURN", result -> {
result
.filteredOnKeys("key-1", "key-2")
.single();
})
.executing("MATCH (n) RETURN", result -> {
result
.filteredOnKeys("key-2", "key-3")
.single();
});


}
}

0 comments on commit 8e95b89

Please sign in to comment.