forked from jakewins/neo4j-procedure-template
-
Notifications
You must be signed in to change notification settings - Fork 148
/
LegacyFullTextIndexTest.java
50 lines (40 loc) · 1.88 KB
/
LegacyFullTextIndexTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package example;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.neo4j.driver.v1.*;
import org.neo4j.harness.ServerControls;
import org.neo4j.harness.TestServerBuilders;
import static org.assertj.core.api.Assertions.assertThat;
import static org.neo4j.driver.v1.Values.parameters;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class LegacyFullTextIndexTest {
private static final Config driverConfig = Config.build().withoutEncryption().toConfig();
private ServerControls embeddedDatabaseServer;
@BeforeAll
void initializeNeo4j() {
this.embeddedDatabaseServer = TestServerBuilders
.newInProcessBuilder()
.withProcedure(FullTextIndex.class)
.newServer();
}
@Test
public void shouldAllowIndexingAndFindingANode() {
// In a try-block, to make sure we close the driver and session after the test
try(Driver driver = GraphDatabase.driver(embeddedDatabaseServer.boltURI(), driverConfig);
Session session = driver.session())
{
// Given I've started Neo4j with the FullTextIndex procedure class
// which my 'neo4j' rule above does.
// And given I have a node in the database
long nodeId = session.run( "CREATE (p:User {name:'Brookreson'}) RETURN id(p)" )
.single()
.get( 0 ).asLong();
// When I use the index procedure to index a node
session.run( "CALL example.index({id}, ['name'])", parameters( "id", nodeId ) );
// Then I can search for that node with lucene query syntax
StatementResult result = session.run( "CALL example.search('User', 'name:Brook*')" );
assertThat(result.single().get( "nodeId" ).asLong()).isEqualTo( nodeId );
}
}
}