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

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


    @Test
    public void domainObjectWithDisabledMembers() throws Exception {

        // given, when
        final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("BSRL","64");

        // property ('visibleButNotEditableProperty')
        final JsonRepresentation properties = domainObjectRepr.getProperties();
        final JsonRepresentation nameProperty = properties.getRepresentation("visibleButNotEditableProperty");
        assertThat(nameProperty.getString("disabledReason"), is("Always disabled"));
    }
View Full Code Here


    @Test
    public void domainObjectWithHiddenMembers() throws Exception {

        // given, when
        final DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("BSRL","64");

        // property ('invisibleProperty')
        final JsonRepresentation properties = domainObjectRepr.getProperties();
        final JsonRepresentation nameProperty = properties.getRepresentation("invisibleProperty");
        assertThat(nameProperty, is(nullValue()));
    }
View Full Code Here

        final RestfulResponse<DomainObjectRepresentation> jsonResp = RestfulResponse.ofT(resp);

        // then
        assertThat(jsonResp.getStatus(), is(HttpStatusCode.OK));

        final DomainObjectRepresentation repr = jsonResp.getEntity();

        assertThat(repr, isMap());

        assertThat(repr.getTitle(), matches("JdkValuedEntities"));
       
        assertThat(repr.getDomainType(), is(nullValue()));
        assertThat(repr.getInstanceId(), is(nullValue()));
       
        assertThat(repr.getServiceId(), is("JdkValuedEntities"));
       
        assertThat(repr.getSelf(), isLink().httpMethod(RestfulHttpMethod.GET));
       
        assertThat(repr.getMembers(), isMap());
        assertThat(repr.getMembers().size(), is(2));
        DomainObjectMemberRepresentation listMemberRepr = repr.getAction("list");
       
        assertThat(listMemberRepr.getMemberType(), is("action"));
        assertThat(listMemberRepr.getDisabledReason(), is(nullValue()));
        assertThat(listMemberRepr.getLinks(), isArray());
        assertThat(listMemberRepr.getLinks().size(), is(1));
       
        LinkRepresentation listMemberReprDetailsLink = listMemberRepr.getLinkWithRel(Rel.DETAILS);
        assertThat(listMemberReprDetailsLink, isLink(client)
                                       .httpMethod(RestfulHttpMethod.GET)
                                       .href(endsWith("/services/JdkValuedEntities/actions/list"))
                                       .returning(HttpStatusCode.OK)
                                       .responseEntityWithSelfHref(listMemberReprDetailsLink.getHref()));
       
       
        assertThat(repr.getLinks(), isArray());
        assertThat(repr.getLinks().size(), is(3));
       
        // link to self (see above)
        // link to describedby
        LinkRepresentation describedByLink = repr.getLinkWithRel(Rel.DESCRIBEDBY);
        assertThat(describedByLink, isLink(client)
                                       .httpMethod(RestfulHttpMethod.GET)
                                       .href(endsWith("/domain-types/JdkValuedEntities"))
                                       );
        assertThat(describedByLink, isLink(client)
                .returning(HttpStatusCode.OK)
                .responseEntityWithSelfHref(describedByLink.getHref()));
       
        assertThat(repr.getLinkWithRel(Rel.PERSIST), is(nullValue()));
        assertThat(repr.getLinkWithRel(Rel.UPDATE), is(nullValue()));
        assertThat(repr.getLinkWithRel(Rel.DELETE), is(nullValue()));
       
        assertThat(repr.getExtensions(), isMap());
        assertThat(repr.getOid(), matches("JdkValuedEntities:2"));
    }
View Full Code Here

        // when
        final RestfulResponse<DomainObjectRepresentation> jsonResp = RestfulResponse.ofT(resp);

        // then
        assertThat(jsonResp.getStatus(), is(HttpStatusCode.OK));
        final DomainObjectRepresentation repr = jsonResp.getEntity();

        assertThat(repr, isMap());

        final DomainObjectMemberRepresentation actionRepr = repr.getAction("visibleAndInvocableAction");
        assertThat(actionRepr, isMap());

        assertThat(actionRepr.getDisabledReason(), is(nullValue()));

        final LinkRepresentation actionDetailsLink = actionRepr.getLinkWithRel(Rel.DETAILS);
View Full Code Here

        // when
        final RestfulResponse<DomainObjectRepresentation> jsonResp = RestfulResponse.ofT(resp);

        // then
        assertThat(jsonResp.getStatus(), is(HttpStatusCode.OK));
        final DomainObjectRepresentation repr = jsonResp.getEntity();

        final DomainObjectMemberRepresentation actionRepr = repr.getAction("visibleButNotInvocableAction");
        assertThat(actionRepr, isMap());

        assertThat(actionRepr.getDisabledReason(), is("Always disabled"));

        final LinkRepresentation actionDetailsLink = actionRepr.getLinkWithRel(Rel.DETAILS);
View Full Code Here

        // when
        final RestfulResponse<DomainObjectRepresentation> jsonResp = RestfulResponse.ofT(resp);

        // then
        assertThat(jsonResp.getStatus(), is(HttpStatusCode.OK));
        final DomainObjectRepresentation repr = jsonResp.getEntity();

        assertThat(repr.getAction("invisibleAction"), is(nullValue()));
    }
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;
        final int i = 999999;
        final long l = 99999999999L;
        final short s = (short)999;
        final boolean z = false;
        argRepr.mapPut("byteProperty.value", b);
        argRepr.mapPut("charProperty.value", c);
        argRepr.mapPut("doubleProperty.value", d);
        argRepr.mapPut("floatProperty.value", f);
        argRepr.mapPut("intProperty.value", i);
        argRepr.mapPut("longProperty.value", l);
        argRepr.mapPut("shortProperty.value", s);
        argRepr.mapPut("booleanProperty.value", z);
        RestfulResponse<JsonRepresentation> result = client.follow(updateLink, argRepr);
        assertThat(result.getStatus(), is(HttpStatusCode.OK));
       
        final DomainObjectRepresentation afterResp = result.getEntity().as(DomainObjectRepresentation.class);
        assertThat(afterResp.getProperty("byteProperty").getByte("value"), is(b));
        assertThat(afterResp.getProperty("charProperty").getChar("value"), is(c));
        assertThat(afterResp.getProperty("doubleProperty").getDouble("value"), is(d));
        assertThat(afterResp.getProperty("floatProperty").getFloat("value"), is(f));
        assertThat(afterResp.getProperty("intProperty").getInt("value"), is(i));
        assertThat(afterResp.getProperty("longProperty").getLong("value"), is(l));
        assertThat(afterResp.getProperty("shortProperty").getShort("value"), is(s));
        assertThat(afterResp.getProperty("booleanProperty").getBoolean("value"), is(z));
    }
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("123456789012345678");
        final java.sql.Date sqld = new java.sql.Date(new DateTime(2014,5,1, 0,0, DateTimeZone.UTC).getMillis());
        final java.sql.Time sqlt = new java.sql.Time(13,0,0);
        final java.sql.Timestamp sqlts = new java.sql.Timestamp(114,4,1,13,0,0,0);
        final java.util.Date d = new DateTime(2014,5,1, 11,45, DateTimeZone.UTC).toDate();
        final String e = "ORANGE";
        final String s = "Tangerine";
       
        argRepr.mapPut("bigDecimalProperty.value", bd);
        argRepr.mapPut("bigIntegerProperty.value", bi);
        argRepr.mapPut("javaSqlDateProperty.value", asIsoNoT(sqld)); // 1-may-2014
        argRepr.mapPut("javaSqlTimeProperty.value", asIsoOnlyT(sqlt)); // 1 pm
        argRepr.mapPut("javaSqlTimestampProperty.value", sqlts.getTime());
        argRepr.mapPut("javaUtilDateProperty.value", asIso(d));
        argRepr.mapPut("myEnum.value", e);
        argRepr.mapPut("stringProperty.value", s);
       
        final RestfulResponse<JsonRepresentation> result = client.follow(updateLink, argRepr);
        assertThat(result.getStatus(), is(HttpStatusCode.OK));
       
        final DomainObjectRepresentation afterResp = result.getEntity().as(DomainObjectRepresentation.class);
       
        assertThat(afterResp.getProperty("bigDecimalProperty").getBigDecimal("value"), is(new BigDecimal("12345678901234567.7890000000"))); // big-decimal(30,10)
        assertThat(afterResp.getProperty("bigIntegerProperty").getBigInteger("value"), is(bi));
        assertThat(afterResp.getProperty("javaSqlDateProperty").getDate("value"), is((java.util.Date)sqld));
        assertThat(afterResp.getProperty("javaSqlTimeProperty").getTime("value"), is((java.util.Date)sqlt));
        assertThat(afterResp.getProperty("javaSqlTimestampProperty").getLong("value"), is(sqlts.getTime()));
        assertThat(afterResp.getProperty("javaUtilDateProperty").getDateTime("value"), is(d));
        assertThat(afterResp.getProperty("myEnum").getString("value"), is(e));
        assertThat(afterResp.getProperty("stringProperty").getString("value"), is(s));
       
    }
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, DateTimeZone.UTC);
        final String s = "New string";
       
        argRepr.mapPut("localDateProperty.value", "2013-05-01");
        argRepr.mapPut("localDateTimeProperty.value", "2013-02-01T14:15:00Z");
        argRepr.mapPut("dateTimeProperty.value", asIso(dt.toDate()));
        argRepr.mapPut("stringProperty.value", s);

        final RestfulResponse<JsonRepresentation> result = client.follow(updateLink, argRepr);
        assertThat(result.getStatus(), is(HttpStatusCode.OK));
       
        final DomainObjectRepresentation afterResp = result.getEntity().as(DomainObjectRepresentation.class);
       
        assertThat(afterResp.getProperty("localDateProperty").getString("value"), is("2013-05-01")); // being a bit hacky here...
        assertThat(afterResp.getProperty("localDateTimeProperty").getDateTime("value"), is(ldt.toDate()));
        assertThat(afterResp.getProperty("dateTimeProperty").getDateTime("value"), is(dt.toDate()));
        assertThat(afterResp.getProperty("stringProperty").getString("value"), is(s));
    }
View Full Code Here

    private DomainObjectRepresentation getObjectRepr(final String domainType, final String instanceId) throws JsonParseException, JsonMappingException, IOException {
        final Response domainObjectResp = domainObjectResource.object(domainType, instanceId);
        final RestfulResponse<DomainObjectRepresentation> domainObjectJsonResp = RestfulResponse.ofT(domainObjectResp);
        assertThat(domainObjectJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL));

        final DomainObjectRepresentation domainObjectRepr = domainObjectJsonResp.getEntity();
        return domainObjectRepr;
    }
View Full Code Here

TOP

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

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.