aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store/src/test
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-11-10 17:25:24 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-11-10 17:25:24 +0100
commitfbd2f59a86d8dbd54dae50ca3c3e27d0642d5806 (patch)
tree8430a24c3cdfaf9f07035a56f584055f1e65e8e4 /subprojects/store/src/test
parentfeat(web): backend URL configuration (diff)
downloadrefinery-fbd2f59a86d8dbd54dae50ca3c3e27d0642d5806.tar.gz
refinery-fbd2f59a86d8dbd54dae50ca3c3e27d0642d5806.tar.zst
refinery-fbd2f59a86d8dbd54dae50ca3c3e27d0642d5806.zip
feat(store): DataRepresentation reflective type
Diffstat (limited to 'subprojects/store/src/test')
-rw-r--r--subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java50
1 files changed, 23 insertions, 27 deletions
diff --git a/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java b/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java
index 61dd7c74..a9c2e3f7 100644
--- a/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java
+++ b/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java
@@ -1,26 +1,22 @@
1package tools.refinery.store.model.tests; 1package tools.refinery.store.model.tests;
2 2
3import static org.junit.jupiter.api.Assertions.assertEquals;
4import static org.junit.jupiter.api.Assertions.assertFalse;
5import static org.junit.jupiter.api.Assertions.assertTrue;
6
7import java.util.Set;
8
9import org.junit.jupiter.api.Assertions;
10import org.junit.jupiter.api.Test; 3import org.junit.jupiter.api.Test;
11
12import tools.refinery.store.model.Model; 4import tools.refinery.store.model.Model;
13import tools.refinery.store.model.ModelStore; 5import tools.refinery.store.model.ModelStore;
14import tools.refinery.store.model.ModelStoreImpl; 6import tools.refinery.store.model.ModelStoreImpl;
15import tools.refinery.store.tuple.Tuple;
16import tools.refinery.store.model.representation.Relation; 7import tools.refinery.store.model.representation.Relation;
8import tools.refinery.store.tuple.Tuple;
9
10import java.util.Set;
11
12import static org.junit.jupiter.api.Assertions.*;
17 13
18class ModelTest { 14class ModelTest {
19 15
20 @Test 16 @Test
21 void modelConstructionTest() { 17 void modelConstructionTest() {
22 Relation<Boolean> person = new Relation<>("Person", 1, false); 18 Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false);
23 Relation<Boolean> friend = new Relation<>("friend", 2, false); 19 Relation<Boolean> friend = new Relation<>("friend", 2, Boolean.class, false);
24 20
25 ModelStore store = new ModelStoreImpl(Set.of(person, friend)); 21 ModelStore store = new ModelStoreImpl(Set.of(person, friend));
26 Model model = store.createModel(); 22 Model model = store.createModel();
@@ -30,15 +26,15 @@ class ModelTest {
30 assertTrue(model.getDataRepresentations().contains(person)); 26 assertTrue(model.getDataRepresentations().contains(person));
31 assertTrue(model.getDataRepresentations().contains(friend)); 27 assertTrue(model.getDataRepresentations().contains(friend));
32 28
33 Relation<Integer> other = new Relation<Integer>("other", 2, null); 29 Relation<Integer> other = new Relation<Integer>("other", 2, Integer.class, null);
34 assertFalse(model.getDataRepresentations().contains(other)); 30 assertFalse(model.getDataRepresentations().contains(other));
35 } 31 }
36 32
37 @Test 33 @Test
38 void modelBuildingTest() { 34 void modelBuildingTest() {
39 Relation<Boolean> person = new Relation<>("Person", 1, false); 35 Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false);
40 Relation<Integer> age = new Relation<Integer>("age", 1, null); 36 Relation<Integer> age = new Relation<Integer>("age", 1, Integer.class, null);
41 Relation<Boolean> friend = new Relation<>("friend", 2, false); 37 Relation<Boolean> friend = new Relation<>("friend", 2, Boolean.class, false);
42 38
43 ModelStore store = new ModelStoreImpl(Set.of(person, age, friend)); 39 ModelStore store = new ModelStoreImpl(Set.of(person, age, friend));
44 Model model = store.createModel(); 40 Model model = store.createModel();
@@ -56,7 +52,7 @@ class ModelTest {
56 52
57 assertEquals(3, model.get(age, Tuple.of(0))); 53 assertEquals(3, model.get(age, Tuple.of(0)));
58 assertEquals(1, model.get(age, Tuple.of(1))); 54 assertEquals(1, model.get(age, Tuple.of(1)));
59 assertEquals(null, model.get(age, Tuple.of(2))); 55 assertNull(model.get(age, Tuple.of(2)));
60 56
61 assertTrue(model.get(friend, Tuple.of(0, 1))); 57 assertTrue(model.get(friend, Tuple.of(0, 1)));
62 assertFalse(model.get(friend, Tuple.of(0, 5))); 58 assertFalse(model.get(friend, Tuple.of(0, 5)));
@@ -64,32 +60,32 @@ class ModelTest {
64 60
65 @Test 61 @Test
66 void modelBuildingArityFailTest() { 62 void modelBuildingArityFailTest() {
67 Relation<Boolean> person = new Relation<>("Person", 1, false); 63 Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false);
68 ModelStore store = new ModelStoreImpl(Set.of(person)); 64 ModelStore store = new ModelStoreImpl(Set.of(person));
69 Model model = store.createModel(); 65 Model model = store.createModel();
70 66
71 final Tuple tuple3 = Tuple.of(1, 1, 1); 67 final Tuple tuple3 = Tuple.of(1, 1, 1);
72 Assertions.assertThrows(IllegalArgumentException.class, () -> model.put(person, tuple3, true)); 68 assertThrows(IllegalArgumentException.class, () -> model.put(person, tuple3, true));
73 Assertions.assertThrows(IllegalArgumentException.class, () -> model.get(person, tuple3)); 69 assertThrows(IllegalArgumentException.class, () -> model.get(person, tuple3));
74 } 70 }
75 71
76 @Test 72 @Test
77 void modelBuildingNullFailTest() { 73 void modelBuildingNullFailTest() {
78 Relation<Integer> age = new Relation<Integer>("age", 1, null); 74 Relation<Integer> age = new Relation<Integer>("age", 1, Integer.class, null);
79 ModelStore store = new ModelStoreImpl(Set.of(age)); 75 ModelStore store = new ModelStoreImpl(Set.of(age));
80 Model model = store.createModel(); 76 Model model = store.createModel();
81 77
82 model.put(age, Tuple.of(1), null); // valid 78 model.put(age, Tuple.of(1), null); // valid
83 Assertions.assertThrows(IllegalArgumentException.class, () -> model.put(age, null, 1)); 79 assertThrows(IllegalArgumentException.class, () -> model.put(age, null, 1));
84 Assertions.assertThrows(IllegalArgumentException.class, () -> model.get(age, null)); 80 assertThrows(IllegalArgumentException.class, () -> model.get(age, null));
85 81
86 } 82 }
87 83
88 @Test 84 @Test
89 void modelUpdateTest() { 85 void modelUpdateTest() {
90 Relation<Boolean> person = new Relation<>("Person", 1, false); 86 Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false);
91 Relation<Integer> age = new Relation<Integer>("age", 1, null); 87 Relation<Integer> age = new Relation<Integer>("age", 1, Integer.class, null);
92 Relation<Boolean> friend = new Relation<>("friend", 2, false); 88 Relation<Boolean> friend = new Relation<>("friend", 2, Boolean.class, false);
93 89
94 ModelStore store = new ModelStoreImpl(Set.of(person, age, friend)); 90 ModelStore store = new ModelStoreImpl(Set.of(person, age, friend));
95 Model model = store.createModel(); 91 Model model = store.createModel();
@@ -113,8 +109,8 @@ class ModelTest {
113 109
114 @Test 110 @Test
115 void restoreTest() { 111 void restoreTest() {
116 Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); 112 Relation<Boolean> person = new Relation<Boolean>("Person", 1, Boolean.class, false);
117 Relation<Boolean> friend = new Relation<Boolean>("friend", 2, false); 113 Relation<Boolean> friend = new Relation<Boolean>("friend", 2, Boolean.class, false);
118 114
119 ModelStore store = new ModelStoreImpl(Set.of(person, friend)); 115 ModelStore store = new ModelStoreImpl(Set.of(person, friend));
120 Model model = store.createModel(); 116 Model model = store.createModel();