Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/junit/plugins/uml/org.eclipse.papyrus.diagram.stereotypeproperty.tests/src/org/eclipse/papyrus/diagram/stereotypeproperty/TestStereotypeApplication.java')
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.diagram.stereotypeproperty.tests/src/org/eclipse/papyrus/diagram/stereotypeproperty/TestStereotypeApplication.java132
1 files changed, 127 insertions, 5 deletions
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.diagram.stereotypeproperty.tests/src/org/eclipse/papyrus/diagram/stereotypeproperty/TestStereotypeApplication.java b/tests/junit/plugins/uml/org.eclipse.papyrus.diagram.stereotypeproperty.tests/src/org/eclipse/papyrus/diagram/stereotypeproperty/TestStereotypeApplication.java
index 4c88dd3f61a..cbe1453b00b 100644
--- a/tests/junit/plugins/uml/org.eclipse.papyrus.diagram.stereotypeproperty.tests/src/org/eclipse/papyrus/diagram/stereotypeproperty/TestStereotypeApplication.java
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.diagram.stereotypeproperty.tests/src/org/eclipse/papyrus/diagram/stereotypeproperty/TestStereotypeApplication.java
@@ -34,10 +34,12 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IShapeCompartmentEditPa
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.PackageEditPart;
import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.common.figure.node.ClassifierFigure;
import org.eclipse.papyrus.uml.diagram.common.figure.node.EditingFlowPage;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeConpartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.common.figure.node.PackageFigure;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeMultilinePropertyEditPart;
import org.eclipse.papyrus.uml.extensionpoints.profile.RegisteredProfile;
import org.eclipse.papyrus.uml.extensionpoints.utils.Util;
@@ -53,13 +55,22 @@ import org.junit.Test;
public class TestStereotypeApplication extends AbstractPapyrusTestCase {
+ protected static final String ST_LEFT = String.valueOf("\u00AB");
+
+ protected static final String ST_RIGHT = String.valueOf("\u00BB");
private static final String TEST_PROFILE_STEREOTYPE1 = "testProfile::Stereotype1";
@Test
- public void testToManageModel() {
+ public void testStereotypeApplicationOnClass() {
testToCreateANode(UMLElementTypes.Class_2008);
}
+
+ @Test
+ public void testStereotypeApplicationOnPackage() {
+ testToCreateAPackage(UMLElementTypes.Package_2007);
+
+ }
/**
* Test to create a node.
@@ -125,7 +136,7 @@ public class TestStereotypeApplication extends AbstractPapyrusTestCase {
for(int i = 0; i < NotationClass1.getTransientChildren().size(); i++) {
View view = (View) NotationClass1.getTransientChildren().get(i);
- if(view.getType().equals(AppliedStereotypeConpartmentEditPart.ID)) {
+ if(view.getType().equals(AppliedStereotypeCompartmentEditPart.ID)) {
appliedStereotypeCompartmentNotation = view;
}
if(view.getType().equals(IShapeCompartmentEditPart.VIEW_TYPE)) {
@@ -149,7 +160,7 @@ public class TestStereotypeApplication extends AbstractPapyrusTestCase {
//get the label
org.eclipse.draw2d.Label stereotypeLabel=((ClassifierFigure)nodePlate.getChildren().get(0)).getStereotypesLabel();
assertTrue( "stereotype label must be not null" ,stereotypeLabel!=null);
- assertTrue( "text of stereotype label be equals to «stereotype1» " ,stereotypeLabel.getText().equals("«stereotype1»"));
+ assertTrue( "text of stereotype label be equals to" +ST_LEFT+"stereotype1"+ST_RIGHT ,stereotypeLabel.getText().equals(ST_LEFT+"stereotype1"+ST_RIGHT));
}
{//test display of property of stereotype in compartment
@@ -162,7 +173,7 @@ public class TestStereotypeApplication extends AbstractPapyrusTestCase {
stereotypePropertyView=(View)appliedStereotypeCompartmentNotation.getChildren().get(0);
assertNotNull( "the view of the applied stereotype property must be created", stereotypePropertyView);
//look for the editpart that represents the property of applied stereotype
- stereotypeCompartmentEdipart=(GraphicalEditPart)classEditPart.getChildBySemanticHint(AppliedStereotypeConpartmentEditPart.ID);
+ stereotypeCompartmentEdipart=(GraphicalEditPart)classEditPart.getChildBySemanticHint(AppliedStereotypeCompartmentEditPart.ID);
stereotypePropertyEdipart=(GraphicalEditPart)stereotypeCompartmentEdipart.getChildBySemanticHint(AppliedStereotypeMultilinePropertyEditPart.ID);
assertNotNull( "the editpart of the applied stereotype compartment must be created", stereotypeCompartmentEdipart);
assertNotNull( "the editpart of the applied stereotype property must be created", stereotypePropertyEdipart);
@@ -188,4 +199,115 @@ public class TestStereotypeApplication extends AbstractPapyrusTestCase {
}
+
+ /**
+ * Test to create a node.
+ *
+ * @param type
+ * the type
+ */
+ public void testToCreateAPackage(IElementType type) {
+
+ //VARIABLES
+ org.eclipse.uml2.uml.Package package1=null;
+ //stereotype that is applied on class1
+ Stereotype stereotypeTest=null;
+ //view of the class
+ View Notationpackage1=null;
+ //editpart of class1
+ GraphicalEditPart package1EditPart=null;
+ //compartment of stereotype
+ View appliedStereotypeCompartmentNotation = null;
+ //compartment Shape
+ View shapeCompartmentView=null;
+ //the view of the applied stereotype property
+ View stereotypePropertyView=null;
+ GraphicalEditPart stereotypeCompartmentEdipart=null;
+ GraphicalEditPart stereotypePropertyEdipart=null;
+
+ //CREATION
+ assertTrue(CREATION + INITIALIZATION_TEST, getDiagramEditPart().getChildren().size() == 0);
+
+ assertTrue(CREATION + INITIALIZATION_TEST, getRootSemanticModel().getOwnedElements().size() == 1);
+ //1 element element due to the reference to the profile
+ assertTrue(CREATION + INITIALIZATION_TEST, ((Model)getRootSemanticModel()).getAllAppliedProfiles().size() == 1);
+
+
+ {//execution of the command
+ CreateViewRequest requestcreation = CreateViewRequestFactory.getCreateShapeRequest(type, getDiagramEditPart().getDiagramPreferencesHint());
+ Command command = getDiagramEditPart().getCommand(requestcreation);
+ assertNotNull(CREATION + COMMAND_NULL, command);
+ assertTrue(CREATION + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
+ assertTrue("CREATION: " + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true);
+ diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
+ assertTrue(CREATION + TEST_THE_EXECUTION, getRootView().getChildren().size() == 1);
+ }
+
+ //get the created Class
+ package1 = (org.eclipse.uml2.uml.Package)((org.eclipse.uml2.uml.Package)getRootSemanticModel()).getPackagedElement("Package1");
+ assertNotNull("created class must be not null", package1 );
+ //look for the editpart that the class
+ package1EditPart = (PackageEditPart)getDiagramEditPart().getChildren().get(0);
+ //test if stereotype can be applied
+ assertTrue("stereotype1 must be applicable on class1", package1.getApplicableStereotype(TEST_PROFILE_STEREOTYPE1) != null);
+
+ {// execution of the application of the stereotype
+ ArrayList<Stereotype> stereotypeslist = new ArrayList<Stereotype>();
+ stereotypeslist.add(package1.getApplicableStereotype(TEST_PROFILE_STEREOTYPE1));
+ ApplyStereotypeCommand applyStereotypeCommand = new ApplyStereotypeCommand(((Element)package1EditPart.resolveSemanticElement()), stereotypeslist, diagramEditor.getEditingDomain());
+ diagramEditor.getEditingDomain().getCommandStack().execute(applyStereotypeCommand);
+ assertTrue("No applied stereotype found on the element ", package1.getAppliedStereotypes().size() != 0);
+ }
+
+ //look for the applied stereotype compartment
+ Notationpackage1=package1EditPart.getNotationView();
+
+ for(int i = 0; i < Notationpackage1.getTransientChildren().size(); i++) {
+ View view = (View) Notationpackage1.getTransientChildren().get(i);
+ if(view.getType().equals(AppliedStereotypeCompartmentEditPart.ID)) {
+ appliedStereotypeCompartmentNotation = view;
+ }
+ if(view.getType().equals(IShapeCompartmentEditPart.VIEW_TYPE)) {
+ shapeCompartmentView= view;
+ }
+ }
+ // the mechanism of stereotype display is running.
+ //the thread is synchronous
+ assertTrue( "No stereotype Compartment found in the notation", appliedStereotypeCompartmentNotation != null);
+ assertTrue( "No stereotype shape Compartment found in the notation", shapeCompartmentView != null);
+
+ //now display stereotypes
+ stereotypeTest=package1.getAppliedStereotypes().get(0);
+
+ {//display stereotype1
+ RecordingCommand displayStereotypeCommand= AppliedStereotypeHelper.getAppliedStereotypeToDisplayCommand(diagramEditor.getEditingDomain(), Notationpackage1,stereotypeTest.getQualifiedName() , UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION);
+
+ diagramEditor.getEditingDomain().getCommandStack().execute(displayStereotypeCommand);
+ org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SVGNodePlateFigure nodePlate=(org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SVGNodePlateFigure)((BorderedNodeFigure)package1EditPart.getFigure()).getChildren().get(0);
+
+ //get the label
+ org.eclipse.draw2d.Label stereotypeLabel=((PackageFigure)nodePlate.getChildren().get(0)).getStereotypesLabel();
+ assertTrue( "stereotype label must be not null" ,stereotypeLabel!=null);
+ assertTrue( "text of stereotype label be equals to "+ST_LEFT+"stereotype1"+ST_RIGHT ,stereotypeLabel.getText().equals(ST_LEFT+"stereotype1"+ST_RIGHT));
+ }
+
+ {//test display of property of stereotype in compartment
+ RecordingCommand displayPropertyStereotypeCommand= AppliedStereotypeHelper.getAddAppliedStereotypePropertiesCommand(diagramEditor.getEditingDomain(), Notationpackage1,stereotypeTest.getQualifiedName()+".testInt");
+ diagramEditor.getEditingDomain().getCommandStack().execute(displayPropertyStereotypeCommand);
+
+ //the compartment must be visible
+ assertTrue( "the compartment must be visible", appliedStereotypeCompartmentNotation.isVisible()==true);
+ //look for view that represents the property of the applied stereotype
+ stereotypePropertyView=(View)appliedStereotypeCompartmentNotation.getChildren().get(0);
+ assertNotNull( "the view of the applied stereotype property must be created", stereotypePropertyView);
+ //look for the editpart that represents the property of applied stereotype
+ stereotypeCompartmentEdipart=(GraphicalEditPart)package1EditPart.getChildBySemanticHint(AppliedStereotypeCompartmentEditPart.ID);
+ stereotypePropertyEdipart=(GraphicalEditPart)stereotypeCompartmentEdipart.getChildBySemanticHint(AppliedStereotypeMultilinePropertyEditPart.ID);
+ assertNotNull( "the editpart of the applied stereotype compartment must be created", stereotypeCompartmentEdipart);
+ assertNotNull( "the editpart of the applied stereotype property must be created", stereotypePropertyEdipart);
+ EditingFlowPage textarea=(EditingFlowPage)stereotypePropertyEdipart.getFigure();
+ assertTrue( "text of stereotype label be equals to "+ST_LEFT+"stereotype1"+ST_RIGHT ,((TextFlowEx)textarea.getChildren().get(0)).getText().equals("testInt=0"));
+ }
+ }
+
}

Back to the top