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

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


        // then actions
        final JsonRepresentation actions = domainObjectRepr.getActions();
        assertThat(actions.size(), is(3));

        final DomainObjectMemberRepresentation containsAction = domainObjectRepr.getAction("contains");
        assertThat(containsAction.getString("memberType"), is("action"));
        assertThat(containsAction.getString("id"), is("contains"));

        LinkRepresentation containsActionLink = containsAction.getLinkWithRel(Rel.DETAILS.andParam("action", "contains"));
        assertThat(containsActionLink.getRel(), is(Rel.DETAILS.andParam("action", "contains")));
        assertThat(containsActionLink.getHref(), is(self.getHref() + "/actions/contains"));
        assertThat(containsActionLink.getType(), is(RepresentationType.OBJECT_ACTION.getMediaType()));
        assertThat(containsActionLink.getHttpMethod(), is(RestfulHttpMethod.GET));

        // can also look up with abbreviated parameterized version of Rel
        containsActionLink = containsAction.getLinkWithRel(Rel.DETAILS);
        assertThat(containsActionLink.getRel(), is("urn:org.restfulobjects:rels/details;action=\"contains\""));
        assertThat(containsActionLink.getHref(), is(self.getHref() + "/actions/contains"));
        assertThat(containsActionLink.getType(), is(RepresentationType.OBJECT_ACTION.getMediaType()));
        assertThat(containsActionLink.getHttpMethod(), is(RestfulHttpMethod.GET));
View Full Code Here


        final RestfulResponse<JsonRepresentation> restResp = client.follow(link);
        final JsonRepresentation entityRepr = restResp.getEntity();
        domainObjectRepr = entityRepr.as(DomainObjectRepresentation.class);

        // and then members (types)
        DomainObjectMemberRepresentation property;
        ScalarValueRepresentation scalarRepr;

        property = domainObjectRepr.getProperty("bigDecimalProperty");
        assertThat(property.getMemberType(), is("property"));
        assertThat(property.getFormat(), is("big-decimal(30,10)"));
        assertThat(property.getXIsisFormat(), is("javamathbigdecimal"));
        scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
        assertThat(scalarRepr.isString(), is(true));
        BigDecimal bigDecimal = scalarRepr.asBigDecimal(property.getFormat());
        assertThat(bigDecimal, is(new BigDecimal("12345678901234567890.1234567890")));

        property = domainObjectRepr.getProperty("bigDecimalProperty2");
        assertThat(property.getMemberType(), is("property"));
        assertThat(property.getFormat(), is("big-decimal(18,2)"));
        assertThat(property.getXIsisFormat(), is("javamathbigdecimal"));
        scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
        assertThat(scalarRepr.isString(), is(true));
        BigDecimal bigDecimal2 = scalarRepr.asBigDecimal(property.getFormat());
        assertThat(bigDecimal2, is(new BigDecimal("123.45")));

        property = domainObjectRepr.getProperty("bigIntegerProperty");
        assertThat(property.getMemberType(), is("property"));
        assertThat(property.getFormat(), is("big-integer(18)"));
        assertThat(property.getXIsisFormat(), is("javamathbiginteger"));
        scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
        assertThat(scalarRepr.isString(), is(true));
        BigInteger bigInteger = scalarRepr.asBigInteger(property.getFormat());
        assertThat(bigInteger, is(new BigInteger("123456789012345678")));

        property = domainObjectRepr.getProperty("bigIntegerProperty2");
        assertThat(property.getMemberType(), is("property"));
        assertThat(property.getFormat(), is("big-integer(18)"));
        scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
        assertThat(scalarRepr.isString(), is(true));
        BigInteger bigInteger2 = scalarRepr.asBigInteger(property.getFormat());
        assertThat(bigInteger2, is(new BigInteger("12345")));

        property = domainObjectRepr.getProperty("javaSqlDateProperty");
        assertThat(property.getMemberType(), is("property"));
        assertThat(property.getFormat(), is("date"));
        assertThat(property.getXIsisFormat(), is("javasqldate"));
        scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
        assertThat(scalarRepr.isString(), is(true));
        assertThat(scalarRepr.asString(), is("2014-04-24"));
        assertThat(scalarRepr.asDate(), is(asDate("2014-04-24")));

        property = domainObjectRepr.getProperty("javaSqlTimeProperty");
        assertThat(property.getMemberType(), is("property"));
        assertThat(property.getFormat(), is("time"));
        assertThat(property.getXIsisFormat(), is("javasqltime"));
        scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
        assertThat(scalarRepr.isString(), is(true));
        assertThat(scalarRepr.asString(), is("12:34:45"));
        assertThat(scalarRepr.asTime(), is(asDateTime("1970-01-01T12:34:45Z")));

        property = domainObjectRepr.getProperty("javaSqlTimestampProperty");
        assertThat(property.getMemberType(), is("property"));
        assertThat(property.getFormat(), is("utc-millisec"));
        assertThat(property.getXIsisFormat(), is("javasqltimestamp"));
        scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
        assertThat(scalarRepr.isInt() || scalarRepr.isLong(), is(true));
        Long aLong = scalarRepr.asLong();
        assertThat(aLong, is(new Long("1234567890")));

        property = domainObjectRepr.getProperty("javaUtilDateProperty");
        assertThat(property.getMemberType(), is("property"));
        assertThat(property.getFormat(), is("date-time"));
        assertThat(property.getXIsisFormat(), is("javautildate"));
        scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
        assertThat(scalarRepr.isString(), is(true));
        Date utilDate = scalarRepr.asDateTime();
        assertThat(utilDate, is(asDateTime("2013-05-25T12:34:45Z")));
        assertThat(scalarRepr.asString(), is("2013-05-25T12:34:45Z"));

        property = domainObjectRepr.getProperty("myEnum");
        assertThat(property.getMemberType(), is("property"));
        assertThat(property.getFormat(), is("string"));
        assertThat(property.getXIsisFormat(), is("string"));
        scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
        assertThat(scalarRepr.isString(), is(true));
        String myEnumStr = scalarRepr.asString();
        assertThat(myEnumStr, is("RED"));
    }
View Full Code Here

TOP

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

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.