blob: b3f449e3271f74219b92a759ed13e4dbe4e75bde [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2015, 2019 SAP SE
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* mwenz - Bug 470455 - Difficulty in creating associations
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.graphiti.ui.internal.command;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.IFeature;
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.ICreateService;
import org.junit.Test;
public class CreateConnectionCommandTest {
/*
* Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=470455
*/
@Test
public void whenInnerShapeHasNoAnchor_andCanStartConnection_thenReturnTrue() {
ICreateService createService = Graphiti.getCreateService();
Diagram diagram = createService.createDiagram("dummy", "name");
ContainerShape containerShape = createService.createContainerShape(diagram, true);
createService.createChopboxAnchor(containerShape);
createService.createRectangle(containerShape);
ContainerShape anotherShape = createService.createContainerShape(containerShape, true);
createService.createRectangle(anotherShape);
Shape textShape = createService.createShape(anotherShape, true);
createService.createText(textShape);
ICreateConnectionFeature createConnectionFeature = new AbstractCreateConnectionFeature(null, "Test", "Test") {
@Override
public Connection create(ICreateConnectionContext context) {
return null;
}
@Override
public boolean canStartConnection(ICreateConnectionContext context) {
return true;
}
@Override
public boolean canCreate(ICreateConnectionContext context) {
return false;
}
};
ArrayList<IFeature> featureList = new ArrayList<IFeature>(1);
featureList.add(createConnectionFeature);
CreateConnectionCommand createConnectionCommand = new CreateConnectionCommand(null, textShape, featureList);
assertTrue(createConnectionCommand.canStartConnection());
}
}