You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/03/04 22:58:54 UTC

[31/35] ISIS-233-ro: more on domainservice.serviceId

http://git-wip-us.apache.org/repos/asf/isis/blob/950b413a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_invoke_TOREFACTOR.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_invoke_TOREFACTOR.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_invoke_TOREFACTOR.java
new file mode 100644
index 0000000..5626aa7
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_invoke_TOREFACTOR.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.actioninvoke;
+
+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 DomainServiceTest_invoke_TOREFACTOR {
+
+    @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/950b413a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_req_queryarg_xrovalidateonly.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_req_queryarg_xrovalidateonly.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_req_queryarg_xrovalidateonly.java
new file mode 100644
index 0000000..5a2b8d1
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_req_queryarg_xrovalidateonly.java
@@ -0,0 +1,20 @@
+package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice.actioninvoke;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DomainServiceTest_req_queryarg_xrovalidateonly {
+
+    @Ignore
+    @Test
+    public void success() throws Exception {
+        // should return 204 (13.3)
+    }
+
+    @Ignore
+    @Test
+    public void failure() throws Exception {
+        // should return 422, etc
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/950b413a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_List.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_List.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_List.java
new file mode 100644
index 0000000..a7c1d82
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_List.java
@@ -0,0 +1,13 @@
+package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice.actioninvoke;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DomainServiceTest_resp_representation_of_List {
+
+    @Ignore
+    @Test
+    public void todo() throws Exception {
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/950b413a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Object.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Object.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Object.java
new file mode 100644
index 0000000..9827629
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Object.java
@@ -0,0 +1,13 @@
+package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice.actioninvoke;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DomainServiceTest_resp_representation_of_Object {
+
+    @Ignore
+    @Test
+    public void todo() throws Exception {
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/950b413a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Scalar.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Scalar.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Scalar.java
new file mode 100644
index 0000000..b0586db
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Scalar.java
@@ -0,0 +1,13 @@
+package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice.actioninvoke;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DomainServiceTest_resp_representation_of_Scalar {
+
+    @Ignore
+    @Test
+    public void todo() throws Exception {
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/950b413a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Void.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Void.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Void.java
new file mode 100644
index 0000000..304a536
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_representation_of_Void.java
@@ -0,0 +1,13 @@
+package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice.actioninvoke;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DomainServiceTest_resp_representation_of_Void {
+
+    @Ignore
+    @Test
+    public void todo() throws Exception {
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/950b413a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_throwsError.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_throwsError.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_throwsError.java
new file mode 100644
index 0000000..a77b9f6
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_resp_throwsError.java
@@ -0,0 +1,13 @@
+package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice.actioninvoke;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DomainServiceTest_resp_throwsError {
+
+    @Ignore
+    @Test
+    public void todo() throws Exception {
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/950b413a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_when_created_new_object.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_when_created_new_object.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_when_created_new_object.java
new file mode 100644
index 0000000..efe7665
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_when_created_new_object.java
@@ -0,0 +1,14 @@
+package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice.actioninvoke;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DomainServiceTest_when_created_new_object {
+
+    @Ignore
+    @Test
+    public void todo() throws Exception {
+        // should return 201 (13.2)
+        // if a newly created object
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/950b413a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_when_is_forbidden.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_when_is_forbidden.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_when_is_forbidden.java
new file mode 100644
index 0000000..53bdb35
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/zzztodo/domainservice/actioninvoke/DomainServiceTest_when_is_forbidden.java
@@ -0,0 +1,13 @@
+package org.apache.isis.viewer.restfulobjects.tck.zzztodo.domainservice.actioninvoke;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DomainServiceTest_when_is_forbidden {
+
+    @Ignore
+    @Test
+    public void todo() throws Exception {
+        // should return 403 (13.6)
+    }
+}