This is an automated email from the ASF dual-hosted git repository. danhaywood pushed a commit to branch CAUSEWAY-3661 in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 0bd57dbb44d7807a9f990e3d1eeb04bd29c5b921 Author: danhaywood <[email protected]> AuthorDate: Tue Mar 12 11:33:35 2024 +0000 CAUSEWAY-3661: can't reproduce, empty collection in RO returns a 200 rather than 404 --- ...sewayViewerRestfulObjectsIntegTestAbstract.java | 4 ++ ....collection_with_no_staff_members.approved.json | 25 +++++++++++ ...est.collection_with_staff_members.approved.json | 37 +++++++++++++++++ .../dept/Department_IntegTest.exists.approved.json | 30 +++++++------- .../test/scenarios/dept/Department_IntegTest.java | 48 ++++++++++++++++++++++ 5 files changed, 129 insertions(+), 15 deletions(-) diff --git a/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/CausewayViewerRestfulObjectsIntegTestAbstract.java b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/CausewayViewerRestfulObjectsIntegTestAbstract.java index b783b52b5b..42c1141185 100644 --- a/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/CausewayViewerRestfulObjectsIntegTestAbstract.java +++ b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/CausewayViewerRestfulObjectsIntegTestAbstract.java @@ -187,6 +187,10 @@ public abstract class CausewayViewerRestfulObjectsIntegTestAbstract { String prettyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectMapper.readTree(s)); if (bookmarkOptions == BookmarkOptions.SCRUB) { prettyJson = prettyJson.replaceAll(":\\d+/", ":NNN/"); + prettyJson = prettyJson.replaceAll(":\\d+\"", ":NNN\""); // "oid" : "university.dept.Department:33" ; "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department:33", + prettyJson = prettyJson.replaceAll("/\\d+/", "/NNN/"); + prettyJson = prettyJson.replaceAll("/\\d+\"", "/NNN\""); + prettyJson = prettyJson.replaceAll(": \"\\d+\"", ": \"NNN\""); // "instanceId" : "33", } return prettyJson; } catch (JsonProcessingException e) { diff --git a/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.collection_with_no_staff_members.approved.json b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.collection_with_no_staff_members.approved.json new file mode 100644 index 0000000000..b0ede153d8 --- /dev/null +++ b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.collection_with_no_staff_members.approved.json @@ -0,0 +1,25 @@ +{ + "id" : "staffMembers", + "memberType" : "collection", + "links" : [ { + "rel" : "self", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/collections/staffMembers", + "method" : "GET", + "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-collection\"" + }, { + "rel" : "up", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN", + "method" : "GET", + "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object\"", + "title" : "Untitled Department" + }, { + "rel" : "describedby", + "href" : "http://0.0.0.0:NNN/restful/domain-types/university.dept.Department/collections/staffMembers", + "method" : "GET", + "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/collection-description\"" + } ], + "extensions" : { + "collectionSemantics" : "list" + }, + "value" : [ ] +} \ No newline at end of file diff --git a/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.collection_with_staff_members.approved.json b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.collection_with_staff_members.approved.json new file mode 100644 index 0000000000..ef8ccac5fe --- /dev/null +++ b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.collection_with_staff_members.approved.json @@ -0,0 +1,37 @@ +{ + "id" : "staffMembers", + "memberType" : "collection", + "links" : [ { + "rel" : "self", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/collections/staffMembers", + "method" : "GET", + "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-collection\"" + }, { + "rel" : "up", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN", + "method" : "GET", + "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object\"", + "title" : "Untitled Department" + }, { + "rel" : "describedby", + "href" : "http://0.0.0.0:NNN/restful/domain-types/university.dept.Department/collections/staffMembers", + "method" : "GET", + "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/collection-description\"" + } ], + "extensions" : { + "collectionSemantics" : "list" + }, + "value" : [ { + "rel" : "urn:org.restfulobjects:rels/value", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.StaffMember/NNN", + "method" : "GET", + "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object\"", + "title" : "Untitled Staff Member" + }, { + "rel" : "urn:org.restfulobjects:rels/value", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.StaffMember/NNN", + "method" : "GET", + "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object\"", + "title" : "Untitled Staff Member" + } ] +} \ No newline at end of file diff --git a/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.exists.approved.json b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.exists.approved.json index 7d20e5c64f..a306b8cc69 100644 --- a/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.exists.approved.json +++ b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.exists.approved.json @@ -1,7 +1,7 @@ { "links" : [ { "rel" : "self", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object\"", "title" : "Untitled Department" @@ -12,42 +12,42 @@ "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/domain-type\"" }, { "rel" : "urn:org.apache.causeway.restfulobjects:rels/object-layout", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/object-layout", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/object-layout", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-layout-bs\"" }, { "rel" : "urn:org.apache.causeway.restfulobjects:rels/object-icon", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/object-icon", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/object-icon", "method" : "GET", "type" : "image/*" }, { "rel" : "urn:org.restfulobjects:rels/update", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department:17", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department:NNN", "method" : "PUT", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object\"", "arguments" : { } } ], "extensions" : { - "oid" : "university.dept.Department:17", + "oid" : "university.dept.Department:NNN", "isService" : false, "isPersistent" : true }, "title" : "Untitled Department", "domainType" : "university.dept.Department", - "instanceId" : "17", + "instanceId" : "NNN", "members" : { "deptHead" : { "id" : "deptHead", "memberType" : "property", "links" : [ { "rel" : "urn:org.restfulobjects:rels/details;property=\"deptHead\"", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/properties/deptHead", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/properties/deptHead", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-property\"" } ], "value" : { "rel" : "urn:org.restfulobjects:rels/value", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.DeptHead/23", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.DeptHead/NNN", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object\"", "title" : "Untitled Dept Head" @@ -58,7 +58,7 @@ "memberType" : "property", "links" : [ { "rel" : "urn:org.restfulobjects:rels/details;property=\"name\"", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/properties/name", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/properties/name", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-property\"" } ], @@ -73,7 +73,7 @@ "memberType" : "collection", "links" : [ { "rel" : "urn:org.restfulobjects:rels/details;collection=\"staffMembers\"", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/collections/staffMembers", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/collections/staffMembers", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-collection\"" } ] @@ -83,7 +83,7 @@ "memberType" : "action", "links" : [ { "rel" : "urn:org.restfulobjects:rels/details;action=\"changeName\"", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/actions/changeName", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/actions/changeName", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-action\"" } ] @@ -93,7 +93,7 @@ "memberType" : "action", "links" : [ { "rel" : "urn:org.restfulobjects:rels/details;action=\"changeDeptHead\"", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/actions/changeDeptHead", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/actions/changeDeptHead", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-action\"" } ] @@ -103,7 +103,7 @@ "memberType" : "action", "links" : [ { "rel" : "urn:org.restfulobjects:rels/details;action=\"addStaffMember\"", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/actions/addStaffMember", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/actions/addStaffMember", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-action\"" } ] @@ -113,7 +113,7 @@ "memberType" : "action", "links" : [ { "rel" : "urn:org.restfulobjects:rels/details;action=\"addStaffMembers\"", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/actions/addStaffMembers", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/actions/addStaffMembers", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-action\"" } ] @@ -123,7 +123,7 @@ "memberType" : "action", "links" : [ { "rel" : "urn:org.restfulobjects:rels/details;action=\"removeStaffMember\"", - "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/17/actions/removeStaffMember", + "href" : "http://0.0.0.0:NNN/restful/objects/university.dept.Department/NNN/actions/removeStaffMember", "method" : "GET", "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/object-action\"" } ] diff --git a/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.java b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.java index 343500ef13..1b1b2c585b 100644 --- a/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.java +++ b/viewers/restfulobjects/test/src/test/java/org/apache/causeway/viewer/restfulobjects/test/scenarios/dept/Department_IntegTest.java @@ -67,6 +67,54 @@ public class Department_IntegTest extends Abstract_IntegTest { Approvals.verify(entity, jsonOptions()); } + @Test + @UseReporter(DiffReporter.class) + public void collection_with_staff_members() { + + // given + Bookmark bookmark = transactionService.callTransactional(Propagation.REQUIRED, () -> { + Department classics = departmentRepository.findByName("Classics"); + return bookmarkService.bookmarkFor(classics).orElseThrow(); + }).valueAsNonNullElseFail(); + + Invocation.Builder request = restfulClient.request(String.format("/objects/%s/%s/collections/staffMembers", bookmark.getLogicalTypeName(), bookmark.getIdentifier())); + + // when + val response = request.get(); + + // then + val entity = response.readEntity(String.class); + + assertThat(response) + .extracting(Response::getStatus) + .isEqualTo(Response.Status.OK.getStatusCode()); + Approvals.verify(entity, jsonOptions()); + } + + @Test + @UseReporter(DiffReporter.class) + public void collection_with_no_staff_members() { + + // given + Bookmark bookmark = transactionService.callTransactional(Propagation.REQUIRED, () -> { + Department classics = departmentRepository.findByName("Textiles"); + return bookmarkService.bookmarkFor(classics).orElseThrow(); + }).valueAsNonNullElseFail(); + + Invocation.Builder request = restfulClient.request(String.format("/objects/%s/%s/collections/staffMembers", bookmark.getLogicalTypeName(), bookmark.getIdentifier())); + + // when + val response = request.get(); + + // then + val entity = response.readEntity(String.class); + + assertThat(response) + .extracting(Response::getStatus) + .isEqualTo(Response.Status.OK.getStatusCode()); + Approvals.verify(entity, jsonOptions()); + } + @Test @UseReporter(DiffReporter.class) public void does_not_exist() {
