public void testAttributeDerive() { AstOclConstraintFactory factory1 = AstOclConstraintFactoryManager.getInstance(umlModel.getOclPackage()); AstOclModelElementFactory factory2 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); IntegerLiteralExp exp1 = factory2.createIntegerLiteralExp(100, getClassifier("Integer")); ExpressionInOcl expInOcl = factory1.createExpressionInOcl("name", getClassifier("Film"), exp1); OclAttributeDeriveConstraint constraint = (OclAttributeDeriveConstraint)factory1.createAttributeDeriveConstraint("test.ocl", getClassifier("Film"), getClassifier("Film").lookupAttribute("rentalFee"), expInOcl); Assert.AreEqual("derive: 100", constraint.ToString()); OclConstraint c = getClassifier("Film").getDeriveConstraint("rentalFee"); Assert.AreEqual(constraint, c); CoreAttribute attrib = getClassifier("Film").lookupAttribute("rentalFee"); Assert.IsNotNull(attrib); Assert.AreEqual(expInOcl, attrib.getDerivedValueExpression()); Assert.IsTrue(attrib.isDerived()); getClassifier("Film").deleteAllConstraintsForSource("test.ocl"); Assert.IsNull(getClassifier("Film").getDeriveConstraint("rentalFee")); }
public void testPrePost() { AstOclConstraintFactory factory1 = AstOclConstraintFactoryManager.getInstance(umlModel.getOclPackage()); AstOclModelElementFactory factory2 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); BooleanLiteralExp exp1 = factory2.createBooleanLiteralExp(true, getClassifier("Boolean")); ExpressionInOcl expInOcl1 = factory1.createExpressionInOcl("name", getClassifier("Film"), exp1); BooleanLiteralExp exp2 = factory2.createBooleanLiteralExp(false, getClassifier("Boolean")); ExpressionInOcl expInOcl2 = factory1.createExpressionInOcl("name", getClassifier("Film"), exp2); List <object> parms = new List <object>(); parms.Add(getClassifier("Integer")); CoreOperation oper = getClassifier("Film").lookupOperation("getRentalFee", parms); OclPrePostConstraint constraint = (OclPrePostConstraint)factory1.createPrePostConstraint("test.ocl", oper); OclConstraint preConstraint = factory1.createPreConstraint(constraint, "test.ocl", "myPre", oper, expInOcl1); OclConstraint postConstraint = factory1.createPostConstraint(constraint, "test.ocl", "myPost", oper, expInOcl2); Assert.AreEqual("pre myPre: True", preConstraint.ToString()); Assert.AreEqual("post myPost: False", postConstraint.ToString()); Assert.IsTrue(oper.getSpecifications().Contains(constraint)); OclPrePostConstraint example = (OclPrePostConstraint)oper.getSpecifications()[0]; Assert.IsTrue(example.getPreConditions().Contains((OclPreConstraint)preConstraint)); Assert.IsTrue(example.getPostConditions().Contains((OclPostConstraint)postConstraint)); oper.deleteAllConstraintsForSource("test.ocl"); Assert.AreEqual(0, oper.getSpecifications().Count); }
private void deleteAllConstraintsForHashMap( string sourceName, Dictionary <string, OclConstraint> map) { List <object> toBeRemoved = new List <object>(); foreach (KeyValuePair <string, OclConstraint> element in map) { OclConstraint constraint = element.Value; if (constraint.getSource().Equals(sourceName)) { toBeRemoved.Add(element.Key); } } foreach (string element in toBeRemoved) { map.Remove(element); } }
/** * @param constraint The constraint to set. */ public void setConstraint(OclConstraint constraint) { this.constraint = constraint; }
public void addOwnerToSource( OclConstraint constraint, OclConstraintOwner owner) { addOwnerToSource(constraint.getSource(), owner); }