Package com.cumulocity.me.rest.representation.inventory

Examples of com.cumulocity.me.rest.representation.inventory.ManagedObjectRepresentation


    }

    @Test @Ignore("unsupported on ME")
    public void createAndUpdateManagedObjectByRemovingFragment() throws Exception {
        // Given
        ManagedObjectRepresentation rep = aSampleMo().with(new Coordinate()).build();
        ManagedObjectRepresentation created = inventory.create(rep);

        // When
        created.set(null, Coordinate.class);
        GId id = created.getId();
        created.setId(null);
        created.setLastUpdated(null);
        ManagedObjectRepresentation updated = inventory.getManagedObject(id).update(created);

        // Then
        assertThat(updated.getId()).isNotNull();
        assertThat(updated.get(Coordinate.class)).isNull();
    }
View Full Code Here


    }

    @Test
    public void tryToGetNonExistentManagedObject() throws Exception {
        // Given
        ManagedObjectRepresentation rep = aSampleMo().withID(new GId("1")).build();

        // Then
        exception.expect(sdkException(HTTP_NOT_FOUND));

        // When
        inventory.getManagedObject(rep.getId()).get();
    }
View Full Code Here

    }

    @Test
    public void tryToDeleteNonExistentManagedObject() throws Exception {
        // Given
        ManagedObjectRepresentation rep = aSampleMo().withID(new GId("1")).build();

        // Then
        exception.expect(sdkException(HTTP_NOT_FOUND));

        // When
        inventory.getManagedObject(rep.getId()).delete();
    }
View Full Code Here

    }
   
    private void deleteMOs(List mosOn1stPage) throws SDKException {
        Iterator iterator = mosOn1stPage.iterator();
        while (iterator.hasNext()) {
        ManagedObjectRepresentation mo  = (ManagedObjectRepresentation) iterator.next();
            inventoryApi.getManagedObject(mo.getId()).delete();
        }
    }
View Full Code Here

    }

    @Test
    public void tryToUpdateNonExistentManagedObject() throws Exception {
        // Given
        ManagedObjectRepresentation rep = aSampleMo().build();

        // Then
        exception.expect(sdkException(HTTP_NOT_FOUND));

        // When
View Full Code Here

    }

    @Test
    public void getAllWhen2ManagedObjectArePresent() throws Exception {
        // Given
        ManagedObjectRepresentation rep1 = aSampleMo().withName("MO1").build();
        ManagedObjectRepresentation rep2 = aSampleMo().withName("MO2").build();

        // When
        inventory.create(rep1);
        inventory.create(rep2);
View Full Code Here

    }

    @Test
    public void addGetAndRemoveChildDevices() throws Exception {
        // Given
        ManagedObjectRepresentation parent = inventory.create(aSampleMo().withName("parent1").build());
        ManagedObjectRepresentation child1 = inventory.create(aSampleMo().withName("child11").build());
        ManagedObjectRepresentation child2 = inventory.create(aSampleMo().withName("child21").build());

        ManagedObjectReferenceRepresentation childRef1 = anMoRefRepresentationLike(MO_REF_REPRESENTATION).withMo(child1).build();
        ManagedObjectReferenceRepresentation childRef2 = anMoRefRepresentationLike(MO_REF_REPRESENTATION).withMo(child2).build();

        // When
        ManagedObject parentMo = inventory.getManagedObject(parent.getId());
        parentMo.addChildDevice(childRef1);
        parentMo.addChildDevice(childRef2);

        // Then
        ManagedObjectReferenceCollectionRepresentation refCollection = (ManagedObjectReferenceCollectionRepresentation) inventory.getManagedObject(parent.getId()).getChildDevices().get();

        List refs = refCollection.getReferences();
        Set<GId> childDeviceIDs = asSet(
                ((ManagedObjectReferenceRepresentation) refs.get(0)).getManagedObject().getId(),
                ((ManagedObjectReferenceRepresentation) refs.get(1)).getManagedObject().getId());
        assertThat(childDeviceIDs, is(asSet(child1.getId(), child2.getId())));

        // When
        parentMo.deleteChildDevice(child1.getId());
        parentMo.deleteChildDevice(child2.getId());

        // Then
        ManagedObjectReferenceCollectionRepresentation allChildDevices = (ManagedObjectReferenceCollectionRepresentation) inventory.getManagedObject(parent.getId()).getChildDevices().get();
        assertThat(allChildDevices.getReferences().size()).isEqualTo(0);
    }
View Full Code Here

    }

    @Test
    public void getPagedChildDevices() throws Exception {
        // Given
        ManagedObjectRepresentation parent = inventory.create(aSampleMo().withName("parent").build());
        ManagedObject parentMo = inventory.getManagedObject(parent.getId());

        for (int i = 0; i < platform.getPageSize() + 1; i++) {
            ManagedObjectRepresentation child = inventory.create(aSampleMo().withName("child" + i).build());
            ManagedObjectReferenceRepresentation childRef = anMoRefRepresentationLike(MO_REF_REPRESENTATION).withMo(child).build();
            parentMo.addChildDevice(childRef);
        }

        // When
View Full Code Here

    }

    @Test
    public void addGetAndRemoveChildAssets() throws Exception {
        // Given
        ManagedObjectRepresentation parent = inventory.create(aSampleMo().withName("parent").build());
        ManagedObjectRepresentation child1 = inventory.create(aSampleMo().withName("child1").build());
        ManagedObjectRepresentation child2 = inventory.create(aSampleMo().withName("child2").build());

        ManagedObjectReferenceRepresentation childRef1 = anMoRefRepresentationLike(MO_REF_REPRESENTATION).withMo(child1).build();
        ManagedObjectReferenceRepresentation childRef2 = anMoRefRepresentationLike(MO_REF_REPRESENTATION).withMo(child2).build();

        // When
        ManagedObject parentMo = inventory.getManagedObject(parent.getId());
        parentMo.addChildAssets(childRef1);
        parentMo.addChildAssets(childRef2);

        // Then
        ManagedObjectReferenceCollectionRepresentation refCollection = (ManagedObjectReferenceCollectionRepresentation) inventory.getManagedObject(parent.getId()).getChildAssets().get();

        List refs = refCollection.getReferences();
        Set<GId> childDeviceIDs = asSet(
                ((ManagedObjectReferenceRepresentation) refs.get(0)).getManagedObject().getId(),
                ((ManagedObjectReferenceRepresentation) refs.get(1)).getManagedObject().getId());
       
        assertThat(childDeviceIDs, is(asSet(child1.getId(), child2.getId())));

        // When
        parentMo.deleteChildAsset(child1.getId());
        parentMo.deleteChildAsset(child2.getId());

        // Then
        ManagedObjectReferenceCollectionRepresentation allChildDevices = (ManagedObjectReferenceCollectionRepresentation) inventory.getManagedObject(parent.getId()).getChildAssets().get();
        assertThat(allChildDevices.getReferences().size()).isEqualTo(0);
    }
View Full Code Here

    }

    @Test
    public void getPagedChildAssets() throws Exception {
        // Given
        ManagedObjectRepresentation parent = inventory.create(aSampleMo().withName("parent").build());
        ManagedObject parentMo = inventory.getManagedObject(parent.getId());

        for (int i = 0; i < platform.getPageSize() + 1; i++) {
            ManagedObjectRepresentation child = inventory.create(aSampleMo().withName("child" + i).build());
            ManagedObjectReferenceRepresentation childRef = anMoRefRepresentationLike(MO_REF_REPRESENTATION).withMo(child).build();
            parentMo.addChildAssets(childRef);
        }

        // When
View Full Code Here

TOP

Related Classes of com.cumulocity.me.rest.representation.inventory.ManagedObjectRepresentation

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.