|
20 | 20 |
|
21 | 21 | package com.arangodb;
|
22 | 22 |
|
23 |
| -import com.arangodb.entity.BaseDocument; |
24 |
| -import com.arangodb.entity.BaseEdgeDocument; |
25 |
| -import com.arangodb.entity.CollectionEntity; |
26 |
| -import com.arangodb.entity.CollectionPropertiesEntity; |
27 |
| -import com.arangodb.entity.CollectionRevisionEntity; |
28 |
| -import com.arangodb.entity.DocumentCreateEntity; |
29 |
| -import com.arangodb.entity.DocumentDeleteEntity; |
30 |
| -import com.arangodb.entity.DocumentEntity; |
31 |
| -import com.arangodb.entity.DocumentImportEntity; |
32 |
| -import com.arangodb.entity.DocumentUpdateEntity; |
33 |
| -import com.arangodb.entity.IndexEntity; |
34 |
| -import com.arangodb.entity.IndexType; |
35 |
| -import com.arangodb.entity.MultiDocumentEntity; |
36 |
| -import com.arangodb.entity.Permissions; |
37 |
| -import com.arangodb.entity.ShardEntity; |
| 23 | +import com.arangodb.entity.*; |
38 | 24 | import com.arangodb.model.*;
|
39 | 25 | import com.arangodb.model.DocumentImportOptions.OnDuplicate;
|
| 26 | +import com.arangodb.serde.JacksonSerde; |
40 | 27 | import com.arangodb.util.MapBuilder;
|
41 | 28 | import com.arangodb.util.RawBytes;
|
42 | 29 | import com.arangodb.util.RawJson;
|
43 | 30 | import com.fasterxml.jackson.annotation.JsonInclude;
|
| 31 | +import com.fasterxml.jackson.annotation.JsonTypeInfo; |
44 | 32 | import com.fasterxml.jackson.core.JsonProcessingException;
|
45 | 33 | import com.fasterxml.jackson.databind.ObjectMapper;
|
46 | 34 | import org.junit.jupiter.api.BeforeAll;
|
@@ -90,6 +78,78 @@ static void init() {
|
90 | 78 | initEdgeCollections(EDGE_COLLECTION_NAME);
|
91 | 79 | }
|
92 | 80 |
|
| 81 | + @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "type") |
| 82 | + public interface Animal { |
| 83 | + String getKey(); |
| 84 | + |
| 85 | + String getName(); |
| 86 | + } |
| 87 | + |
| 88 | + public static class Dog implements Animal { |
| 89 | + |
| 90 | + @Key |
| 91 | + private String key; |
| 92 | + private String name; |
| 93 | + |
| 94 | + public Dog() { |
| 95 | + } |
| 96 | + |
| 97 | + public Dog(String key, String name) { |
| 98 | + this.key = key; |
| 99 | + this.name = name; |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public String getKey() { |
| 104 | + return key; |
| 105 | + } |
| 106 | + |
| 107 | + public void setKey(String key) { |
| 108 | + this.key = key; |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public String getName() { |
| 113 | + return name; |
| 114 | + } |
| 115 | + |
| 116 | + public void setName(String name) { |
| 117 | + this.name = name; |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + public static class Cat implements Animal { |
| 122 | + @Key |
| 123 | + private String key; |
| 124 | + private String name; |
| 125 | + |
| 126 | + public Cat() { |
| 127 | + } |
| 128 | + |
| 129 | + public Cat(String key, String name) { |
| 130 | + this.key = key; |
| 131 | + this.name = name; |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public String getKey() { |
| 136 | + return key; |
| 137 | + } |
| 138 | + |
| 139 | + public void setKey(String key) { |
| 140 | + this.key = key; |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public String getName() { |
| 145 | + return name; |
| 146 | + } |
| 147 | + |
| 148 | + public void setName(String name) { |
| 149 | + this.name = name; |
| 150 | + } |
| 151 | + } |
| 152 | + |
93 | 153 | @ParameterizedTest(name = "{index}")
|
94 | 154 | @MethodSource("cols")
|
95 | 155 | void insertDocument(ArangoCollection collection) {
|
@@ -160,6 +220,40 @@ void insertDocumentReturnNew(ArangoCollection collection) {
|
160 | 220 | assertThat(doc.getNew()).isNotNull();
|
161 | 221 | }
|
162 | 222 |
|
| 223 | + @ParameterizedTest(name = "{index}") |
| 224 | + @MethodSource("cols") |
| 225 | + void insertDocumentWithTypeOverwriteModeReplace(ArangoCollection collection) { |
| 226 | + assumeTrue(isAtLeastVersion(3, 7)); |
| 227 | + assumeTrue(collection.getSerde().getUserSerde() instanceof JacksonSerde, "polymorphic deserialization support required"); |
| 228 | + |
| 229 | + String key = UUID.randomUUID().toString(); |
| 230 | + Dog dog = new Dog(key, "Teddy"); |
| 231 | + Cat cat = new Cat(key, "Luna"); |
| 232 | + |
| 233 | + final DocumentCreateOptions options = new DocumentCreateOptions() |
| 234 | + .returnNew(true) |
| 235 | + .returnOld(true) |
| 236 | + .overwriteMode(OverwriteMode.replace); |
| 237 | + collection.insertDocument(dog, options); |
| 238 | + final DocumentCreateEntity<Animal> doc = collection.insertDocument(cat, options, Animal.class); |
| 239 | + assertThat(doc).isNotNull(); |
| 240 | + assertThat(doc.getId()).isNotNull(); |
| 241 | + assertThat(doc.getKey()).isNotNull().isEqualTo(key); |
| 242 | + assertThat(doc.getRev()).isNotNull(); |
| 243 | + |
| 244 | + assertThat(doc.getOld()) |
| 245 | + .isNotNull() |
| 246 | + .isInstanceOf(Dog.class); |
| 247 | + assertThat(doc.getOld().getKey()).isEqualTo(key); |
| 248 | + assertThat(doc.getOld().getName()).isEqualTo("Teddy"); |
| 249 | + |
| 250 | + assertThat(doc.getNew()) |
| 251 | + .isNotNull() |
| 252 | + .isInstanceOf(Cat.class); |
| 253 | + assertThat(doc.getNew().getKey()).isEqualTo(key); |
| 254 | + assertThat(doc.getNew().getName()).isEqualTo("Luna"); |
| 255 | + } |
| 256 | + |
163 | 257 | @ParameterizedTest(name = "{index}")
|
164 | 258 | @MethodSource("cols")
|
165 | 259 | void insertDocumentOverwriteModeIgnore(ArangoCollection collection) {
|
|
0 commit comments