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

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.equals(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


        final ListRepresentation listRepr = actionResultRepr.getResult().as(ListRepresentation.class);

        assertThat(listRepr.getValue(), is(not(nullValue())));
        assertThat(listRepr.getValue().size(), is(IsisMatchers.greaterThan(idx + 1)));

        final LinkRepresentation domainObjectLinkRepr = listRepr.getValue().arrayGet(idx).as(LinkRepresentation.class);

        assertThat(domainObjectLinkRepr, is(not(nullValue())));
        assertThat(domainObjectLinkRepr, isLink().rel(Rel.ELEMENT).httpMethod(RestfulHttpMethod.GET).type(RepresentationType.DOMAIN_OBJECT.getMediaType()).arguments(JsonRepresentation.newMap()).build());

        return domainObjectLinkRepr;
View Full Code Here

        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"));
View Full Code Here

    @Test
    public void primitivePropertiesUpdated() throws Exception {
       
        final DomainObjectRepresentation domainObjectRepr = getObjectRepr("PRMV", "31");
       
        final LinkRepresentation updateLink = domainObjectRepr.getLinkWithRel(Rel.UPDATE);
       
        final JsonRepresentation argRepr = updateLink.getArguments();
       
        final byte b = (byte)99;
        final char c = 'b';
        final double d = 12345.678;
        final float f = 54321.123F;
View Full Code Here

    @Test
    public void jdkPropertiesUpdated() throws Exception {
       
        final DomainObjectRepresentation domainObjectRepr = getObjectRepr("JDKV", "29");
        final LinkRepresentation updateLink = domainObjectRepr.getLinkWithRel(Rel.UPDATE);
        final JsonRepresentation argRepr = updateLink.getArguments();

        final BigDecimal bd = new BigDecimal("12345678901234567.789");
        final BigInteger bi = new BigInteger("12345678901234567890");
        final java.sql.Date sqld = new java.sql.Date(114,4,1);
        final java.sql.Time sqlt = new java.sql.Time(13,0,0);
View Full Code Here

    @Test
    public void jodaPropertiesUpdated() throws Exception {
       
        final DomainObjectRepresentation domainObjectRepr = getObjectRepr("JODA", "73");
       
        final LinkRepresentation updateLink = domainObjectRepr.getLinkWithRel(Rel.UPDATE);
       
        final JsonRepresentation argRepr = updateLink.getArguments();
       
        final LocalDate ld = new LocalDate(2013,5,1);
        final LocalDateTime ldt = new LocalDateTime(2013,2,1,14,15,0);
        final DateTime dt = new DateTime(2013,2,1,14,15,0);
        final String s = "New string";
View Full Code Here

    @Test
    public void thenMembers() throws Exception {

        // when
        final LinkRepresentation link = Util.domainObjectLink(client, "WrapperValuedEntities");
        domainObjectRepr = client.follow(link).getEntity().as(DomainObjectRepresentation.class);


        // and then members (types)
        DomainObjectMemberRepresentation property;
View Full Code Here

    @Before
    public void setUp() throws Exception {
        final WebServer webServer = webServerRule.getWebServer();
        client = new RestfulClient(webServer.getBase());
       
        link = new LinkRepresentation();
    }
View Full Code Here

    @Test
    public void whenPropertyDoesntExist() throws Exception {

        // given
        final LinkRepresentation linkToExistingObject = Util.domainObjectLink(client, "PrimitiveValuedEntities");
        link.withHref(linkToExistingObject.getHref() + "/properties/nonExistentProperty");
       
        // when
        final RestfulResponse<JsonRepresentation> restfulResp = client.follow(link);
       
        // then
View Full Code Here

        final ObjectPropertyRepresentation propertyRepr = idPropertyJsonResp.getEntity();

        assertThat(propertyRepr.getString("memberType"), is("property"));

        // self link
        final LinkRepresentation selfLink = propertyRepr.getLinkWithRel(Rel.SELF);
        assertThat(selfLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("/objects/org.apache.isis.core.tck.dom.defaults.WithDefaultsEntity/58/properties/anInt"))
                                .returning(HttpStatusCode.OK));

        // up link
        final LinkRepresentation upLink = propertyRepr.getLinkWithRel(Rel.UP);
        assertThat(upLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.GET)
                                .href(endsWith("/objects/org.apache.isis.core.tck.dom.defaults.WithDefaultsEntity/58"))
                                .returning(HttpStatusCode.OK)
                                .type(RepresentationType.DOMAIN_OBJECT.getMediaType())
                                .title("default-name"));

        //modify link
        final LinkRepresentation modifyLink = propertyRepr.getLinkWithRel(Rel.MODIFY);
        assertThat(modifyLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.PUT)
                                .type(RepresentationType.OBJECT_PROPERTY.getMediaType())
                                .href(endsWith("/objects/org.apache.isis.core.tck.dom.defaults.WithDefaultsEntity/58/properties/anInt")));

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

        //clear link
        final LinkRepresentation clearLink = propertyRepr.getLinkWithRel(Rel.CLEAR);
        assertThat(clearLink, isLink(client)
                                .httpMethod(RestfulHttpMethod.DELETE)
                                .type(RepresentationType.OBJECT_PROPERTY.getMediaType())
                                .href(endsWith("/objects/org.apache.isis.core.tck.dom.defaults.WithDefaultsEntity/58/properties/anInt")));

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

        assertThat(propertyRepr.getInt("value"), is(42));
        assertThat(propertyRepr.getString("format"),is("int"));
        assertThat(propertyRepr.getString("extensions.x-isis-format"), is("int"));
        assertThat(propertyRepr.getExtensions(), isMap());
View Full Code Here

TOP

Related Classes of org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation

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.