-
Notifications
You must be signed in to change notification settings - Fork 1
/
DataLoaderTest.java
95 lines (81 loc) · 3.24 KB
/
DataLoaderTest.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.example;
import com.vaticle.typedb.client.api.TypeDBClient;
import com.vaticle.typedb.client.api.TypeDBOptions;
import com.vaticle.typedb.client.api.TypeDBSession;
import com.vaticle.typedb.client.TypeDB;
import com.vaticle.typedb.client.api.TypeDBTransaction;
import com.vaticle.typeql.lang.TypeQL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
public class DataLoaderTest {
TypeDBClient client;
TypeDBSession session;
String databaseName = "achievements";
String databaseAddress = "localhost:1729";
@Before
public void loadDataAndConnect() throws FileNotFoundException {
DataLoader.main(new String[] {});
client = TypeDB.coreClient(databaseAddress);
session = client.session(databaseName, TypeDBSession.Type.DATA);
}
static class TestExampleLong {
String message;
String query;
long correctResult;
public TestExampleLong(String message, String query, long result) {
this.message = message;
this.query = query;
this.correctResult = result;
}
public void testQueryResult(TypeDBTransaction transaction) {
long queryResult = transaction.query().match(TypeQL.parseQuery(query).asMatchAggregate()).get().asNumber().longValue();
assertEquals(message, correctResult, queryResult);
}
}
static class TestQuantity extends TestExampleLong {
public TestQuantity(String entity, long result) {
super("Number of " + entity + "s",
"match $x isa " + entity + "; get $x; count;",
result);
}
}
@Test
public void assertMigrationResults() {
Collection<TestQuantity> testExamples = new ArrayList<>();
testExamples.add(new TestQuantity("student", 915));
testExamples.add(new TestQuantity("teacher", 11));
testExamples.add(new TestQuantity("group", 190));
testExamples.add(new TestQuantity("result", 10));
testExamples.add(new TestQuantity("olympiad", 23));
testExamples.add(new TestQuantity("membership", 2121));
testExamples.add(new TestQuantity("teaching", 123));
testExamples.add(new TestQuantity("participation", 1316));
TypeDBTransaction transaction = session.transaction(TypeDBTransaction.Type.READ);
for (TestExampleLong example : testExamples) {
example.testQueryResult(transaction);
}
transaction.close();
}
@Test
public void assertRules() {
TestExampleLong example = new TestExampleLong(
"Number of ROI-2023 prize-winners",
"match $stud isa student; $olymp isa olympiad, has title 'ROI 2023'; " +
"($stud, $olymp) isa prize-winning; get $stud; count;",
6
);
TypeDBTransaction transaction = session.transaction(TypeDBTransaction.Type.READ, TypeDBOptions.core().infer(true));
example.testQueryResult(transaction);
transaction.close();
}
@After
public void disconnect() {
session.close();
client.close();
}
}