Package com.cumulocity.rest.representation.inventory

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


    }

    @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();

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

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

        List<ManagedObjectReferenceRepresentation> refs = refCollection.getReferences();
        Set<GId> childDeviceIDs = asSet(refs.get(0).getManagedObject().getId(), 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 = inventory.getManagedObject(
                parent.getId()).getChildDevices().get();
        assertEquals(0, allChildDevices.getReferences().size());
View Full Code Here


    }

    @When("I query all Events by source '(\\d+)' and type '([^']*)'$")
    public void iQueryAllBySourceAndType(int index, String type) throws SDKException, ClassNotFoundException {
        try {
            ManagedObjectRepresentation mo = managedObject;
            EventFilter filter = new EventFilter().bySource(mo).byType(type);
            collection = eventApi.getEventsByFilter(filter).get();
        } catch (SDKException ex) {
            status = ex.getHttpStatus();
        }
View Full Code Here

    }
   
    @When("I query all Events by source '(\\d+)' and time '([^']*)'$")
    public void iQueryAllBySourceAndTime(int index, String time) throws SDKException, ClassNotFoundException {
        try {
            ManagedObjectRepresentation mo = managedObject;
            EventFilter filter = new EventFilter().byDate(DateConverter.string2Date(time), DateConverter.string2Date(time));
            collection = eventApi.getEventsByFilter(filter).get();
        } catch (SDKException ex) {
            status = ex.getHttpStatus();
        }
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);
        }
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();

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

        // Then
        ManagedObjectReferenceCollectionRepresentation refCollection = inventory.getManagedObject(
                parent.getId()).getChildAssets().get();
        List<ManagedObjectReferenceRepresentation> refs = refCollection.getReferences();
        Set<GId> childDeviceIDs = asSet(refs.get(0).getManagedObject().getId(), 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 = inventory.getManagedObject(
                parent.getId()).getChildAssets().get();
        assertEquals(0, allChildDevices.getReferences().size());
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);
        }
View Full Code Here

    }

    @Test
    public void bulkQuery() throws Exception {
        // Given
        ManagedObjectRepresentation mo1 = inventory.create(aSampleMo().withName("MO1").build());
        ManagedObjectRepresentation mo3 = inventory.create(aSampleMo().withName("MO3").build());
        inventory.create(aSampleMo().withName("MO2").build());

        // When
        ManagedObjectCollectionRepresentation moCollection = inventory.getManagedObjectsByFilter(new InventoryFilter().byIds(asList(mo3.getId(), mo1.getId()))).get();

        // Then
        List<ManagedObjectRepresentation> mos = moCollection.getManagedObjects();
        assertThat(mos.size(), is(2));
        assertThat(mos.get(0).getName(), is("MO3"));
View Full Code Here

    @Test
    public void createAndDeleteManagedObject() throws Exception {
        // Given
        ExternalIDRepresentation xtIDRep = createExternalIDRep(XT_ID, XT_TYPE);

        ManagedObjectRepresentation moRep1 = createManagedObjectAndAssignExternalID("object1", xtIDRep);
        ManagedObject retrievedMO1 = getManageObjectByExternalID(getExternalIDBoundToGId(moRep1.getId()));
        retrievedMO1.delete();

        // When
        ManagedObjectRepresentation moRep2 = createManagedObjectAndAssignExternalID("object2", xtIDRep);
        ManagedObject retrievedMO2 = getManageObjectByExternalID(getExternalIDBoundToGId(moRep2.getId()));

        //Then
        assertThat(retrievedMO2, is(notNullValue()));
        assertThat(retrievedMO2.get().getName(), is("object2"));
View Full Code Here

        //cleanup
        retrievedMO2.delete();
    }

    private ManagedObjectRepresentation createManagedObjectAndAssignExternalID(String name, ExternalIDRepresentation xtIDRep) throws SDKException {
        ManagedObjectRepresentation originalMO = createManagedObject(name);
        assignExternalID(originalMO, xtIDRep);
        return originalMO;
    }
View Full Code Here

        xtIDRep.setType(type);
        return xtIDRep;
    }

    private ManagedObjectRepresentation createManagedObject(String name) throws SDKException {
        ManagedObjectRepresentation moRep = new ManagedObjectRepresentation();
        moRep.setName(name);
        return inventory.create(moRep);
    }
View Full Code Here

TOP

Related Classes of com.cumulocity.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.