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