public void testPre_01() { doTestManyContextOK("context Film::getTapes() : Set(Tape) pre myPre: tapes->size() > 0 ", getCurrentMethodName()); CoreClassifier film = (CoreClassifier)environment.lookup("Film"); CoreOperation operation = film.lookupOperation("getTapes", null); Assert.AreEqual(1, new List <object>(operation.getSpecifications()).Count); OclPrePostConstraint constraint = (OclPrePostConstraint) new List <object>(operation.getSpecifications())[0]; Assert.AreEqual(1, new List <object>(constraint.getPreConditions()).Count); Assert.AreEqual("myPre", ((OclPreConstraint) new List <object>(constraint.getPreConditions())[0]).getName()); }
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); }
public void testPrePost_03() { doTestManyContextOK("context Film::getTapes() : Set(Tape) pre myPre0: tapes->size() > 0 pre anotherPre0: tapes->size() < 10 post myPost0: result = tapes->select(rentalFee > 10) post anotherPost0: result = tapes->select(rentalFee > 10) " + "context Film::getTapes() : Set(Tape) pre myPre1: tapes->size() > 0 pre anotherPre1: tapes->size() < 10 post myPost1: result = tapes->select(rentalFee > 10) post anotherPost1: result = tapes->select(rentalFee > 10) ", getCurrentMethodName()); CoreClassifier film = (CoreClassifier)environment.lookup("Film"); CoreOperation operation = film.lookupOperation("getTapes", null); Assert.AreEqual(2, new List <object>(operation.getSpecifications()).Count); for (int i = 0; i < 2; i++) { OclPrePostConstraint constraint = (OclPrePostConstraint) new List <object>(new List <object>(operation.getSpecifications()))[i]; Assert.AreEqual(2, constraint.getPreConditions().Count); Assert.AreEqual("myPre" + i, ((OclPreConstraint) new List <object>(constraint.getPreConditions())[0]).getName()); Assert.AreEqual("anotherPre" + i, ((OclPreConstraint) new List <object>(constraint.getPreConditions())[1]).getName()); Assert.AreEqual(2, new List <object>(constraint.getPostConditions()).Count); Assert.AreEqual("myPost" + i, ((OclPostConstraint) new List <object>(constraint.getPostConditions())[0]).getName()); Assert.AreEqual("anotherPost" + i, ((OclPostConstraint) new List <object>(constraint.getPostConditions())[1]).getName()); } }
public void testPrePost_DefLocalVar_01() { doTestManyContextOK("context Film::getTapes() : Set(Tape) \r\n" + "def: theSize : Integer = tapes->size() \r\n" + "def: abc : Integer = theSize + 10 \r\n" + "pre myPre: theSize > 0 \r\n" + "post myPost: result = tapes->select(rentalFee > 10) \r\n" + "pre anotherPre: theSize < 10 and abc > 20", getCurrentMethodName()); CoreClassifier film = (CoreClassifier)environment.lookup("Film"); CoreOperation operation = film.lookupOperation("getTapes", null); Assert.AreEqual(1, new List <object>(operation.getSpecifications()).Count); OclPrePostConstraint constraint = (OclPrePostConstraint) new List <object>(operation.getSpecifications())[0]; Assert.AreEqual(2, constraint.getPreConditions().Count); Assert.AreEqual("myPre", ((OclPreConstraint) new List <object>(constraint.getPreConditions())[0]).getName()); Assert.AreEqual("anotherPre", ((OclPreConstraint) new List <object>(constraint.getPreConditions())[1]).getName()); Assert.AreEqual(1, new List <object>(constraint.getPostConditions()).Count); Assert.AreEqual("myPost", ((OclPostConstraint) new List <object>(constraint.getPostConditions())[0]).getName()); Assert.IsNotNull(operation.lookupLocalVariable("theSize")); }