Skip to content

Commit 175b14b

Browse files
authored
Merge pull request #14 from jamesross03/develop
1.0.2-SNAPSHOT: patch
2 parents 955790d + 371405b commit 175b14b

File tree

11 files changed

+850
-11
lines changed

11 files changed

+850
-11
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>uk.ac.standrews.cs</groupId>
2525
<artifactId>common-pom</artifactId>
26-
<version>4.0-SNAPSHOT</version>
26+
<version>4.1.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>population-records</artifactId>
@@ -49,9 +49,9 @@
4949
</dependency>
5050

5151
<dependency>
52-
<groupId>org.junit.jupiter</groupId>
53-
<artifactId>junit-jupiter</artifactId>
54-
<version>5.10.2</version> <!-- Use the latest version -->
52+
<groupId>org.neo4j.test</groupId>
53+
<artifactId>neo4j-harness</artifactId>
54+
<version>5.26.9</version>
5555
<scope>test</scope>
5656
</dependency>
5757

src/main/java/uk/ac/standrews/cs/population_records/RecordRepository.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public void addMarriage(Marriage marriage) throws BucketException {
8686

8787
public static final int RECORDS_IMPORTED_PER_TRANSACTION = 10000;
8888

89-
private <T extends LXP> void importRecords(IBucket<T> bucket, Iterable<LXP> records) throws BucketException {
89+
@SuppressWarnings("unchecked")
90+
private <T extends LXP> void importRecords(IBucket<T> bucket, Iterable<LXP> records) throws BucketException {
9091

9192
final ITransactionManager transaction_manager = Store.getInstance().getTransactionManager();
9293
final boolean auto_commit_previously_enabled = transaction_manager.isAutoCommitEnabled();
@@ -131,7 +132,7 @@ private <T extends LXP> Iterable<T> getRecords(IBucket<T> bucket) {
131132

132133
return () -> new Iterator<>() {
133134

134-
final List<String> object_ids = bucket.getObjectIds();
135+
final List<Long> object_ids = bucket.getObjectIds();
135136
final int bucket_size = object_ids.size();
136137
int next_index = 0;
137138

@@ -251,7 +252,7 @@ public static String[] getBucketNames() {
251252
return new String[]{BIRTHS_BUCKET_NAME, DEATHS_BUCKET_NAME, MARRIAGES_BUCKET_NAME};
252253
}
253254

254-
public IBucket getBucket(String bucketName) {
255+
public IBucket<?> getBucket(String bucketName) {
255256
switch (bucketName) {
256257
case BIRTHS_BUCKET_NAME:
257258
return births;

src/main/java/uk/ac/standrews/cs/population_records/record_types/Birth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public Birth() {
5353
super();
5454
}
5555

56-
public Birth(String persistent_object_id, Map properties, IBucket bucket) throws PersistentObjectException {
56+
public Birth(long persistent_object_id, Map properties, IBucket bucket) throws PersistentObjectException {
5757

5858
super(persistent_object_id, properties, bucket);
5959
}

src/main/java/uk/ac/standrews/cs/population_records/record_types/Death.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public Death() {
5757
super();
5858
}
5959

60-
public Death(String persistent_Object_id, Map properties, IBucket bucket) throws PersistentObjectException {
60+
public Death(long persistent_Object_id, Map properties, IBucket bucket) throws PersistentObjectException {
6161

6262
super(persistent_Object_id, properties, bucket);
6363
}
@@ -75,7 +75,7 @@ public boolean equals(final Object o) {
7575

7676
@Override
7777
public int hashCode() {
78-
return Long.valueOf(this.getId()).hashCode();
78+
return Long.valueOf(getId()).hashCode();
7979
}
8080

8181
@Override

src/main/java/uk/ac/standrews/cs/population_records/record_types/Marriage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public Marriage() {
6060
super();
6161
}
6262

63-
public Marriage(String persistent_object_id, Map properties, IBucket bucket) throws PersistentObjectException {
63+
public Marriage(long persistent_object_id, Map properties, IBucket bucket) throws PersistentObjectException {
6464

6565
super(persistent_object_id, properties, bucket);
6666
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright 2021 Systems Research Group, University of St Andrews:
3+
* <https://github.com/stacs-srg>
4+
*
5+
* This file is part of the module population-records.
6+
*
7+
* population-records is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8+
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
9+
* version.
10+
*
11+
* population-records is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
12+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along with population-records. If not, see
15+
* <http://www.gnu.org/licenses/>.
16+
*/
17+
package uk.ac.standrews.cs.population_records;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertThrows;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
25+
import java.io.IOException;
26+
import java.net.SocketAddress;
27+
import java.util.Arrays;
28+
import java.util.List;
29+
30+
import org.junit.jupiter.api.AfterAll;
31+
import org.junit.jupiter.api.AfterEach;
32+
import org.junit.jupiter.api.BeforeAll;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
35+
36+
import org.neo4j.driver.AuthTokens;
37+
import org.neo4j.driver.Driver;
38+
import org.neo4j.driver.GraphDatabase;
39+
import org.neo4j.driver.Session;
40+
import org.neo4j.harness.Neo4j;
41+
import org.neo4j.harness.Neo4jBuilders;
42+
43+
import uk.ac.standrews.cs.neoStorr.impl.Store;
44+
import uk.ac.standrews.cs.neoStorr.impl.exceptions.BucketException;
45+
import uk.ac.standrews.cs.neoStorr.impl.exceptions.RepositoryException;
46+
import uk.ac.standrews.cs.neoStorr.interfaces.IBucket;
47+
import uk.ac.standrews.cs.population_records.record_types.*;
48+
49+
public class RecordRepositoryNeoTest {
50+
static final RecordTypeTest BIRTH_TEST = new BirthTest();
51+
static final RecordTypeTest MARRIAGE_TEST = new MarriageTest();
52+
static final RecordTypeTest DEATH_TEST = new DeathTest();
53+
static final String REPO_NAME_BASE = "test_";
54+
55+
static Neo4j neo4jDb;
56+
String repoName;
57+
RecordRepository repo;
58+
59+
@BeforeAll
60+
static void setUpNeo() {
61+
neo4jDb = Neo4jBuilders.newInProcessBuilder()
62+
.build();
63+
// Sets override for neo-storr.neoDbCypherBridge
64+
System.setProperty("NeoDBTestURL", neo4jDb.boltURI().toString());
65+
}
66+
67+
@BeforeEach
68+
void setUpRepo() {
69+
repoName = REPO_NAME_BASE + System.nanoTime();
70+
repo = new RecordRepository(repoName);
71+
}
72+
73+
@AfterEach
74+
void tearDown() throws RepositoryException {
75+
Store.getInstance().deleteRepository(repoName);
76+
assertFalse(Store.getInstance().repositoryExists(repoName));
77+
repo = null;
78+
}
79+
80+
@AfterAll
81+
static void tearDownNeo() {
82+
Store.getInstance().close();
83+
System.clearProperty("NeoDBTestURL");
84+
85+
if (neo4jDb!= null) neo4jDb.close();
86+
neo4jDb = null;
87+
}
88+
89+
@Test
90+
public void testNeo4jConnection() {
91+
String testString = "Hello world";
92+
Driver driver = GraphDatabase.driver(neo4jDb.boltURI(), AuthTokens.none());
93+
94+
try (Session session = driver.session()) {
95+
String response = session.run("RETURN '"+testString+"'").single().get(0).asString();
96+
assertEquals(testString, response);
97+
}
98+
}
99+
100+
101+
@Test
102+
void testAddAndGetBirthRecord() throws BucketException, RepositoryException, IOException {
103+
Birth birth = new Birth(BIRTH_TEST.datasetNoRecords, BIRTH_TEST.testRecords.get(0));
104+
repo.addBirth(birth);
105+
106+
assertEquals(1, repo.getNumberOfBirths());
107+
108+
Birth retrieved = repo.getBirths().iterator().next();
109+
assertEquals(birth, retrieved);
110+
}
111+
112+
@Test
113+
void testAddAndGetMarriageRecord() throws BucketException, RepositoryException, IOException {
114+
Marriage marriage = new Marriage(MARRIAGE_TEST.datasetNoRecords, MARRIAGE_TEST.testRecords.get(0));
115+
repo.addMarriage(marriage);
116+
117+
assertEquals(1, repo.getNumberOfMarriages());
118+
119+
Marriage retrieved = repo.getMarriages().iterator().next();
120+
assertEquals(marriage, retrieved);
121+
}
122+
123+
@Test
124+
void testAddAndGetDeathRecord() throws BucketException, RepositoryException, IOException {
125+
Death death = new Death(DEATH_TEST.datasetNoRecords, DEATH_TEST.testRecords.get(0));
126+
repo.addDeath(death);
127+
128+
assertEquals(1, repo.getNumberOfDeaths());
129+
130+
Death retrieved = repo.getDeaths().iterator().next();
131+
assertEquals(death, retrieved);
132+
}
133+
134+
@Test
135+
void testDeleteBuckets() throws RepositoryException {
136+
repo.deleteBirthsBucket();
137+
repo.deleteDeathsBucket();
138+
repo.deleteMarriagesBucket();
139+
140+
for (String x : RecordRepository.getBucketNames()) {
141+
assertThrows(RepositoryException.class, () -> {
142+
Store.getInstance().getRepository(repoName).getBucket(x);
143+
});
144+
}
145+
}
146+
147+
@Test
148+
void testGetBuckets() {
149+
for (String x : RecordRepository.getBucketNames()) {
150+
assertNotNull(repo.getBucket(x));
151+
}
152+
}
153+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2021 Systems Research Group, University of St Andrews:
3+
* <https://github.com/stacs-srg>
4+
*
5+
* This file is part of the module population-records.
6+
*
7+
* population-records is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8+
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
9+
* version.
10+
*
11+
* population-records is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
12+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along with population-records. If not, see
15+
* <http://www.gnu.org/licenses/>.
16+
*/
17+
package uk.ac.standrews.cs.population_records;
18+
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
20+
21+
import java.util.Arrays;
22+
import java.util.List;
23+
import org.junit.jupiter.api.Test;
24+
25+
public class RecordRepositoryTest {
26+
@Test
27+
void testGetBucketNames() {
28+
List<String> bucketNames = Arrays.asList(RecordRepository.getBucketNames());
29+
assertTrue(bucketNames.contains("birth_records"));
30+
assertTrue(bucketNames.contains("marriage_records"));
31+
assertTrue(bucketNames.contains("death_records"));
32+
}
33+
}

0 commit comments

Comments
 (0)