@Test
public void testDeleteCI() {
final DiagramEditor de = TestUtil.loadFile("test.dispel");
Diagram d = de.getDiagramTypeProvider().getDiagram();
Pair<Shape, EObject> ciPair = TestUtil.getLiteralWithName(
"\"Hello World\"", d);
assertNotNull(ciPair.getLeft());
assertNotNull(ciPair.getRight());
assertNotNull(Utility.getParentConnectionStatement(ciPair.getRight()));
assertNotNull(Utility.getParentConnectionStatement(ciPair.getRight()
).eContainer());
//Take a note of any outgoing connections
List<Connection> cons = new ArrayList<Connection>();
for (Anchor a : ciPair.getLeft().getAnchors()) {
cons.addAll(a.getOutgoingConnections());
}
//Just make sure they're linked
for (Connection c : cons) {
assertNotNull(c.getParent());
}
final Shape deleteShape = ciPair.getLeft();
//Have to async call delete within transaction, then use swtbot to
//confirm
asyncExec((new VoidResult() {
@Override
public void run() {
de.getEditingDomain().getCommandStack().execute(
new RecordingCommand(de.getEditingDomain()) {
@Override
protected void doExecute() {
IDiagramTypeProvider dtp =
de.getDiagramTypeProvider();
IFeatureProvider fp = dtp.getFeatureProvider();
final DeleteContext dc = new DeleteContext(
deleteShape);
final IDeleteFeature df =
de.getDiagramTypeProvider(
).getFeatureProvider().getDeleteFeature(
dc);
assert(df.canDelete(dc));
df.delete(dc);
}});
}}));
SWTBotShell shell = mBot.shell("Confirm Delete");
shell.activate();
mBot.button("Yes").click();
mBot.sleep(1000);
mBot.menu("File").menu("Save").click();
mBot.sleep(1000);
//Make sure deleted from diagram and model
assertFalse(d.getChildren().contains(deleteShape));
assertNull(Utility.getParentConnectionStatement(ciPair.getRight()
).eContainer());
//Outgoing connections should be dead too
for (Connection c : cons) {
assertNull(c.getParent());