Package com.cumulocity.me.rest.json

Examples of com.cumulocity.me.rest.json.JSONObject


    @Test
    public void shouldFormatWithStringFragments() throws Exception {
        representation.withID(id).with("Test_Fragment", "{\"type\":\"test\"}");
       
        JSONObject json = converter.toJson(representation.build());
       
        assertThat(json.toString()).isEqualTo("{\"Test_Fragment\":{\"type\":\"test\"},\"id\":\"testid\"}");
    }
View Full Code Here


        assertThat(json.toString()).isEqualTo("{\"Test_Fragment\":{\"type\":\"test\"},\"id\":\"testid\"}");
    }
   
    @Test
    public void shouldParseEmptyJson() throws Exception {
        Object parsed = converter.fromJson(new JSONObject("{}"));
       
        assertThat(parsed).isInstanceOf(EventRepresentation.class);
    }
View Full Code Here

        assertThat(parsed).isInstanceOf(EventRepresentation.class);
    }
   
    @Test
    public void shouldParseWithSimpleProps() throws Exception {
        JSONObject json = new JSONObject("{\"type\":\"some_type\",\"creationTime\":\"2001-01-01T00:00:01.0Z\",\"time\":\"2001-01-01T00:00:01.0Z\",\"text\":\"sample text\",\"id\":\"testid\"}");
       
        EventRepresentation parsed = (EventRepresentation) converter.fromJson(json);
       
        assertThat(parsed.getId()).isEqualTo(id);
        assertThat(parsed.getType()).isEqualTo(type);
View Full Code Here

    }
   
    @Test
    public void shouldParseWithComplexProps() throws Exception {
        when(conversionService.fromJson(jsonObject("{\"id\":\"src_id\"}"), same(ManagedObjectRepresentation.class))).thenReturn(source);
        JSONObject json = new JSONObject("{\"source\":{\"id\":\"src_id\"},\"id\":\"testid\"}");
       
        EventRepresentation parsed = (EventRepresentation) converter.fromJson(json);
       
        assertThat(parsed.getId()).isEqualTo(id);
        assertThat(parsed.getSource()).isSameAs(source);
View Full Code Here

    }
   
    @Test
    public void shouldParseWithFragment() throws Exception {
        when(conversionService.fromJson(jsonObject("{\"type\":\"test\"}"), same(TestFragment.class))).thenReturn(fragment);
        JSONObject json = new JSONObject("{\"com_cumulocity_me_rest_convert_TestFragment\":{\"type\":\"test\"},\"id\":\"testid\"}");
       
        EventRepresentation parsed = (EventRepresentation) converter.fromJson(json);
       
        assertThat(parsed.getId()).isEqualTo(id);
        assertThat(parsed.getAttrs().size()).isEqualTo(1);
View Full Code Here

        assertThat(parsed.get(TestFragment.class)).isSameAs(fragment);
    }
   
    @Test
    public void shouldParseWithStringFragment() throws Exception {
        JSONObject json = new JSONObject("{\"test_fragment\":{\"type\":\"test\"},\"id\":\"testid\"}");
       
        EventRepresentation parsed = (EventRepresentation) converter.fromJson(json);
       
        assertThat(parsed.getId()).isEqualTo(id);
        assertThat(parsed.getAttrs().size()).isEqualTo(1);
View Full Code Here

    @Test
    public void shouldConvertToJson() throws Exception {
        ManagedObjectCollectionRepresentation representation = new ManagedObjectCollectionRepresentation();
        representation.setManagedObjects(getListOfManagedObjects());
        JSONObject expectedJSON = aJSONObject().withProperty(PROP_MANAGED_OBJECTS, getJsonListManagedObjects()).build();

        JSONObject outputJSON = toJson(representation);

        assertThat(outputJSON.toString()).isEqualTo(expectedJSON.toString());
    }
View Full Code Here

        assertThat(outputJSON.toString()).isEqualTo(expectedJSON.toString());
    }

    @Test
    public void shouldConvertFromJson() throws Exception {
        JSONObject json = aJSONObject().withProperty(PROP_MANAGED_OBJECTS, getJsonListManagedObjects()).build();

        ManagedObjectCollectionRepresentation representation = fromJson(json);

        assertThat(representation).isNotNull();
        assertThat(representation.getManagedObjects()).isNotNull();
View Full Code Here

    Date lastUpdated = new Date();

    @Test
    public void shouldConvertMinimalMoFromJson() throws Exception {
        JSONObject json = minimalJsonManagedObjectRepresentation().build();

        ManagedObjectRepresentation representation = fromJson(json);

        assertThat(representation.getId()).isEqualTo(new GId(ID));
        assertThat(representation.getSelf()).isEqualTo(SELF);
View Full Code Here

        assertThat(representation.getSelf()).isEqualTo(SELF);
    }

    @Test
    public void shouldConvertChildAssetsAndDevicesFromJson() throws Exception {
        JSONObject json = minimalJsonManagedObjectRepresentation()
                .withPropertyBuilder(PROP_CHILD_ASSETS, minimalJsonObjectRepresentation())
                .withPropertyBuilder(PROP_CHILD_DEVICES, minimalJsonObjectRepresentation())
                .withPropertyBuilder(PROP_PARENTS, minimalJsonObjectRepresentation()).build();

        ManagedObjectRepresentation representation = fromJson(json);
View Full Code Here

TOP

Related Classes of com.cumulocity.me.rest.json.JSONObject

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.