|
17 | 17 |
|
18 | 18 | import static java.util.Collections.singletonMap;
|
19 | 19 | import static org.hamcrest.MatcherAssert.assertThat;
|
| 20 | +import static org.hamcrest.Matchers.contains; |
| 21 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
| 22 | +import static org.hamcrest.Matchers.equalTo; |
20 | 23 | import static org.hamcrest.Matchers.hasEntry;
|
21 | 24 | import static org.hamcrest.Matchers.is;
|
22 | 25 | import static software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues.nullAttributeValue;
|
|
25 | 28 | import java.util.Arrays;
|
26 | 29 | import java.util.HashMap;
|
27 | 30 | import java.util.Map;
|
| 31 | +import java.util.stream.Collectors; |
| 32 | +import org.junit.jupiter.api.Assertions; |
28 | 33 | import org.junit.jupiter.api.Test;
|
29 | 34 | import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.AbstractBean;
|
30 | 35 | import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.AbstractImmutable;
|
@@ -213,37 +218,86 @@ public void documentImmutable_map_correctlyMapsImmutableAttributes() {
|
213 | 218 | public void dynamoDbFlatten_correctlyFlattensBeanAttributes() {
|
214 | 219 | ImmutableTableSchema<FlattenedBeanImmutable> tableSchema =
|
215 | 220 | ImmutableTableSchema.create(FlattenedBeanImmutable.class);
|
| 221 | + |
| 222 | + assertThat(tableSchema.attributeNames(), containsInAnyOrder("id", "attribute1", "attribute2", |
| 223 | + "prefix-attribute2", "autoPrefixBean.attribute2", "custom.attribute2")); |
| 224 | + |
216 | 225 | AbstractBean abstractBean = new AbstractBean();
|
217 | 226 | abstractBean.setAttribute2("two");
|
218 | 227 | FlattenedBeanImmutable flattenedBeanImmutable =
|
219 | 228 | new FlattenedBeanImmutable.Builder().setId("id-value")
|
220 | 229 | .setAttribute1("one")
|
221 | 230 | .setAbstractBean(abstractBean)
|
| 231 | + .setExplicitPrefixBean(abstractBean) |
| 232 | + .setAutoPrefixBean(abstractBean) |
| 233 | + .setCustomPrefixBean(abstractBean) |
222 | 234 | .build();
|
223 | 235 |
|
224 | 236 | Map<String, AttributeValue> itemMap = tableSchema.itemToMap(flattenedBeanImmutable, false);
|
225 |
| - assertThat(itemMap.size(), is(3)); |
| 237 | + assertThat(itemMap.size(), is(6)); |
226 | 238 | assertThat(itemMap, hasEntry("id", stringValue("id-value")));
|
227 | 239 | assertThat(itemMap, hasEntry("attribute1", stringValue("one")));
|
228 | 240 | assertThat(itemMap, hasEntry("attribute2", stringValue("two")));
|
| 241 | + assertThat(itemMap, hasEntry("prefix-attribute2", stringValue("two"))); |
| 242 | + assertThat(itemMap, hasEntry("autoPrefixBean.attribute2", stringValue("two"))); |
| 243 | + assertThat(itemMap, hasEntry("custom.attribute2", stringValue("two"))); |
229 | 244 | }
|
230 | 245 |
|
231 | 246 | @Test
|
232 | 247 | public void dynamoDbFlatten_correctlyFlattensImmutableAttributes() {
|
233 | 248 | ImmutableTableSchema<FlattenedImmutableImmutable> tableSchema =
|
234 | 249 | ImmutableTableSchema.create(FlattenedImmutableImmutable.class);
|
| 250 | + |
| 251 | + assertThat(tableSchema.attributeNames(), containsInAnyOrder("id", "attribute1", "attribute2", |
| 252 | + "prefix-attribute2", "autoPrefixImmutable.attribute2", "custom.attribute2")); |
| 253 | + |
235 | 254 | AbstractImmutable abstractImmutable = AbstractImmutable.builder().attribute2("two").build();
|
236 | 255 | FlattenedImmutableImmutable FlattenedImmutableImmutable =
|
237 | 256 | new FlattenedImmutableImmutable.Builder().setId("id-value")
|
238 | 257 | .setAttribute1("one")
|
239 | 258 | .setAbstractImmutable(abstractImmutable)
|
| 259 | + .setExplicitPrefixImmutable(abstractImmutable) |
| 260 | + .setAutoPrefixImmutable(abstractImmutable) |
| 261 | + .setCustomPrefixImmutable(abstractImmutable) |
240 | 262 | .build();
|
241 | 263 |
|
242 | 264 | Map<String, AttributeValue> itemMap = tableSchema.itemToMap(FlattenedImmutableImmutable, false);
|
243 |
| - assertThat(itemMap.size(), is(3)); |
| 265 | + assertThat(itemMap.size(), is(6)); |
244 | 266 | assertThat(itemMap, hasEntry("id", stringValue("id-value")));
|
245 | 267 | assertThat(itemMap, hasEntry("attribute1", stringValue("one")));
|
246 | 268 | assertThat(itemMap, hasEntry("attribute2", stringValue("two")));
|
| 269 | + assertThat(itemMap, hasEntry("prefix-attribute2", stringValue("two"))); |
| 270 | + assertThat(itemMap, hasEntry("autoPrefixImmutable.attribute2", stringValue("two"))); |
| 271 | + assertThat(itemMap, hasEntry("custom.attribute2", stringValue("two"))); |
| 272 | + } |
| 273 | + |
| 274 | + @Test |
| 275 | + public void dynamoDbFlatten_correctlyGetFlattenedBeanAttributes() { |
| 276 | + ImmutableTableSchema<FlattenedBeanImmutable> tableSchema = |
| 277 | + ImmutableTableSchema.create(FlattenedBeanImmutable.class); |
| 278 | + |
| 279 | + AbstractBean abstractBean = new AbstractBean(); |
| 280 | + abstractBean.setAttribute2("two"); |
| 281 | + AbstractBean explicitPrefixBean = new AbstractBean(); |
| 282 | + explicitPrefixBean.setAttribute2("three"); |
| 283 | + AbstractBean autoPrefixBean = new AbstractBean(); |
| 284 | + autoPrefixBean.setAttribute2("four"); |
| 285 | + AbstractBean customPrefixBean = new AbstractBean(); |
| 286 | + customPrefixBean.setAttribute2("five"); |
| 287 | + FlattenedBeanImmutable bean = new FlattenedBeanImmutable.Builder().setId("id-value") |
| 288 | + .setAttribute1("one") |
| 289 | + .setAbstractBean(abstractBean) |
| 290 | + .setExplicitPrefixBean(explicitPrefixBean) |
| 291 | + .setAutoPrefixBean(autoPrefixBean) |
| 292 | + .setCustomPrefixBean(customPrefixBean) |
| 293 | + .build(); |
| 294 | + |
| 295 | + assertThat(tableSchema.attributeValue(bean, "id"), equalTo(stringValue("id-value"))); |
| 296 | + assertThat(tableSchema.attributeValue(bean, "attribute1"), equalTo(stringValue("one"))); |
| 297 | + assertThat(tableSchema.attributeValue(bean, "attribute2"), equalTo(stringValue("two"))); |
| 298 | + assertThat(tableSchema.attributeValue(bean, "prefix-attribute2"), equalTo(stringValue("three"))); |
| 299 | + assertThat(tableSchema.attributeValue(bean, "autoPrefixBean.attribute2"), equalTo(stringValue("four"))); |
| 300 | + assertThat(tableSchema.attributeValue(bean, "custom.attribute2"), equalTo(stringValue("five"))); |
247 | 301 | }
|
248 | 302 |
|
249 | 303 | @Test
|
|
0 commit comments