protected IteratorExp checkIteratorExp(OclExpression oclExpression, String typeName, String name, String iteratorType, String iteratorName) { Assert.IsTrue(oclExpression is IteratorExp); IteratorExp exp = (IteratorExp)oclExpression; Assert.AreEqual(typeName, exp.getType().getName()); Assert.AreEqual(name, exp.getName()); Assert.AreEqual(1, exp.getIterators().Count); VariableDeclaration varDecl = (VariableDeclaration)exp.getIterators()[0]; Assert.AreEqual(iteratorName, varDecl.getVarName()); Assert.AreEqual(iteratorType, varDecl.getType().getName()); return(exp); }
public void testForAll_01() { List <object> constraints = doTestContextOK("context Film inv: self.tapes->forAll(t1 : Tape, t2 : Tape | t1 <> t2 and t1.number = 1 and self.name = \"alex\")", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); Assert.IsTrue(oclExpression is IteratorExp); IteratorExp exp = (IteratorExp)oclExpression; Assert.AreEqual("Boolean", exp.getType().getName()); Assert.AreEqual("forAll", exp.getName()); Assert.AreEqual(2, exp.getIterators().Count); VariableDeclaration v1 = (VariableDeclaration)exp.getIterators()[0]; VariableDeclaration v2 = (VariableDeclaration)exp.getIterators()[1]; Assert.AreEqual("t1", v1.getName()); Assert.AreEqual("t2", v2.getName()); Assert.AreEqual("Tape", v1.getType().getName()); Assert.IsTrue(exp.getBody() is OperationCallExp); checkOperationCallExp(exp.getBody(), "and", "Boolean"); }
public void testIteratorExp() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Distributor"), null); VariableExp source = factory1.createVariableExp(variable); VariableDeclaration iter = factory1.createVariableDeclaration("iter", getClassifier("SpecialFilm"), null); VariableExp iterRef = factory1.createVariableExp(iter); CoreAttribute attr = getClassifier("SpecialFilm").lookupAttribute("name"); AttributeCallExp body = factory1.createAttributeCallExp(iterRef, attr, false); CoreClassifier setSpecialFilm = factory1.createSetType(getClassifier("SpecialFilm")); List <object> iterators = new List <object> (); iterators.Add(iter); IteratorExp exp = factory1.createIteratorExp("select", setSpecialFilm, source, body, iterators); Assert.AreEqual("abc->select(iter : SpecialFilm | iter.name)", exp.ToString()); Assert.AreEqual("Set(SpecialFilm)", exp.getType().getName()); }