|
12 | 12 |
|
13 | 13 | package com.phocassoftware.graphql.database.manager.test.hashed;
|
14 | 14 |
|
15 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
16 |
| -import static org.junit.jupiter.api.Assertions.assertThrows; |
17 |
| - |
18 | 15 | import com.phocassoftware.graphql.database.manager.Database;
|
19 | 16 | import com.phocassoftware.graphql.database.manager.Table;
|
20 | 17 | import com.phocassoftware.graphql.database.manager.annotations.Hash;
|
| 18 | +import com.phocassoftware.graphql.database.manager.test.TestDatabase; |
21 | 19 | import com.phocassoftware.graphql.database.manager.test.annotations.DatabaseNames;
|
22 |
| -import java.util.concurrent.CompletionException; |
| 20 | +import com.phocassoftware.graphql.database.manager.test.annotations.DatabaseOrganisation; |
| 21 | +import org.junit.jupiter.api.Assertions; |
| 22 | + |
| 23 | +import java.util.Comparator; |
23 | 24 | import java.util.concurrent.ExecutionException;
|
24 | 25 |
|
25 | 26 | final class DynamoDbLinkTest {
|
26 | 27 |
|
27 | 28 | @TestDatabase
|
28 |
| - void testSimpleQuery(@DatabaseNames({ "prod", "stage" }) final Database db, @DatabaseNames("prod") final Database dbProd) |
29 |
| - throws InterruptedException, ExecutionException { |
| 29 | + void testSimpleQuery( |
| 30 | + @DatabaseNames({ "prod", "stage" }) @DatabaseOrganisation("fixed") final Database db, |
| 31 | + @DatabaseNames("prod") @DatabaseOrganisation("fixed") final Database dbProd |
| 32 | + ) throws ExecutionException, InterruptedException { |
30 | 33 | var garry = db.put(new SimpleTable("garry")).get();
|
| 34 | + var john = db.put(new AnotherTable("john")).get(); |
| 35 | + var frank = dbProd.put(new SimpleTable("frank")).get(); |
31 | 36 | var bob = dbProd.put(new AnotherTable("bob")).get();
|
32 | 37 |
|
33 |
| - var t = assertThrows(CompletionException.class, () -> db.link(garry, bob.getClass(), bob.getId()).join()); |
34 |
| - assertEquals(UnsupportedOperationException.class, t.getCause().getClass()); |
| 38 | + db.link(garry, bob.getClass(), bob.getId()).get(); |
| 39 | + dbProd.link(frank, bob.getClass(), bob.getId()).get(); |
| 40 | + db.link(garry, john.getClass(), john.getId()).get(); |
| 41 | + |
| 42 | + john = db.get(AnotherTable.class, john.getId()).get(); |
| 43 | + bob = db.get(AnotherTable.class, bob.getId()).get(); |
| 44 | + |
| 45 | + var johnLink = db.getLink(john, SimpleTable.class).get(); |
| 46 | + Assertions.assertEquals("garry", johnLink.name); |
| 47 | + |
| 48 | + var bobLinks = db.getLinks(bob, SimpleTable.class).get(); |
| 49 | + |
| 50 | + Assertions.assertEquals(1, bobLinks.size()); |
| 51 | + bobLinks.sort(Comparator.comparing(a -> a.name)); |
| 52 | + |
| 53 | + Assertions.assertEquals("frank", bobLinks.get(0).name); |
| 54 | + } |
| 55 | + |
| 56 | + @TestDatabase |
| 57 | + void testUpdate(final Database db) throws InterruptedException, ExecutionException { |
| 58 | + var garry = db.put(new SimpleTable("garry")).get(); |
| 59 | + var john = db.put(new AnotherTable("john")).get(); |
| 60 | + var bob = db.put(new AnotherTable("bob")).get(); |
| 61 | + |
| 62 | + db.link(garry, john.getClass(), john.getId()).get(); |
| 63 | + db.link(garry, bob.getClass(), bob.getId()).get(); |
| 64 | + |
| 65 | + garry = db.get(SimpleTable.class, garry.getId()).get(); |
| 66 | + john = db.get(AnotherTable.class, john.getId()).get(); |
| 67 | + bob = db.get(AnotherTable.class, bob.getId()).get(); |
| 68 | + |
| 69 | + var bobLinks = db.getLink(bob, SimpleTable.class).get(); |
| 70 | + Assertions.assertEquals("garry", bobLinks.name); |
| 71 | + |
| 72 | + var garryLink = db.getLink(garry, AnotherTable.class).get(); |
| 73 | + Assertions.assertEquals("bob", garryLink.getName()); |
| 74 | + |
| 75 | + var johnLink = db.getLinks(john, SimpleTable.class).get(); |
| 76 | + Assertions.assertEquals(0, johnLink.size()); |
| 77 | + } |
| 78 | + |
| 79 | + @TestDatabase |
| 80 | + void testDelete(final Database db) throws InterruptedException, ExecutionException { |
| 81 | + var garry = db.put(new SimpleTable("garry")).get(); |
| 82 | + var john = db.put(new AnotherTable("john")).get(); |
| 83 | + |
| 84 | + db.link(garry, john.getClass(), john.getId()).get(); |
| 85 | + |
| 86 | + Assertions |
| 87 | + .assertThrows( |
| 88 | + RuntimeException.class, |
| 89 | + () -> { |
| 90 | + db.delete(garry, false).get(); |
| 91 | + } |
| 92 | + ); |
| 93 | + |
| 94 | + db.delete(garry, true).get(); |
| 95 | + |
| 96 | + var list = db.getLinks(john, SimpleTable.class).get(); |
| 97 | + Assertions.assertEquals(0, list.size()); |
| 98 | + } |
| 99 | + |
| 100 | + @TestDatabase |
| 101 | + void testDeleteLinks(final Database db) throws InterruptedException, ExecutionException { |
| 102 | + var garry = db.put(new SimpleTable("garry")).get(); |
| 103 | + var john = db.put(new AnotherTable("john")).get(); |
| 104 | + |
| 105 | + garry = db.link(garry, john.getClass(), john.getId()).get(); |
| 106 | + |
| 107 | + garry = db.deleteLinks(garry).get(); |
| 108 | + |
| 109 | + garry = db.get(SimpleTable.class, garry.getId()).get(); |
| 110 | + |
| 111 | + var list = db.getLinks(john, SimpleTable.class).get(); |
| 112 | + Assertions.assertEquals(0, list.size()); |
| 113 | + |
| 114 | + var list2 = db.getLinks(garry, AnotherTable.class).get(); |
| 115 | + Assertions.assertEquals(0, list2.size()); |
| 116 | + } |
| 117 | + |
| 118 | + @TestDatabase |
| 119 | + void unlink(final Database db) throws InterruptedException, ExecutionException { |
| 120 | + var garry = db.put(new SimpleTable("garry")).get(); |
| 121 | + var bob = db.put(new AnotherTable("bob")).get(); |
| 122 | + |
| 123 | + db.link(garry, bob.getClass(), bob.getId()).get(); |
| 124 | + |
| 125 | + garry = db.get(SimpleTable.class, garry.getId()).get(); |
| 126 | + bob = db.get(AnotherTable.class, bob.getId()).get(); |
| 127 | + |
| 128 | + var bobLinks = db.getLink(bob, SimpleTable.class).get(); |
| 129 | + Assertions.assertEquals("garry", bobLinks.name); |
| 130 | + |
| 131 | + var garryLink = db.getLink(garry, AnotherTable.class).get(); |
| 132 | + Assertions.assertEquals("bob", garryLink.getName()); |
| 133 | + |
| 134 | + db.unlink(garry, AnotherTable.class, bob.getId()).get(); |
| 135 | + |
| 136 | + var unlinked = db.getLink(garry, AnotherTable.class).get(); |
| 137 | + Assertions.assertNull(unlinked); |
35 | 138 | }
|
36 | 139 |
|
37 | 140 | @Hash(SimplerHasher.class)
|
|
0 commit comments