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

Examples of org.apache.isis.viewer.restfulobjects.applib.domainobjects.ObjectCollectionRepresentation


        final Response collectionResp = domainObjectResource.accessCollection("BSRL", "73", "visibleAndEditableCollection");
        final RestfulResponse<ObjectCollectionRepresentation> collectionJsonResp = RestfulResponse.ofT(collectionResp);
        assertThat(collectionJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL));

        // then
        final ObjectCollectionRepresentation collectionRepr = collectionJsonResp.getEntity();

        assertThat(collectionRepr.getString("memberType"), is("collection"));

        // self link
        final LinkRepresentation selfLink = collectionRepr.getLinkWithRel(Rel.SELF);
        assertThat(selfLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("/objects/BSRL/73/collections/visibleAndEditableCollection"))
                                .returning(HttpStatusCode.OK)
                                .build());

        // up link
        final LinkRepresentation upLink = collectionRepr.getLinkWithRel(Rel.UP);
        assertThat(upLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("http://localhost:39393/objects/BSRL/73"))
                                .returning(HttpStatusCode.OK)
                                .type(RepresentationType.DOMAIN_OBJECT.getMediaType())
                                .title("Untitled Bus Rules Entity")
                                .build());

        //addto link
        final LinkRepresentation addtoLink = collectionRepr.getLinkWithRel(Rel.ADD_TO);
        assertThat(addtoLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.POST)
                                .type(RepresentationType.OBJECT_COLLECTION.getMediaType())
                                .href(endsWith("/objects/BSRL/73/collections/visibleAndEditableCollection"))
                                .build());

        assertThat(addtoLink.getArguments(), is(not(nullValue())));
        assertThat(addtoLink.getArguments().isArray(), is(false));
        assertThat(addtoLink.getArguments().size(), is(1));

       //remove-from link
        final LinkRepresentation removeFromLink = collectionRepr.getLinkWithRel(Rel.REMOVE_FROM);
        assertThat(removeFromLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.DELETE)
                                .type(RepresentationType.OBJECT_COLLECTION.getMediaType())
                                .href(endsWith("/objects/BSRL/73/collections/visibleAndEditableCollection"))
                                .build());

        assertThat(removeFromLink.getArguments(), is(not(nullValue())));
        assertThat(removeFromLink.getArguments().isArray(), is(false));
        assertThat(removeFromLink.getArguments().size(), is(1));

        // described by link
        final LinkRepresentation describedByLink = collectionRepr.getLinkWithRel(Rel.DESCRIBEDBY);
        assertThat(describedByLink, isLink(client)
                                .returning(HttpStatusCode.OK)
                                .responseEntityWithSelfHref(describedByLink.getHref())
                                .build());

        assertThat(collectionRepr.getArray("value").isArray(),is(true));

        assertThat(collectionRepr.getExtensions(), isMap());
        assertThat(collectionRepr.getExtensions().getString("collectionSemantics"), is("list"));
        assertThat(collectionRepr.getExtensions().getArray("changed").isArray(), is(true));
        assertThat(collectionRepr.getExtensions().getArray("disposed").isArray(), is(true));
    }
View Full Code Here


    public void usingClientFollow() throws Exception {

        // given
        RestfulResponse<ObjectCollectionRepresentation> childrenRestfulResponse =
                RestfulResponse.ofT(objectResource.accessCollection("PRNT", "53", "children"));
        ObjectCollectionRepresentation childrenRepr = childrenRestfulResponse.getEntity();

        JsonRepresentation collValue = childrenRepr.getValue();

        final int numChildren = collValue.size();
        assertThat(numChildren, is(IsisMatchers.greaterThan(0)));

        final LinkRepresentation firstChildRepr = collValue.arrayIterator(LinkRepresentation.class).next();
       
        // when
        final RestfulResponse<ObjectActionRepresentation> removeChildRestfulResponse =
                RestfulResponse.ofT(objectResource.actionPrompt("PRNT", "53", "removeChild"));
        final ObjectActionRepresentation removeChildRepr = removeChildRestfulResponse.getEntity();
       
        LinkRepresentation invokeLinkRepr = removeChildRepr.getLinkWithRel(Rel.INVOKE);
        JsonRepresentation args = invokeLinkRepr.getArguments();
        args.mapPut("childEntity.value", firstChildRepr);
        RestfulResponse<JsonRepresentation> invokeResp = client.follow(invokeLinkRepr, args);
       
        @SuppressWarnings("unused")
        JsonRepresentation invokeRepr = invokeResp.getEntity();
        final HttpStatusCode status = invokeResp.getStatus();
        assertThat(status, is(HttpStatusCode.OK));

        // then
        childrenRestfulResponse =
                RestfulResponse.ofT(objectResource.accessCollection("PRNT", "53", "children"));
        childrenRepr = childrenRestfulResponse.getEntity();

        collValue = childrenRepr.getValue();
        assertThat(collValue.size(), is(numChildren-1));
    }
View Full Code Here

        final Response collectionResp = domainObjectResource.accessCollection("BSRL", "64", "invisibleCollection");
        final RestfulResponse<ObjectCollectionRepresentation> collectionJsonResp = RestfulResponse.ofT(collectionResp);
        assertThat(collectionJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL));

        // then
        final ObjectCollectionRepresentation collectionRepr = collectionJsonResp.getEntity();

        assertThat(collectionRepr.getString("memberType"), is("collection"));

        // self link
        final LinkRepresentation selfLink = collectionRepr.getLinkWithRel(Rel.SELF);
        assertThat(selfLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("/objects/BSRL/64/collections/invisibleCollection"))
                                .returning(HttpStatusCode.OK));

        // up link
        final LinkRepresentation upLink = collectionRepr.getLinkWithRel(Rel.UP);
        assertThat(upLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("http://localhost:39393/objects/BSRL/64"))
                                .returning(HttpStatusCode.OK)
                                .type(RepresentationType.DOMAIN_OBJECT.getMediaType())
                                .title("Untitled Bus Rules Entity"));

        //addto link
        final LinkRepresentation addtoLink = collectionRepr.getLinkWithRel(Rel.ADD_TO);
        assertThat(addtoLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.POST)
                                .type(RepresentationType.OBJECT_COLLECTION.getMediaType())
                                .href(endsWith("/objects/BSRL/64/collections/invisibleCollection")));

        assertThat(addtoLink.getArguments(), is(not(nullValue())));
        assertThat(addtoLink.getArguments().isArray(), is(false));
        assertThat(addtoLink.getArguments().size(), is(1));

       //remove-from link
        final LinkRepresentation removeFromLink = collectionRepr.getLinkWithRel(Rel.REMOVE_FROM);
        assertThat(removeFromLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.DELETE)
                                .type(RepresentationType.OBJECT_COLLECTION.getMediaType())
                                .href(endsWith("/objects/BSRL/64/collections/invisibleCollection")));

        assertThat(removeFromLink.getArguments(), is(not(nullValue())));
        assertThat(removeFromLink.getArguments().isArray(), is(false));
        assertThat(removeFromLink.getArguments().size(), is(1));

        // described by link
        final LinkRepresentation describedByLink = collectionRepr.getLinkWithRel(Rel.DESCRIBEDBY);
        assertThat(describedByLink, isLink(client)
                                .returning(HttpStatusCode.OK)
                                .responseEntityWithSelfHref(describedByLink.getHref()));

        assertThat(collectionRepr.getArray("value").isArray(),is(true));

        assertThat(collectionRepr.getExtensions(), isMap());
        assertThat(collectionRepr.getExtensions().getString("collectionSemantics"), is("list"));
        assertThat(collectionRepr.getExtensions().getArray("changed").isArray(), is(true));
        assertThat(collectionRepr.getExtensions().getArray("disposed").isArray(), is(true));
    }
View Full Code Here

    public void usingClientFollow() throws Exception {

        // given
        RestfulResponse<ObjectCollectionRepresentation> childrenRestfulResponse =
                RestfulResponse.ofT(objectResource.accessCollection("PRNT", "43", "children"));
        ObjectCollectionRepresentation childrenRepr = childrenRestfulResponse.getEntity();

        JsonRepresentation collValue = childrenRepr.getValue();

        final int numChildren = collValue.size();
        assertThat(numChildren, is(IsisMatchers.greaterThan(0)));

        final LinkRepresentation firstChildRepr = collValue.arrayIterator(LinkRepresentation.class).next();
       
        // when
        final RestfulResponse<ObjectActionRepresentation> removeChildRestfulResponse =
                RestfulResponse.ofT(objectResource.actionPrompt("PRNT", "43", "removeChild"));
        final ObjectActionRepresentation removeChildRepr = removeChildRestfulResponse.getEntity();
       
        LinkRepresentation invokeLinkRepr = removeChildRepr.getLinkWithRel(Rel.INVOKE);
        JsonRepresentation args = invokeLinkRepr.getArguments();
        args.mapPut("childEntity.value", firstChildRepr);
        RestfulResponse<JsonRepresentation> invokeResp = client.follow(invokeLinkRepr, args);
       
        @SuppressWarnings("unused")
        JsonRepresentation invokeRepr = invokeResp.getEntity();
        final HttpStatusCode status = invokeResp.getStatus();
        assertThat(status, is(HttpStatusCode.OK));

        // then
        childrenRestfulResponse =
                RestfulResponse.ofT(objectResource.accessCollection("PRNT", "43", "children"));
        childrenRepr = childrenRestfulResponse.getEntity();

        collValue = childrenRepr.getValue();
        assertThat(collValue.size(), is(numChildren-1));
    }
View Full Code Here

        final Response collectionResp = domainObjectResource.accessCollection("BSRL", "64", "visibleAndEditableCollection");
        final RestfulResponse<ObjectCollectionRepresentation> collectionJsonResp = RestfulResponse.ofT(collectionResp);
        assertThat(collectionJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL));

        // then
        final ObjectCollectionRepresentation collectionRepr = collectionJsonResp.getEntity();

        assertThat(collectionRepr.getString("memberType"), is("collection"));

        // self link
        final LinkRepresentation selfLink = collectionRepr.getLinkWithRel(Rel.SELF);
        assertThat(selfLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("/objects/BSRL/64/collections/visibleAndEditableCollection"))
                                .returning(HttpStatusCode.OK)
                                .build());

        // up link
        final LinkRepresentation upLink = collectionRepr.getLinkWithRel(Rel.UP);
        assertThat(upLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("http://localhost:39393/objects/BSRL/64"))
                                .returning(HttpStatusCode.OK)
                                .type(RepresentationType.DOMAIN_OBJECT.getMediaType())
                                .title("Untitled Bus Rules Entity")
                                .build());

        //addto link
        final LinkRepresentation addtoLink = collectionRepr.getLinkWithRel(Rel.ADD_TO);
        assertThat(addtoLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.POST)
                                .type(RepresentationType.OBJECT_COLLECTION.getMediaType())
                                .href(endsWith("/objects/BSRL/64/collections/visibleAndEditableCollection"))
                                .build());

        assertThat(addtoLink.getArguments(), is(not(nullValue())));
        assertThat(addtoLink.getArguments().isArray(), is(false));
        assertThat(addtoLink.getArguments().size(), is(1));

       //remove-from link
        final LinkRepresentation removeFromLink = collectionRepr.getLinkWithRel(Rel.REMOVE_FROM);
        assertThat(removeFromLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.DELETE)
                                .type(RepresentationType.OBJECT_COLLECTION.getMediaType())
                                .href(endsWith("/objects/BSRL/64/collections/visibleAndEditableCollection"))
                                .build());

        assertThat(removeFromLink.getArguments(), is(not(nullValue())));
        assertThat(removeFromLink.getArguments().isArray(), is(false));
        assertThat(removeFromLink.getArguments().size(), is(1));

        // described by link
        final LinkRepresentation describedByLink = collectionRepr.getLinkWithRel(Rel.DESCRIBEDBY);
        assertThat(describedByLink, isLink(client)
                                .returning(HttpStatusCode.OK)
                                .responseEntityWithSelfHref(describedByLink.getHref())
                                .build());

        assertThat(collectionRepr.getArray("value").isArray(),is(true));

        assertThat(collectionRepr.getExtensions(), isMap());
        assertThat(collectionRepr.getExtensions().getString("collectionSemantics"), is("list"));
        assertThat(collectionRepr.getExtensions().getArray("changed").isArray(), is(true));
        assertThat(collectionRepr.getExtensions().getArray("disposed").isArray(), is(true));
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.viewer.restfulobjects.applib.domainobjects.ObjectCollectionRepresentation

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.