ISIS-233: domainservice.serviceId testing of repr.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/c0e6f1d7 Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/c0e6f1d7 Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/c0e6f1d7 Branch: refs/heads/master Commit: c0e6f1d763c90720f30a2cd06191f5f70e88d315 Parents: cfe2b10 Author: Dan Haywood <[email protected]> Authored: Tue Mar 5 23:51:40 2013 +0000 Committer: Dan Haywood <[email protected]> Committed: Sat Apr 27 18:57:40 2013 +0100 ---------------------------------------------------------------------- ...ainServiceTest_req_queryarg_xrofollowlinks.java | 5 +- .../DomainServiceTest_resp_representation.java | 70 +++++++++++++-- .../tck/dom/busrules/BusRulesEntityRepository.java | 4 +- 3 files changed, 67 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/c0e6f1d7/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_req_queryarg_xrofollowlinks.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_req_queryarg_xrofollowlinks.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_req_queryarg_xrofollowlinks.java index 7e655d7..4021e98 100644 --- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_req_queryarg_xrofollowlinks.java +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_req_queryarg_xrofollowlinks.java @@ -90,7 +90,7 @@ public class DomainServiceTest_req_queryarg_xrofollowlinks { } @Test - public void toMembers() throws Exception { + public void toMembersDetails() throws Exception { final String href = givenHrefToService("WrapperValuedEntities"); final RestfulRequest request = client.createRequest(RestfulHttpMethod.GET, href).withArg(RequestParameter.FOLLOW_LINKS, "members.links[rel=%s]", Rel.DETAILS.getName()); @@ -139,7 +139,7 @@ public class DomainServiceTest_req_queryarg_xrofollowlinks { } @Test - public void multipleMembers() throws Exception { + public void toMultipleMembersDetails() throws Exception { final String href = givenHrefToService("WrapperValuedEntities"); @@ -164,7 +164,6 @@ public class DomainServiceTest_req_queryarg_xrofollowlinks { } - private String givenHrefToService(final String serviceId) throws JsonParseException, JsonMappingException, IOException { final DomainServiceResource resource = client.getDomainServiceResource(); http://git-wip-us.apache.org/repos/asf/isis/blob/c0e6f1d7/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_resp_representation.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_resp_representation.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_resp_representation.java index a58cfe4..fea89c7 100644 --- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_resp_representation.java +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainservice/serviceId/DomainServiceTest_resp_representation.java @@ -23,11 +23,13 @@ import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.a import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isArray; import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isLink; import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isMap; +import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; +import javax.ws.rs.HttpMethod; import javax.ws.rs.core.Response; import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation; @@ -40,6 +42,7 @@ import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectMe import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectRepresentation; import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainServiceResource; import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; +import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; @@ -125,23 +128,76 @@ public class DomainServiceTest_resp_representation { } - @Ignore("todo") + @Test - public void disabledAction() throws Exception { + public void visibleAndInvocableAction() throws Exception { + // given + final Response resp = resource.service("BusinessRulesEntities"); + + // when + final RestfulResponse<DomainObjectRepresentation> jsonResp = RestfulResponse.ofT(resp); + + // then + assertThat(jsonResp.getStatus(), is(HttpStatusCode.OK)); + final DomainObjectRepresentation repr = jsonResp.getEntity(); + + assertThat(repr, isMap()); + + final DomainObjectMemberRepresentation actionRepr = repr.getAction("visibleAndInvocableAction"); + assertThat(actionRepr, isMap()); + + assertThat(actionRepr.getDisabledReason(), is(nullValue())); + + final LinkRepresentation actionDetailsLink = actionRepr.getLinkWithRel(Rel.DETAILS); + assertThat(actionDetailsLink, isLink(this.client) + .rel(Rel.DETAILS) + .httpMethod(RestfulHttpMethod.GET) + .href(Matchers.endsWith(":39393/services/BusinessRulesEntities/actions/visibleAndInvocableAction")) + .returning(HttpStatusCode.OK)); + } + + + @Test + public void visibleButNotInvocableAction() throws Exception { - // has a disabledRead + // given + final Response resp = resource.service("BusinessRulesEntities"); + + // when + final RestfulResponse<DomainObjectRepresentation> jsonResp = RestfulResponse.ofT(resp); + + // then + assertThat(jsonResp.getStatus(), is(HttpStatusCode.OK)); + final DomainObjectRepresentation repr = jsonResp.getEntity(); + + final DomainObjectMemberRepresentation actionRepr = repr.getAction("visibleButNotInvocableAction"); + assertThat(actionRepr, isMap()); + assertThat(actionRepr.getDisabledReason(), is("Always disabled")); + + final LinkRepresentation actionDetailsLink = actionRepr.getLinkWithRel(Rel.DETAILS); + + // even though not invocable, still can traverse to its details page + assertThat(actionDetailsLink, isLink(this.client) + .href(Matchers.endsWith(":39393/services/BusinessRulesEntities/actions/visibleButNotInvocableAction")) + .returning(HttpStatusCode.OK)); } - @Ignore("todo") @Test - public void nonExistentAction() throws Exception { + public void invisibleAction() throws Exception { + // given + final Response resp = resource.service("BusinessRulesEntities"); - // eg... - // DomainObjectMemberRepresentation listMemberRepr = repr.getAction("foobar"); + // when + final RestfulResponse<DomainObjectRepresentation> jsonResp = RestfulResponse.ofT(resp); + + // then + assertThat(jsonResp.getStatus(), is(HttpStatusCode.OK)); + final DomainObjectRepresentation repr = jsonResp.getEntity(); + assertThat(repr.getAction("invisibleAction"), is(nullValue())); } http://git-wip-us.apache.org/repos/asf/isis/blob/c0e6f1d7/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/busrules/BusRulesEntityRepository.java ---------------------------------------------------------------------- diff --git a/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/busrules/BusRulesEntityRepository.java b/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/busrules/BusRulesEntityRepository.java index cc1a814..456f514 100644 --- a/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/busrules/BusRulesEntityRepository.java +++ b/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/busrules/BusRulesEntityRepository.java @@ -49,14 +49,14 @@ public class BusRulesEntityRepository extends AbstractEntityRepository<BusRulesE @ActionSemantics(Of.SAFE) @MemberOrder(sequence = "1") - public BusRulesEntity visibleAndInvokableAction(int id) { + public BusRulesEntity visibleAndInvocableAction(int id) { return this.findById(id); } @Disabled @ActionSemantics(Of.SAFE) @MemberOrder(sequence = "1") - public BusRulesEntity visibleButUninvokableAction(int id) { + public BusRulesEntity visibleButNotInvocableAction(int id) { return this.findById(id); }
