http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/version/VersionResourceTest_root_response_representation.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/version/VersionResourceTest_root_response_representation.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/version/VersionResourceTest_root_response_representation.java new file mode 100644 index 0000000..4dfa56e --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/version/VersionResourceTest_root_response_representation.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.isis.viewer.restfulobjects.tck.version; + +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.assertThat; +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.endsWith; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status.Family; + +import org.apache.isis.core.webserver.WebServer; +import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.Rel; +import org.apache.isis.viewer.restfulobjects.applib.RepresentationType; +import org.apache.isis.viewer.restfulobjects.applib.RestfulHttpMethod; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.HttpStatusCode; +import org.apache.isis.viewer.restfulobjects.applib.version.VersionRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.version.VersionResource; +import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class VersionResourceTest_root_response_representation { + + @Rule + public IsisWebServerRule webServerRule = new IsisWebServerRule(); + + private RestfulClient client; + private VersionResource resource; + + @Before + public void setUp() throws Exception { + final WebServer webServer = webServerRule.getWebServer(); + client = new RestfulClient(webServer.getBase()); + + resource = client.getVersionResource(); + } + + @Test + public void representation() throws Exception { + + // given + final Response servicesResp = resource.version(); + + // when + final RestfulResponse<VersionRepresentation> restfulResponse = RestfulResponse.ofT(servicesResp); + assertThat(restfulResponse.getStatus().getFamily(), is(Family.SUCCESSFUL)); + + // then + assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK)); + + final VersionRepresentation repr = restfulResponse.getEntity(); + assertThat(repr, is(not(nullValue()))); + assertThat(repr, isMap()); + + assertThat(repr.getSelf(), isLink(client) + .rel(Rel.SELF) + .href(endsWith(":39393/version")) + .httpMethod(RestfulHttpMethod.GET) + .type(RepresentationType.VERSION.getMediaType()) + .returning(HttpStatusCode.OK) + ); + assertThat(repr.getUp(), isLink(client) + .rel(Rel.UP) + .href(endsWith(":39393/")) + .httpMethod(RestfulHttpMethod.GET) + .type(RepresentationType.HOME_PAGE.getMediaType()) + .returning(HttpStatusCode.OK) + ); + + assertThat(repr.getString("specVersion"), is("1.0.0")); + assertThat(repr.getString("implVersion"), is(not(nullValue()))); + //assertThat(repr.getString("implVersion"), is(not("UNKNOWN"))); + + final JsonRepresentation optionalCapbilitiesRepr = repr.getOptionalCapabilities(); + assertThat(optionalCapbilitiesRepr, isMap()); + + assertThat(optionalCapbilitiesRepr.getString("blobsClobs"), is("yes")); + assertThat(optionalCapbilitiesRepr.getString("deleteObjects"), is("yes")); + assertThat(optionalCapbilitiesRepr.getString("domainModel"), is("formal")); + assertThat(optionalCapbilitiesRepr.getString("validateOnly"), is("yes")); + assertThat(optionalCapbilitiesRepr.getString("protoPersistentObjects"), is("yes")); + + assertThat(repr.getLinks(), isArray()); + assertThat(repr.getExtensions(), is(not(nullValue()))); + } +}
http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainobject/DomainObjectResourceTest_instanceid_get_response_header_cacheControl.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainobject/DomainObjectResourceTest_instanceid_get_response_header_cacheControl.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainobject/DomainObjectResourceTest_instanceid_get_response_header_cacheControl.java new file mode 100644 index 0000000..8e59c83 --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainobject/DomainObjectResourceTest_instanceid_get_response_header_cacheControl.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainobject; + +import org.apache.isis.core.webserver.WebServer; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; +import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +public class DomainObjectResourceTest_instanceid_get_response_header_cacheControl { + + @Rule + public IsisWebServerRule webServerRule = new IsisWebServerRule(); + + protected RestfulClient client; + + @Before + public void setUp() throws Exception { + final WebServer webServer = webServerRule.getWebServer(); + client = new RestfulClient(webServer.getBase()); + } + + @Ignore + @Test + public void noCaching() throws Exception { + + } + + @Ignore + @Test + public void shortTermCaching() throws Exception { + + } + + @Ignore + @Test + public void longTermCaching() throws Exception { + + } + + +} http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainobject/DomainObjectResourceTest_instanceid_get_response_representation.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainobject/DomainObjectResourceTest_instanceid_get_response_representation.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainobject/DomainObjectResourceTest_instanceid_get_response_representation.java new file mode 100644 index 0000000..627a009 --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainobject/DomainObjectResourceTest_instanceid_get_response_representation.java @@ -0,0 +1,401 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainobject; + +import static org.apache.isis.core.commons.matchers.IsisMatchers.matches; +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.assertThat; +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isLink; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status.Family; + +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import org.apache.isis.core.tck.dom.refs.BidirWithSetChildEntity; +import org.apache.isis.core.tck.dom.scalars.ApplibValuedEntity; +import org.apache.isis.core.tck.dom.scalars.ApplibValuedEntityRepository; +import org.apache.isis.core.webserver.WebServer; +import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.Rel; +import org.apache.isis.viewer.restfulobjects.applib.RestfulHttpMethod; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulRequest; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ActionResultRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectResource; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ObjectActionRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ObjectPropertyRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ScalarValueRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ActionResultRepresentation.ResultType; +import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; + +public class DomainObjectResourceTest_instanceid_get_response_representation { + + @Rule + public IsisWebServerRule webServerRule = new IsisWebServerRule(); + + protected RestfulClient client; + + @Before + public void setUp() throws Exception { + final WebServer webServer = webServerRule.getWebServer(); + client = new RestfulClient(webServer.getBase()); + } + + @Test + public void returnsDomainObjectRepresentation() throws Exception { + + // given + final DomainObjectResource domainObjectResource = client.getDomainObjectResource(); + + // when + final Response domainObjectResp = domainObjectResource.object("OID","6"); + final RestfulResponse<DomainObjectRepresentation> domainObjectJsonResp = RestfulResponse.ofT(domainObjectResp); + assertThat(domainObjectJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL)); + + // then + final DomainObjectRepresentation domainObjectRepr = domainObjectJsonResp.getEntity(); + assertThat(domainObjectRepr, is(not(nullValue()))); + } + + @Test + public void domainObjectRepresentationForPersistentObject_hasSelfAndOid() throws Exception { + + // given, when + final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID","32"); + + // then + final LinkRepresentation self = domainObjectRepr.getSelf(); + assertThat(self, isLink().rel(Rel.SELF).href(matches(".+objects/OID/32")).httpMethod(RestfulHttpMethod.GET).type(MediaType.APPLICATION_JSON_TYPE).typeParameter("profile", "urn:org.restfulobjects/domainobject")); + assertThat(domainObjectRepr.getLinkWithRel(Rel.DESCRIBEDBY), isLink().href(matches(".+" + BidirWithSetChildEntity.class.getName())).httpMethod(RestfulHttpMethod.GET).type(MediaType.APPLICATION_JSON_TYPE).typeParameter("profile", "urn:org.restfulobjects/domaintype")); + + assertThat(domainObjectRepr.getTitle(), is("parent 4 - child 2")); + assertThat(domainObjectRepr.getOid(), is("OID:32")); + + // no icon + final LinkRepresentation selfIcon = domainObjectRepr.getLinkWithRel(Rel.ICON); + assertThat(selfIcon, is(nullValue())); + } + + @Test + public void domainObjectRepresentationForTransient_hasNoSelf_andHasNoOid() throws Exception { + + // given, when + final RestfulRequest request = this.client.createRequest(RestfulHttpMethod.POST, "services/simples/actions/newTransientEntity/invoke"); + final RestfulResponse<ActionResultRepresentation> response = request.executeT(); + final ActionResultRepresentation actionResultRepr = response.getEntity(); + assertThat(actionResultRepr.getResultType(), is(ResultType.DOMAIN_OBJECT)); + assertThat(actionResultRepr.getResult(), is(not(nullValue()))); + + final DomainObjectRepresentation domainObjectRepr = actionResultRepr.getResult().as(DomainObjectRepresentation.class); + + // then + final LinkRepresentation self = domainObjectRepr.getSelf(); + assertThat(self, is(nullValue())); + + assertThat(domainObjectRepr.getOid(), is(nullValue())); + } + + @Test + public void domainObjectRepresentation_hasTitle() throws Exception { + + // given, when + final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID","32"); + + // then + assertThat(domainObjectRepr.getTitle(), is("parent 4 - child 2")); + } + + @Test + public void domainObjectRepresentation_hasDescribedByLink() throws Exception { + + // given, when + final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID","32"); + + // then + assertThat(domainObjectRepr.getLinkWithRel(Rel.DESCRIBEDBY), isLink().href(matches(".+" + BidirWithSetChildEntity.class.getName())).httpMethod(RestfulHttpMethod.GET).type(MediaType.APPLICATION_JSON_TYPE).typeParameter("profile", "urn:org.restfulobjects/domaintype")); + } + + @Test + public void domainObjectRepresentation_noIcon() throws Exception { + + // given, when + final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID","32"); + + // then + final LinkRepresentation selfIcon = domainObjectRepr.getLinkWithRel(Rel.ICON); + assertThat(selfIcon, is(nullValue())); + } + + @Ignore("TODO") + @Test + public void domainObjectWithIcon() throws Exception { + + // given, when + final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID","xxx"); + + // icon + final LinkRepresentation selfIcon = domainObjectRepr.getLinkWithRel(Rel.ICON); + assertThat(selfIcon, isLink().href(matches(".+" + "/images/" + "null\\.png")).httpMethod(RestfulHttpMethod.GET)); + + } + + @Test + public void domainObjectRepresentationContent_Properties() throws Exception { + + // given, when + final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID","32"); + final LinkRepresentation self = domainObjectRepr.getSelf(); + + // then properties + final JsonRepresentation properties = domainObjectRepr.getProperties(); + assertThat(properties.size(), is(2)); + + // property ('name') + final JsonRepresentation nameProperty = properties.getRepresentation("[id=name]"); + assertThat(nameProperty.getString("memberType"), is("property")); + assertThat(nameProperty.getString("value"), is("child 2")); + assertThat(nameProperty.getString("disabledReason"), is(nullValue())); + + final LinkRepresentation namePropertyDetails = nameProperty.getLink("links[rel=details]"); + assertThat(namePropertyDetails, isLink().rel("details").href(self.getHref() + "/properties/name").httpMethod(RestfulHttpMethod.GET)); + + } + + @Ignore("todo") + @Test + public void domainObjectRepresentationContent_Collections() throws Exception { + + // given, when + final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID","32"); + + // then collections + + } + + @Ignore("TODO") + @Test + public void domainObjectRepresentationContent() throws Exception { + + // given, when + final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID","32"); + final LinkRepresentation self = domainObjectRepr.getSelf(); + + // then actions + final JsonRepresentation actions = domainObjectRepr.getActions(); + assertThat(actions.size(), is(2)); + + final JsonRepresentation listAction = actions.getRepresentation("list"); + assertThat(listAction.getString("memberType"), is("action")); + assertThat(listAction.getString("actionId"), is("list")); + assertThat(listAction.getString("actionType"), is("USER")); + assertThat(listAction.getInt("numParameters"), is(0)); + + final LinkRepresentation listActionType = listAction.getLink("type"); + assertThat(listActionType.getRel(), is("type")); + assertThat(listActionType.getHref(), matches(".+vnd\\.list\\+json")); + assertThat(listActionType.getHttpMethod(), is(RestfulHttpMethod.GET)); + + final LinkRepresentation listActionDetails = listAction.getLink("details"); + assertThat(listActionDetails.getRel(), is("action")); + assertThat(listActionDetails.getHref(), is(self.getHref() + "/actions/list")); + assertThat(listActionDetails.getHttpMethod(), is(RestfulHttpMethod.GET)); + + final JsonRepresentation newEntityAction = actions.getRepresentation("newEntity"); + assertThat(newEntityAction.getString("memberType"), is("action")); + assertThat(newEntityAction.getString("actionType"), is("USER")); + assertThat(newEntityAction.getInt("numParameters"), is(0)); + + final LinkRepresentation newEntityActionType = newEntityAction.getLink("type"); + assertThat(newEntityActionType.getRel(), is("type")); + assertThat(newEntityActionType.getHref(), matches(".+vnd\\." + ApplibValuedEntity.class.getName() + "\\+json")); + assertThat(newEntityActionType.getHttpMethod(), is(RestfulHttpMethod.GET)); + + final LinkRepresentation newEntityActionDetails = newEntityAction.getLink("details"); + assertThat(newEntityActionDetails.getRel(), is("action")); + assertThat(newEntityActionDetails.getHref(), is(self.getHref() + "/actions/newEntity")); + assertThat(newEntityActionDetails.getHttpMethod(), is(RestfulHttpMethod.GET)); + } + + @Ignore("TODO") + @Test + public void domainObjectWithDisabledMembers() throws Exception { + + // given, when + final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID","xxx"); + + // property ('name') + final JsonRepresentation properties = domainObjectRepr.getProperties(); + final JsonRepresentation nameProperty = properties.getRepresentation("name"); + assertThat(nameProperty.getString("disabledReason"), is(not(nullValue()))); + } + + @Ignore("to get working again") + @Test + public void propertyDetails() throws Exception { + // given + final DomainObjectResource domainObjectResource = client.getDomainObjectResource(); + + // when + final Response idPropertyResp = domainObjectResource.propertyDetails("OID","1", "id"); + final RestfulResponse<ObjectPropertyRepresentation> idPropertyJsonResp = RestfulResponse.ofT(idPropertyResp); + assertThat(idPropertyJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL)); + + // then + final ObjectPropertyRepresentation propertyDetailsRepr = idPropertyJsonResp.getEntity(); + + // _self.link + final LinkRepresentation selfLink = propertyDetailsRepr.getLink("_self.link"); + assertThat(selfLink.getRel(), is("member")); + assertThat(selfLink.getHref(), matches(".+objects/OID:1/properties/id")); + assertThat(selfLink.getHttpMethod(), is(RestfulHttpMethod.GET)); + + // _self.object + final LinkRepresentation selfObject = propertyDetailsRepr.getLink("_self.object"); + assertThat(selfObject.getRel(), is("object")); + assertThat(selfObject.getHref(), matches(".+objects/OID:1")); + assertThat(selfObject.getHttpMethod(), is(RestfulHttpMethod.GET)); + + // type + final LinkRepresentation type = propertyDetailsRepr.getLink("type"); + assertThat(type.getRel(), is("type")); + assertThat(type.getHref(), matches(".+vnd\\.string\\+json")); + assertThat(type.getHttpMethod(), is(RestfulHttpMethod.GET)); + + assertThat(propertyDetailsRepr.getString("memberType"), is("property")); + assertThat(propertyDetailsRepr.getString("value"), is(ApplibValuedEntityRepository.class.getName())); + assertThat(propertyDetailsRepr.getString("disabledReason"), is(not(nullValue()))); + } + + @Ignore("to get working again") + @Test + public void actionPrompt() throws Exception { + // given + final DomainObjectResource domainObjectResource = client.getDomainObjectResource(); + + // when + final Response actionPromptResp = domainObjectResource.actionPrompt("OID","1", "list"); + final RestfulResponse<ObjectActionRepresentation> actionPromptJsonResp = RestfulResponse.ofT(actionPromptResp); + assertThat(actionPromptJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL)); + + // then + final ObjectActionRepresentation actionPromptRepr = actionPromptJsonResp.getEntity(); + + // _self.link + final LinkRepresentation selfLink = actionPromptRepr.getLink("_self.link"); + assertThat(selfLink.getRel(), is("member")); + assertThat(selfLink.getHref(), matches(".+objects/OID:1/actions/list")); + assertThat(selfLink.getHttpMethod(), is(RestfulHttpMethod.GET)); + + // _self.object + final LinkRepresentation selfObject = actionPromptRepr.getLink("_self.object"); + assertThat(selfObject.getRel(), is("object")); + assertThat(selfObject.getHref(), matches(".+objects/OID:1")); + assertThat(selfObject.getHttpMethod(), is(RestfulHttpMethod.GET)); + + // type + final LinkRepresentation type = actionPromptRepr.getLink("type"); + assertThat(type.getRel(), is("type")); + assertThat(type.getHref(), matches(".+vnd\\.list\\+json")); + assertThat(type.getHttpMethod(), is(RestfulHttpMethod.GET)); + + assertThat(actionPromptRepr.getString("memberType"), is("action")); + assertThat(actionPromptRepr.getString("actionType"), is("USER")); + assertThat(actionPromptRepr.getInt("numParameters"), is(0)); + assertThat(actionPromptRepr.getArray("parameters").size(), is(0)); + + final LinkRepresentation invokeLink = actionPromptRepr.getLink("invoke"); + assertThat(invokeLink.getRel(), is("invoke")); + assertThat(invokeLink.getHref(), matches(".+objects/OID:1/actions/list/invoke")); + assertThat(invokeLink.getHttpMethod(), is(RestfulHttpMethod.POST)); + assertThat(invokeLink.getArguments(), is(not(nullValue()))); + assertThat(invokeLink.getArguments().isArray(), is(true)); + assertThat(invokeLink.getArguments().size(), is(0)); + } + + @Ignore("TODO") + @Test + public void collectionDetails() throws Exception { + fail(); + } + + @Ignore("to get working again") + @Test + public void actionPostInvoke_returningList() throws Exception { + + // given + final DomainObjectResource domainObjectResource = client.getDomainObjectResource(); + + final JsonRepresentation body = JsonRepresentation.newArray(); + + // when + final Response actionInvokeResp = domainObjectResource.invokeAction("OID","1", "list", body.asInputStream()); + final RestfulResponse<ScalarValueRepresentation> actionInvokeJsonResp = RestfulResponse.ofT(actionInvokeResp); + assertThat(actionInvokeJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL)); + + // then + final ScalarValueRepresentation actionInvokeRepr = actionInvokeJsonResp.getEntity(); + assertThat(actionInvokeRepr.isArray(), is(true)); + assertThat(actionInvokeRepr.size(), is(5)); + + final JsonRepresentation domainObjectRefRepr = actionInvokeRepr.arrayGet(0); + + assertThat(domainObjectRefRepr, is(not(nullValue()))); + assertThat(domainObjectRefRepr.getString("title"), is("Untitled Applib Values Entity")); // TODO + + final LinkRepresentation domainObjectLink = domainObjectRefRepr.getLink("link"); + assertThat(domainObjectLink.getRel(), is("object")); + assertThat(domainObjectLink.getHref(), matches("http://localhost:\\d+/objects/OID:7")); + + final LinkRepresentation domainObjectTypeLink = domainObjectRefRepr.getLink("type"); + assertThat(domainObjectTypeLink.getRel(), is("type")); + assertThat(domainObjectTypeLink.getHref(), matches("http://localhost:\\d+/types/application/vnd." + org.apache.isis.core.tck.dom.scalars.ApplibValuedEntity.class.getName() + "\\+json")); + + final LinkRepresentation domainObjectIconLink = domainObjectRefRepr.getLink("icon"); + assertThat(domainObjectIconLink.getRel(), is("icon")); + assertThat(domainObjectIconLink.getHref(), matches("http://localhost:\\d+/images/null.png")); // TODO + } + + private DomainObjectRepresentation givenDomainObjectRepresentationFor(final String domainType, String instanceId) throws JsonParseException, JsonMappingException, IOException { + final DomainObjectResource domainObjectResource = client.getDomainObjectResource(); + + final Response domainObjectResp = domainObjectResource.object(domainType, instanceId); + final RestfulResponse<DomainObjectRepresentation> domainObjectJsonResp = RestfulResponse.ofT(domainObjectResp); + assertThat(domainObjectJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL)); + + final DomainObjectRepresentation domainObjectRepr = domainObjectJsonResp.getEntity(); + return domainObjectRepr; + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction.java new file mode 100644 index 0000000..dceab09 --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction.java @@ -0,0 +1,265 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +import java.io.IOException; + +import javax.ws.rs.core.Response; + +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import org.apache.isis.core.webserver.WebServer; +import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.RestfulHttpMethod; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulRequest; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulRequest.RequestParameter; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.HttpStatusCode; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainServiceResource; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ListRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ObjectActionRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ScalarValueRepresentation; +import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; + +public class DomainServiceResourceTest_serviceId_invokeAction { + + @Rule + public IsisWebServerRule webServerRule = new IsisWebServerRule(); + + private RestfulClient client; + + @SuppressWarnings("unused") + private DomainServiceResource resource; + + @Before + public void setUp() throws Exception { + final WebServer webServer = webServerRule.getWebServer(); + client = new RestfulClient(webServer.getBase()); + + resource = client.getDomainServiceResource(); + } + + @Ignore("TODO - fix broken test resulting from introduction of actionresult repr") + @Test + public void invokeQueryOnly_noArg_usingClientFollow() throws Exception { + + // given + final JsonRepresentation givenAction = givenAction("simples", "list"); + final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class); + + // when + final LinkRepresentation invokeLink = actionRepr.getInvoke(); + + // then + assertThat(invokeLink, is(not(nullValue()))); + final RestfulResponse<ListRepresentation> restfulResponse = client.followT(invokeLink); + final ListRepresentation listRepr = restfulResponse.getEntity(); + + assertThat(listRepr.getValue().size(), is(5)); + } + + @Ignore("TODO - fix broken test resulting from introduction of actionresult repr") + @Test + public void invokeIdempotent_withArgs_usingClientFollow() throws Exception { + + // given action + final JsonRepresentation givenAction = givenAction("simples", "newPersistentEntity"); + final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class); + + // when + final LinkRepresentation invokeLink = actionRepr.getInvoke(); + + // then + assertThat(invokeLink, is(not(nullValue()))); + + final JsonRepresentation args = invokeLink.getArguments(); + assertThat(args.size(), is(2)); + assertThat(args.mapHas("name"), is(true)); + assertThat(args.mapHas("flag"), is(true)); + + // when + args.mapPut("name", "New Name"); + args.mapPut("flag", true); + final RestfulResponse<DomainObjectRepresentation> restfulResponse = client.followT(invokeLink, args); + + // then + final DomainObjectRepresentation objectRepr = restfulResponse.getEntity(); + + assertThat(objectRepr.getProperty("name").getString("value"), is("New Name")); + assertThat(objectRepr.getProperty("flag").getBoolean("value"), is(true)); + } + + @Ignore("TODO - fix broken test resulting from introduction of actionresult repr") + @Test + public void invoke_returningScalar_withReferenceArgs_usingClientFollow() throws Exception { + + // given action + final JsonRepresentation givenAction = givenAction("simples", "count"); + final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class); + + // when + final LinkRepresentation invokeLink = actionRepr.getInvoke(); + + // then + assertThat(invokeLink, is(not(nullValue()))); + final JsonRepresentation args = invokeLink.getArguments(); + assertThat(args.size(), is(0)); + + // when + final RestfulResponse<ScalarValueRepresentation> restfulResponse = client.followT(invokeLink, args); + + // then + final ScalarValueRepresentation objectRepr = restfulResponse.getEntity(); + + assertThat(objectRepr.getValue().asInt(), is(6)); + } + + @Ignore("TODO - fix broken test resulting from introduction of actionresult repr") + @Test + public void invokeNonIdempotent_returningVoid_withReferenceArgs_usingClientFollow() throws Exception { + + // given simple entity with 'flag' property set to true + final LinkRepresentation linkToSimpleEntity = givenLinkToSimpleEntity(0); + final RestfulResponse<DomainObjectRepresentation> restfulResponseBefore = client.followT(linkToSimpleEntity); + final DomainObjectRepresentation simpleEntityBefore = restfulResponseBefore.getEntity(); + final Boolean before = simpleEntityBefore.getProperty("flag").getBoolean("value"); + + // and given 'toggle' action on repo + final JsonRepresentation givenAction = givenAction("simples", "toggle"); + final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class); + + // when + final LinkRepresentation invokeLink = actionRepr.getInvoke(); + + // then + assertThat(invokeLink, is(not(nullValue()))); + + final JsonRepresentation args = invokeLink.getArguments(); + assertThat(args.size(), is(1)); + assertThat(args.mapHas("object"), is(true)); + + // when + args.mapPut("object", linkToSimpleEntity); + final RestfulResponse<JsonRepresentation> restfulResponse = client.followT(invokeLink, args); + + // then + assertThat(restfulResponse.getStatus(), is(HttpStatusCode.NO_CONTENT)); + + // and then simple entity 'flag' property set to false + final RestfulResponse<DomainObjectRepresentation> restfulResponseAfter = client.followT(linkToSimpleEntity); + final DomainObjectRepresentation simpleEntityAfter = restfulResponseAfter.getEntity(); + + final Boolean after = simpleEntityAfter.getProperty("flag").getBoolean("value"); + assertThat(after, is(!before)); // ie has been toggled + } + + @org.junit.Ignore("up to here") + @Test + public void invoke_withAllBuiltInArgs_usingClientFollow() throws Exception { + + // given simple entity with 'flag' property set to true + final LinkRepresentation linkToSimpleEntity = givenLinkToSimpleEntity(0); + + // given + final JsonRepresentation givenAction = givenAction("simples", "update"); + final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class); + + // when + final LinkRepresentation invokeLink = actionRepr.getInvoke(); + + // then + assertThat(invokeLink, is(not(nullValue()))); + + final JsonRepresentation args = invokeLink.getArguments(); + assertThat(args.size(), is(0)); + assertThat(args.mapHas("object"), is(true)); + assertThat(args.mapHas("name"), is(true)); + assertThat(args.mapHas("flag"), is(true)); + assertThat(args.mapHas("Boolean"), is(true)); + assertThat(args.mapHas("int"), is(true)); + assertThat(args.mapHas("integer"), is(true)); + assertThat(args.mapHas("long1"), is(true)); + assertThat(args.mapHas("long2"), is(true)); + assertThat(args.mapHas("double1"), is(true)); + assertThat(args.mapHas("double2"), is(true)); + assertThat(args.mapHas("bigInteger"), is(true)); + assertThat(args.mapHas("bigDecimal"), is(true)); + + // when + args.mapPut("name", "New Name"); + args.mapPut("flag", true); + final RestfulResponse<DomainObjectRepresentation> restfulResponse = client.followT(invokeLink, args); + + // then + final DomainObjectRepresentation objectRepr = restfulResponse.getEntity(); + + assertThat(objectRepr.getRepresentation("members[propertyId=%s].value", "name").asString(), is("New Name")); + assertThat(objectRepr.getRepresentation("members[propertyId=%s].value", "flag").asBoolean(), is(true)); + } + + private JsonRepresentation givenAction(final String serviceId, final String actionId) throws JsonParseException, JsonMappingException, IOException { + final String href = givenHrefToService(serviceId); + + final RestfulRequest request = client.createRequest(RestfulHttpMethod.GET, href).withArg(RequestParameter.FOLLOW_LINKS, "members[id=%s].links[rel=details]", actionId); + final RestfulResponse<DomainObjectRepresentation> restfulResponse = request.executeT(); + + assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK)); + final DomainObjectRepresentation repr = restfulResponse.getEntity(); + + final JsonRepresentation actionLinkRepr = repr.getAction(actionId); + return actionLinkRepr.getRepresentation("links[rel=details].value"); + } + + private String givenHrefToService(final String serviceId) throws JsonParseException, JsonMappingException, IOException { + final DomainServiceResource resource = client.getDomainServiceResource(); + final Response response = resource.services(); + final ListRepresentation services = RestfulResponse.<ListRepresentation> ofT(response).getEntity(); + + return services.getRepresentation("values[id=%s]", serviceId).asLink().getHref(); + } + + private LinkRepresentation givenLinkToSimpleEntity(final int num) throws JsonParseException, JsonMappingException, IOException, Exception { + // given + final JsonRepresentation givenAction = givenAction("simples", "list"); + final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class); + + // when + final LinkRepresentation invokeLink = actionRepr.getInvoke(); + + // then + final RestfulResponse<ListRepresentation> restfulResponse = client.followT(invokeLink); + final ListRepresentation listRepr = restfulResponse.getEntity(); + + return listRepr.getValue().arrayGet(num).asLink(); + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsList.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsList.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsList.java new file mode 100644 index 0000000..43f26b2 --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsList.java @@ -0,0 +1,13 @@ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice; + +import org.junit.Ignore; +import org.junit.Test; + +public class DomainServiceResourceTest_serviceId_invokeAction_returnsList { + + @Ignore + @Test + public void todo() throws Exception { + + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsObject.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsObject.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsObject.java new file mode 100644 index 0000000..7577d0d --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsObject.java @@ -0,0 +1,13 @@ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice; + +import org.junit.Ignore; +import org.junit.Test; + +public class DomainServiceResourceTest_serviceId_invokeAction_returnsObject { + + @Ignore + @Test + public void todo() throws Exception { + + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsScalar.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsScalar.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsScalar.java new file mode 100644 index 0000000..988ec19 --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsScalar.java @@ -0,0 +1,13 @@ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice; + +import org.junit.Ignore; +import org.junit.Test; + +public class DomainServiceResourceTest_serviceId_invokeAction_returnsScalar { + + @Ignore + @Test + public void todo() throws Exception { + + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsVoid.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsVoid.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsVoid.java new file mode 100644 index 0000000..8f4f9db --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_returnsVoid.java @@ -0,0 +1,13 @@ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice; + +import org.junit.Ignore; +import org.junit.Test; + +public class DomainServiceResourceTest_serviceId_invokeAction_returnsVoid { + + @Ignore + @Test + public void todo() throws Exception { + + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_throwsError.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_throwsError.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_throwsError.java new file mode 100644 index 0000000..72688ec --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/DomainServiceResourceTest_serviceId_invokeAction_throwsError.java @@ -0,0 +1,13 @@ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice; + +import org.junit.Ignore; +import org.junit.Test; + +public class DomainServiceResourceTest_serviceId_invokeAction_throwsError { + + @Ignore + @Test + public void todo() throws Exception { + + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/objectsoftype/ObjectsOfTypeResourceTest_domainTypeId_post.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/objectsoftype/ObjectsOfTypeResourceTest_domainTypeId_post.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/objectsoftype/ObjectsOfTypeResourceTest_domainTypeId_post.java new file mode 100644 index 0000000..7ceecd3 --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/objectsoftype/ObjectsOfTypeResourceTest_domainTypeId_post.java @@ -0,0 +1,13 @@ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.objectsoftype; + +import org.junit.Ignore; +import org.junit.Test; + +public class ObjectsOfTypeResourceTest_domainTypeId_post { + + @Ignore + @Test + public void todo() throws Exception { + + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/1b9a2a74/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/stories/UserStoryTest.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/stories/UserStoryTest.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/stories/UserStoryTest.java new file mode 100644 index 0000000..5d9892c --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/stories/UserStoryTest.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.isis.viewer.restfulobjects.tck.zzztodo.stories; + +import static org.apache.isis.core.commons.matchers.IsisMatchers.matches; +import static org.junit.Assert.assertThat; + +import javax.ws.rs.core.Response; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import org.apache.isis.core.webserver.WebServer; +import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.client.RepresentationWalker; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; +import org.apache.isis.viewer.restfulobjects.applib.homepage.HomePageResource; +import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; + +public class UserStoryTest { + + @Rule + public IsisWebServerRule webServerRule = new IsisWebServerRule(); + + protected RestfulClient client; + + @Before + public void setUp() throws Exception { + final WebServer webServer = webServerRule.getWebServer(); + client = new RestfulClient(webServer.getBase()); + } + + @Ignore("to get working again") + @Test + public void walkResources() throws Exception { + + // given a response for an initial resource + final HomePageResource homePageResource = client.getHomePageResource(); + final Response homePageResp = homePageResource.homePage(); + + // and given a walker starting from this response + final RepresentationWalker walker = client.createWalker(homePageResp); + + // when walk the home pages' 'services' link + walker.walk("services"); + + // and when locate the ApplibValues repo and walk the its 'object' link + walker.walk("values[title=ApplibValues].links[rel=object]"); + + // and when locate the AppLibValues repo's "newEntity" action and walk + // to its details + walker.walk("values[memberType=action].details"); + + // and when find the invoke body for the "newEntity" action and then + // walk the action using the body + final JsonRepresentation newEntityActionDetails = walker.getEntity(); + final JsonRepresentation newEntityActionInvokeBody = newEntityActionDetails.getArray("invoke.body"); + walker.walk("invoke", newEntityActionInvokeBody); + + // and when walk the link to the returned object + walker.walk("link"); + + // then the returned object is created with its OID + final JsonRepresentation newEntityDomainObject = walker.getEntity(); + assertThat(newEntityDomainObject.getString("_self.link.href"), matches(".+/objects/OID:[\\d]+$")); + } + +}
