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