Package org.apache.isis.viewer.restfulobjects.applib

Examples of org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation$HasLinkToSelf


    @Test
    public void usingClientFollow() throws Exception {

        // given
        final JsonRepresentation givenAction = Util.givenAction(client, "ActionsEntities", "list");
        final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class);

        final LinkRepresentation invokeLink = actionRepr.getInvoke();

        assertThat(invokeLink, isLink(client)
                                    .rel(Rel.INVOKE)
View Full Code Here


    @Test
    public void usingClientFollow() throws Exception {

        // given
        final JsonRepresentation givenAction = Util.givenAction(client, "ActionsEntities", "subList");
        final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class);

        final LinkRepresentation invokeLink = actionRepr.getInvoke();

        assertThat(invokeLink, isLink(client)
                                    .rel(Rel.INVOKE)
                                    .httpMethod(RestfulHttpMethod.GET)
                                    .href(Matchers.endsWith(":39393/services/ActionsEntities/actions/subList/invoke"))
                                    .build());
       
        JsonRepresentation args =invokeLink.getArguments();
        assertThat(args.size(), is(2));
        assertThat(args, RestfulMatchers.mapHas("from"));
        assertThat(args, RestfulMatchers.mapHas("to"));
       
        // when
        args.mapPut("from.value", -1);
        args.mapPut("to.value", 2);

        final RestfulResponse<ActionResultRepresentation> restfulResponse = client.followT(invokeLink, args);
       
        // then
        thenResponseIsAValidationError(restfulResponse);
View Full Code Here

    @Test
    public void usingResourceProxy() throws Exception {

        // given, when
        JsonRepresentation args = JsonRepresentation.newMap();
        args.mapPut("from.value", -1);
        args.mapPut("to.value", 2);
        Response response = serviceResource.invokeActionQueryOnly("ActionsEntities", "subList", UrlEncodingUtils.urlEncode(args));
        RestfulResponse<ActionResultRepresentation> restfulResponse = RestfulResponse.ofT(response);
       
        // then
        thenResponseIsAValidationError(restfulResponse);
View Full Code Here

        assertThat(subListRepr.getValue().size(), is(1));
       
        LinkRepresentation firstEntityLink = subListRepr.getValue().arrayGet(0).asLink();

        // and given a representation of the 'contains' action accepting a entity href
        final JsonRepresentation containsAction = Util.givenAction(client, "ActionsEntities", "contains");
        final ObjectActionRepresentation containsActionRepr = containsAction.as(ObjectActionRepresentation.class);
       
        final LinkRepresentation invokeLink = containsActionRepr.getInvoke();
        final JsonRepresentation args = invokeLink.getArguments();
        assertThat(args.size(), is(3));
       
        // when query the 'contains' action passing in the entity
        // (for a range where the entity is contained in the range)
        args.mapPut("searchFor.value", firstEntityLink);
        args.mapPut("from.value", 0);
        args.mapPut("to.value", 3);
       
        RestfulResponse<ActionResultRepresentation> restfulResponse = client.followT(invokeLink, args);

        // then
        thenResponseIsScalarValueOf(restfulResponse, true);
       
       
        // and when query the 'contains' action for a different range which does not
        // contain the entity
        args.mapPut("searchFor.value", firstEntityLink);
        args.mapPut("from.value", 3);
        args.mapPut("to.values", 5);
       
        restfulResponse = client.followT(invokeLink, args);

        // then
        thenResponseIsScalarValueOf(restfulResponse, false);
View Full Code Here

        final ListRepresentation subListRepr = givenSublistActionInvoked(0, 1);
        LinkRepresentation firstEntityLink = subListRepr.getValue().arrayGet(0).asLink();

        // when query the 'contains' action passing in the entity
        // (for a range where the entity is contained in the range)
        JsonRepresentation args = JsonRepresentation.newMap();
        args.mapPut("searchFor.value", firstEntityLink);
        args.mapPut("from.value", 0);
        args.mapPut("to.value", 3);
        Response response = serviceResource.invokeActionQueryOnly("ActionsEntities", "contains", UrlEncodingUtils.urlEncode(args));
        RestfulResponse<ActionResultRepresentation> restfulResponse = RestfulResponse.ofT(response);
       
        // then
        thenResponseIsScalarValueOf(restfulResponse, true);
View Full Code Here

    private void thenResponseIsScalarValueOf(RestfulResponse<ActionResultRepresentation> restfulResponse, boolean value) throws JsonParseException, JsonMappingException, IOException {
        assertThat(restfulResponse.getHeader(Header.CONTENT_TYPE), hasMediaTypeProfile(RestfulMediaType.APPLICATION_JSON_ACTION_RESULT));
        ActionResultRepresentation actionResultRepr = restfulResponse.getEntity();
        assertThat(actionResultRepr.getResultType(), is(ResultType.SCALAR_VALUE));
        JsonRepresentation resultRepr = actionResultRepr.getResult();
        assertThat(resultRepr, is(not(nullValue())));
       
        ScalarValueRepresentation scalarValueRepr = resultRepr.as(ScalarValueRepresentation.class);
       
        LinkRepresentation returnTypeLink = scalarValueRepr.getLinkWithRel(Rel.RETURN_TYPE);
        assertThat(returnTypeLink, is(not(nullValue())));
        assertThat(returnTypeLink, isLink(client)
                                        .rel(Rel.RETURN_TYPE)
View Full Code Here

        assertThat(scalarValueRepr.getValue().asBoolean(), is(value));
    }


    private ListRepresentation givenSublistActionInvoked(int from, int to) throws Exception {
        final JsonRepresentation givenSubListAction = Util.givenAction(client, "ActionsEntities", "subList");
        final ObjectActionRepresentation actionRepr = givenSubListAction.as(ObjectActionRepresentation.class);
       
        final LinkRepresentation invokeLink = actionRepr.getInvoke();
        final JsonRepresentation args = invokeLink.getArguments();
       
        // when
        args.mapPut("from.value", from);
        args.mapPut("to.value", to);
       
        final RestfulResponse<ActionResultRepresentation> restfulResponse = client.followT(invokeLink, args);
       
        final ActionResultRepresentation actionResultRepr = restfulResponse.getEntity();
        return actionResultRepr.getResult().as(ListRepresentation.class);
View Full Code Here

    @Test
    public void usingClientFollow_whenExplicitlySetToNull() throws Exception {

        // given
        final JsonRepresentation givenAction = Util.givenAction(client, "ActionsEntities", "subListWithOptionalRange");
        final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class);

        final LinkRepresentation invokeLink = actionRepr.getInvoke();

        assertThat(invokeLink, isLink(client)
                                    .rel(Rel.INVOKE)
                                    .httpMethod(RestfulHttpMethod.GET)
                                    .href(Matchers.endsWith(":39393/services/ActionsEntities/actions/subListWithOptionalRange/invoke"))
                                    .build());
       
        JsonRepresentation args =invokeLink.getArguments();
        assertThat(args.size(), is(2));
        assertThat(args, RestfulMatchers.mapHas("from"));
        assertThat(args, RestfulMatchers.mapHas("to"));
       
        // when
        args.mapPut("from.value", (Integer)null);
        args.mapPut("to.value", (Integer)null);

        final RestfulResponse<ActionResultRepresentation> restfulResponse = client.followT(invokeLink, args);
       
        then(restfulResponse);
    }
View Full Code Here

    @Test
    public void usingResourceProxy_whenExplicitlySetToNull() throws Exception {

        // given, when
        JsonRepresentation args = JsonRepresentation.newMap();
        args.mapPut("from.value", (Integer)null);
        args.mapPut("to.value", (Integer)null);
        Response response = serviceResource.invokeActionQueryOnly("ActionsEntities", "subListWithOptionalRange", UrlEncodingUtils.urlEncode(args));
        RestfulResponse<ActionResultRepresentation> restfulResponse = RestfulResponse.ofT(response);
       
        // then
        then(restfulResponse);
View Full Code Here

   
    @Test
    public void usingClientFollow_whenImplicitlySetToNull() throws Exception {

        // given
        final JsonRepresentation givenAction = Util.givenAction(client, "ActionsEntities", "subListWithOptionalRange");
        final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class);

        final LinkRepresentation invokeLink = actionRepr.getInvoke();

        assertThat(invokeLink, isLink(client)
                                    .rel(Rel.INVOKE)
                                    .httpMethod(RestfulHttpMethod.GET)
                                    .href(Matchers.endsWith(":39393/services/ActionsEntities/actions/subListWithOptionalRange/invoke"))
                                    .build());
       
        // when
        JsonRepresentation args = JsonRepresentation.newMap();

        final RestfulResponse<ActionResultRepresentation> restfulResponse = client.followT(invokeLink, args);
       
        then(restfulResponse);
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation$HasLinkToSelf

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.