Examples of LinkRepresentation


Examples of org.apache.isis.viewer.json.applib.links.LinkRepresentation

    private LinkRepresentation link;
    private JsonRepresentation jsonRepresentation;

    @Before
    public void setUp() throws Exception {
        link = new LinkRepresentation().withHref("http://foo/bar").withMethod(HttpMethod.GET);
        jsonRepresentation = new JsonRepresentation(readJson("map.json"));
    }
View Full Code Here

Examples of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

                @Override
                public boolean matchesSafely(final JsonRepresentation linkRepr) {
                    if (linkRepr == null) {
                        return false;
                    }
                    final LinkRepresentation link = linkRepr.asLink();
                    if (rel != null && !Rel.parse(rel).matches(link.getRel())) {
                        return false;
                    }
                    if (relNameMatcher != null && !relNameMatcher.matches(link.getRel())) {
                        return false;
                    }
                    if (href != null && !href.equals(link.getHref())) {
                        return false;
                    }
                    if (hrefMatcher != null && !hrefMatcher.matches(link.getHref())) {
                        return false;
                    }
                    if (title != null && !title.equals(link.getTitle())) {
                        return false;
                    }
                    if (titleMatcher != null && !titleMatcher.matches(link.getTitle())) {
                        return false;
                    }
                    if (httpMethod != null && !httpMethod.equals(link.getHttpMethod())) {
                        return false;
                    }
                    if (mediaType != null && !mediaType.isCompatible(mediaType)) {
                        return false;
                    }
                    if (typeParameterName != null) {
                        final MediaType mediaType = link.getType();
                        final String parameterValue = mediaType.getParameters().get(typeParameterName);
                        if (!typeParameterValue.equals(parameterValue)) {
                            return false;
                        }
                    }
                    if (novalue != null && novalue && link.getValue() != null) {
                        return false;
                    }
                    if (arguments != null && !arguments.equals(link.getArguments())) {
                        return false;
                    }
                    if (valueMatcher != null && !valueMatcher.matches(link.getValue())) {
                        return false;
                    }

                    // follow link if criteria require it
                    RestfulResponse<JsonRepresentation> jsonResp = null;
                    if (statusCode != null || selfHref != null) {
                        if (client == null) {
                            return false;
                        }
                        try {
                            jsonResp = client.followT(link);
                        } catch (final Exception e) {
                            throw new RuntimeException(e);
                        }
                    }

                    // assertions based on provided criteria
                    try {
                        if (statusCode != null) {
                            if (jsonResp.getStatus() != statusCode) {
                                return false;
                            }
                        }
                        if (selfHref != null) {
                            JsonRepresentation entity;
                            try {
                                entity = jsonResp.getEntity();
                            } catch (Exception e) {
                                return false;
                            }
                            if(entity == null) {
                                return false;
                            }
                            LinkRepresentation selfLink = entity.getLink("links[rel=self]");
                            if(selfLink == null) {
                                return false;
                            }
                            if (!selfLink.getHref().equals(selfHref)) {
                                return false;
                            }
                        }
                        return true;
                    } finally {
View Full Code Here

Examples of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

        // given
        final Response resp = resource.version();

        final RestfulResponse<VersionRepresentation> jsonResp = RestfulResponse.ofT(resp);
        final VersionRepresentation repr = jsonResp.getEntity();
        final LinkRepresentation selfLink = repr.getLinkWithRel(Rel.SELF);
        final LinkRepresentation putLink = selfLink.withMethod(RestfulHttpMethod.PUT);

        // when
        final RestfulResponse<JsonRepresentation> restfulResponse = client.follow(putLink);

        // then
View Full Code Here

Examples of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

        // given
        final Response resp = resource.version();

        final RestfulResponse<VersionRepresentation> jsonResp = RestfulResponse.ofT(resp);
        final VersionRepresentation repr = jsonResp.getEntity();
        final LinkRepresentation selfLink = repr.getLinkWithRel(Rel.SELF);
        final LinkRepresentation postLink = selfLink.withMethod(RestfulHttpMethod.POST);

        // when
        final RestfulResponse<JsonRepresentation> restfulResponse = client.follow(postLink);

        // then
View Full Code Here

Examples of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

        // given
        final Response actionPromptResp = domainObjectResource.actionPrompt("RTNE", "78", "contains");
        final RestfulResponse<ObjectActionRepresentation> actionPromptJsonResp = RestfulResponse.ofT(actionPromptResp);
        final ObjectActionRepresentation actionPromptRepr = actionPromptJsonResp.getEntity();
        final LinkRepresentation selfLink = actionPromptRepr.getLinkWithRel(Rel.SELF);
        final LinkRepresentation deleteLink = selfLink.withMethod(RestfulHttpMethod.POST);

        // when
        final RestfulResponse<JsonRepresentation> restfulResponse = client.follow(deleteLink);

        // then
View Full Code Here

Examples of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

        // given
        final Response actionPromptResp = serviceResource.actionPrompt("ActionsEntities", "subListWithOptionalRange");
        final RestfulResponse<ObjectActionRepresentation> actionPromptJsonResp = RestfulResponse.ofT(actionPromptResp);
        final ObjectActionRepresentation actionPromptRepr = actionPromptJsonResp.getEntity();
        final LinkRepresentation selfLink = actionPromptRepr.getLinkWithRel(Rel.SELF);
        final LinkRepresentation postLink = selfLink.withMethod(RestfulHttpMethod.POST);

        // when
        final RestfulResponse<JsonRepresentation> restfulResponse = client.follow(postLink);

        // then
View Full Code Here

Examples of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

        final ObjectActionRepresentation actionPromptRepr = actionPromptJsonResp.getEntity();

        assertThat(actionPromptRepr.getString("memberType"), is("action"));

        // self link
        final LinkRepresentation selfLink = actionPromptRepr.getLinkWithRel(Rel.SELF);
        assertThat(selfLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("/objects/RTNE/78/actions/contains"))
                                .returning(HttpStatusCode.OK));

        // up link
        final LinkRepresentation upLink = actionPromptRepr.getLinkWithRel(Rel.UP);
        assertThat(upLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("/objects/RTNE/78"))
                                .returning(HttpStatusCode.OK)
                                .type(RepresentationType.DOMAIN_OBJECT.getMediaType())
                                .title("Untitled Actions Entity"));

        //invoke link
        final LinkRepresentation invokeLink = actionPromptRepr.getLinkWithRel(Rel.INVOKE);
        assertThat(invokeLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("/objects/RTNE/78/actions/contains/invoke")));

        assertThat(invokeLink.getArguments(), is(not(nullValue())));
        assertThat(invokeLink.getArguments().isArray(), is(false));
        assertThat(invokeLink.getArguments().size(), is(2));

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

        assertThat(actionPromptRepr.getExtensions().getString("actionType"), is("user"));
        assertThat(actionPromptRepr.getExtensions().getString("actionSemantics"), is("safe"));
        assertThat(actionPromptRepr.getMap("parameters").size(), is(2));
    }
View Full Code Here

Examples of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

        // given
        final Response serviceResp = domainServiceResource.service("ActionsEntities");
        final RestfulResponse<DomainObjectRepresentation> serviceJsonResp = RestfulResponse.ofT(serviceResp);
        final DomainObjectRepresentation serviceRepr = serviceJsonResp.getEntity();
        final LinkRepresentation selfLink = serviceRepr.getLinkWithRel(Rel.SELF);
        final LinkRepresentation postLink = selfLink.withMethod(RestfulHttpMethod.PUT);

        // when
        final RestfulResponse<JsonRepresentation> restfulResponse = client.follow(postLink);

        // then
View Full Code Here

Examples of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

        // given
        final Response resp = resource.version();

        final RestfulResponse<VersionRepresentation> jsonResp = RestfulResponse.ofT(resp);
        final VersionRepresentation repr = jsonResp.getEntity();
        final LinkRepresentation selfLink = repr.getLinkWithRel(Rel.SELF);
        final LinkRepresentation deleteLink = selfLink.withMethod(RestfulHttpMethod.DELETE);

        // when
        final RestfulResponse<JsonRepresentation> restfulResponse = client.follow(deleteLink);

        // then
View Full Code Here

Examples of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

        // given
        final Response serviceResp = domainServiceResource.service("ActionsEntities");
        final RestfulResponse<DomainObjectRepresentation> serviceJsonResp = RestfulResponse.ofT(serviceResp);
        final DomainObjectRepresentation servicesRepr = serviceJsonResp.getEntity();
        final LinkRepresentation selfLink = servicesRepr.getLinkWithRel(Rel.SELF);
        final LinkRepresentation postLink = selfLink.withMethod(RestfulHttpMethod.POST);

        // when
        final RestfulResponse<JsonRepresentation> restfulResponse = client.follow(postLink);

        // then
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.