use of org.osate.ge.tests.unit.TestBusinessObject in project osate2 by osate.
the class DiagramUpdaterTest method testDockArea.
// Test that element docking are works as expected
@Test
public void testDockArea() {
// Assign a Docking Position to an Element
final TestBusinessObject testBoParent = testModel.getModel().children[0];
final TestBusinessObject testBo = testBoParent.children[2];
testBo.setDefaultDockingPosition(DockingPosition.LEFT);
// Update the diagram and assign positions
diagramUpdater.updateDiagram(diagram);
assignPositions(diagram.getChildren());
// Check that the contents of test diagram element have the appropriate docking area
checkElements(diagram.getChildren(), testModel.getModel());
// Check that Changing the Docking Area and updating the diagram does not reset the docking area.
final DiagramElement dockableDiagramElement = diagram.getChildByRelativeReference(testBoParent.getRelativeReference()).getChildByRelativeReference(testBo.getRelativeReference());
assertThat(dockableDiagramElement.getDockArea(), is(equalTo(DockArea.fromDockingPosition(testBo.getDefaultDockingPosition()))));
final DockArea newDockArea = DockArea.fromDockingPosition(DockingPosition.RIGHT);
diagram.modify("Set Dock Area", m -> m.setDockArea(dockableDiagramElement, newDockArea));
diagramUpdater.updateDiagram(diagram);
assertThat(dockableDiagramElement.getDockArea(), is(equalTo(newDockArea)));
}
use of org.osate.ge.tests.unit.TestBusinessObject in project osate2 by osate.
the class DiagramUpdaterTest method checkElements.
private static void checkElements(final Collection<DiagramElement> elements, final TestBusinessObject parentBO, final DockArea parentDockArea, final EnumSet<CheckFlag> flags) {
// Check the number of elements in the model
assertThat(elements.size(), is(equalTo(parentBO.children.length)));
// Check that each element in the model is in the element set
for (final TestBusinessObject child : parentBO.children) {
boolean foundBO = false;
final RelativeBusinessObjectReference modelChildRef = child.getRelativeReference();
for (final DiagramElement e : elements) {
final RelativeBusinessObjectReference elementRef = ((TestBusinessObject) e.getBusinessObject()).getRelativeReference();
if (elementRef.equals(modelChildRef)) {
foundBO = true;
break;
}
}
assertThat("The diagram does not contain an element for the business object: " + child, foundBO);
}
// Finish checking each element
for (final DiagramElement e : elements) {
// Check the position of the element
final TestBusinessObject testBo = (TestBusinessObject) e.getBusinessObject();
if (flags.contains(CheckFlag.CHECK_POSITION)) {
assertThat(e.getPosition(), is(equalTo(testBo.getTestPosition())));
}
final DockArea dockArea = getExpectedDockArea(testBo, parentDockArea);
if (flags.contains(CheckFlag.CHECK_DOCK_AREA)) {
assertThat(e.getDockArea(), is(equalTo(dockArea)));
}
// Check the children
checkElements(e.getChildren(), (TestBusinessObject) e.getBusinessObject(), dockArea, flags);
}
}
use of org.osate.ge.tests.unit.TestBusinessObject in project osate2 by osate.
the class DiagramUpdaterTest method testDiagramElementReplaceBusinessObjectWithNew.
// Test that when a business object is replaced by a new one with a different reference that the diagram elements are updated appropriately
@Test
public void testDiagramElementReplaceBusinessObjectWithNew() {
diagramUpdater.updateDiagram(diagram);
assignPositions(diagram.getChildren());
checkElements(diagram.getChildren(), testModel.getModel());
final TestBusinessObject owner = testModel.getModel().children[1];
final TestBusinessObject newBusinessObject = newBO(42);
owner.children[0] = newBusinessObject;
diagramUpdater.updateDiagram(diagram);
// Get the new element
final DiagramElement element = diagram.getChildByRelativeReference(owner.getRelativeReference()).getChildByRelativeReference(newBusinessObject.getRelativeReference());
assertThat(element, is(notNullValue()));
assertThat(element.getPosition(), is(nullValue()));
assertThat(element.getBusinessObject(), is(sameInstance(newBusinessObject)));
final DiagramElement e = diagram.getChildByRelativeReference(owner.getRelativeReference()).getChildByRelativeReference(newBusinessObject.getRelativeReference());
diagram.modify("Set Position", m -> m.setPosition(e, newBusinessObject.getTestPosition()));
checkElements(diagram.getChildren(), testModel.getModel());
}
use of org.osate.ge.tests.unit.TestBusinessObject in project osate2 by osate.
the class DiagramUpdaterTest method testDiagramElementUpdateBusinessObject.
// Test that when a business object is replace by a new one with the same reference.
@Test
public void testDiagramElementUpdateBusinessObject() {
diagramUpdater.updateDiagram(diagram);
assignPositions(diagram.getChildren());
checkElements(diagram.getChildren(), testModel.getModel());
final TestBusinessObject owner = testModel.getModel().children[1];
// Create a copy with the same value. It is assumed that this element does not container children
final TestBusinessObject newBusinessObject = newBO(owner.children[0].value);
owner.children[0] = newBusinessObject;
diagramUpdater.updateDiagram(diagram);
final DiagramElement element = diagram.getChildByRelativeReference(owner.getRelativeReference()).getChildByRelativeReference(newBusinessObject.getRelativeReference());
assertThat(element.getBusinessObject(), is(sameInstance(newBusinessObject)));
checkElements(diagram.getChildren(), testModel.getModel());
}
use of org.osate.ge.tests.unit.TestBusinessObject in project osate2 by osate.
the class DiagramUpdaterTest method assignPositions.
private static void assignPositions(final DiagramModification m, final Collection<DiagramElement> elements) {
for (final DiagramElement element : elements) {
final TestBusinessObject bo = (TestBusinessObject) element.getBusinessObject();
m.setPosition(element, bo.getTestPosition());
// Assign positions to children
assignPositions(m, element.getChildren());
}
}
Aggregations