|
1 | 1 | package io.crnk.core.engine.internal.document.mapper;
|
2 | 2 |
|
3 |
| -import java.net.URI; |
4 | 3 | import java.time.OffsetDateTime;
|
5 | 4 | import java.util.ArrayList;
|
6 | 5 | import java.util.Arrays;
|
|
17 | 16 | import com.fasterxml.jackson.databind.JsonNode;
|
18 | 17 | import com.fasterxml.jackson.databind.ObjectWriter;
|
19 | 18 | import com.fasterxml.jackson.databind.node.ObjectNode;
|
20 |
| -import com.fasterxml.jackson.databind.node.TextNode; |
21 | 19 | import io.crnk.core.engine.document.Document;
|
22 | 20 | import io.crnk.core.engine.document.ErrorData;
|
23 | 21 | import io.crnk.core.engine.document.Relationship;
|
|
27 | 25 | import io.crnk.core.mock.models.LazyTask;
|
28 | 26 | import io.crnk.core.mock.models.Project;
|
29 | 27 | import io.crnk.core.mock.models.Schedule;
|
| 28 | +import io.crnk.core.mock.models.SpecialTask; |
| 29 | +import io.crnk.core.mock.models.SuperTask; |
30 | 30 | import io.crnk.core.mock.models.Task;
|
31 | 31 | import io.crnk.core.queryspec.PathSpec;
|
32 | 32 | import io.crnk.core.queryspec.QuerySpec;
|
@@ -648,6 +648,29 @@ public void testAttributesSelection() {
|
648 | 648 | Assert.assertEquals("sample category", resource.getAttributes().get("category").asText());
|
649 | 649 | }
|
650 | 650 |
|
| 651 | + @Test |
| 652 | + public void testSupertypeAttributesSelection() { |
| 653 | + SpecialTask task = createSpecialTask(2, "sample task"); |
| 654 | + task.setEnd("next month"); |
| 655 | + JsonApiResponse response = new JsonApiResponse(); |
| 656 | + response.setEntity(task); |
| 657 | + |
| 658 | + QuerySpec querySpec = new QuerySpec(SpecialTask.class); |
| 659 | + querySpec.includeField(PathSpec.of("end")); |
| 660 | + final QuerySpec superQuerySpec = new QuerySpec(SuperTask.class); |
| 661 | + superQuerySpec.includeField(PathSpec.of("name")); |
| 662 | + querySpec.setNestedSpecs(Collections.singletonList(superQuerySpec)); |
| 663 | + |
| 664 | + Document document = mapper.toDocument(response, toAdapter(querySpec), mappingConfig).get(); |
| 665 | + Resource resource = document.getSingleData().get(); |
| 666 | + Assert.assertEquals("2", resource.getId()); |
| 667 | + Assert.assertEquals("specialTask", resource.getType()); |
| 668 | + Assert.assertNull(resource.getAttributes().get("category")); |
| 669 | + Assert.assertNull(resource.getAttributes().get("recurring")); |
| 670 | + Assert.assertEquals("sample task", resource.getAttributes().get("name").asText()); |
| 671 | + Assert.assertEquals("next month", resource.getAttributes().get("end").asText()); |
| 672 | + } |
| 673 | + |
651 | 674 | @Test
|
652 | 675 | public void testAttributesOrdering() {
|
653 | 676 | Task task = createTask(3, "sample task");
|
@@ -690,6 +713,13 @@ private LazyTask createLazyTask(long id) {
|
690 | 713 | return task;
|
691 | 714 | }
|
692 | 715 |
|
| 716 | + private SpecialTask createSpecialTask(long id, String name) { |
| 717 | + SpecialTask task = new SpecialTask(); |
| 718 | + task.setId(id); |
| 719 | + task.setName(name); |
| 720 | + return task; |
| 721 | + } |
| 722 | + |
693 | 723 | public static class TestLinksInformation implements LinksInformation {
|
694 | 724 |
|
695 | 725 | public Link value;
|
|
0 commit comments