forked from joel-costigliola/assertj-neo4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[joel-costigliola#75] First clean after api design
- Loading branch information
Showing
6 changed files
with
92 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
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.concurrent.Callable; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* @author patouche - 5/26/20. | ||
*/ | ||
interface DriverAssert { | ||
|
||
Driver getDriver(); | ||
|
||
|
||
|
||
|
||
public class DriverAssert extends AbstractAssert<DriverAssert, Driver> { | ||
|
||
public DriverAssert(final Driver driver) { | ||
super(driver, DriverAssert.class); | ||
} | ||
|
||
private DriverResultAssert executing(final String query) { | ||
try (Session session = this.actual.session()) { | ||
final Result result = session.run(query, TransactionConfig.builder() | ||
.build()); | ||
return new DriverResultAssert(actual, result); | ||
} | ||
} | ||
|
||
public DriverAssert executing(final String query, final Consumer<DriverResultAssert> fn) { | ||
final DriverResultAssert executing = this.executing(query).as("Query results of '%s'", query); | ||
fn.accept(executing); | ||
return myself; | ||
} | ||
|
||
public DriverAssert withDataset(final String... queries) { | ||
Stream.of(queries).forEach(q -> { | ||
try (final Session session = this.actual.session()) { | ||
session.run(q, TransactionConfig.builder().build()); | ||
} | ||
}); | ||
return myself; | ||
} | ||
|
||
public DriverAssert when(Runnable runnable) { | ||
runnable.run(); | ||
return myself; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters