protected void checkOperationCallType(OclExpression oclExpression, String typeName, String operationName, Type sourceClass, String sourceType, Object[] argTypes) { Assert.IsTrue(oclExpression is OperationCallExp); OperationCallExp exp = (OperationCallExp)oclExpression; Assert.AreEqual(typeName, exp.getType().getName()); Assert.IsTrue(exp.getReferredOperation().operationNameMatches(operationName)); if (sourceClass != null) { Assert.IsTrue(sourceClass.IsInstanceOfType(exp.getSource())); Assert.AreEqual(exp.getSource().getType().getName(), sourceType); } else { Assert.IsFalse(exp.getReferredOperation().isInstanceScope()); } if (argTypes == null) { Assert.AreEqual(0, exp.getArguments().Count); } else { Assert.AreEqual(argTypes.Length, exp.getArguments().Count); } }
public void testClassifierAttribute_05() { CoreClassifier film = (CoreClassifier)environment.lookup("Film"); CoreOperation operation = film.lookupOperation("getTapes", null); Assert.AreEqual(0, operation.getSpecifications().Count); List <object> constraints = doTestManyContextOK("context Film::getTapes() : Set(Tape) post: self.rentalFee@pre = 10 ", getCurrentMethodName()); film = (CoreClassifier)environment.lookup("Film"); operation = film.lookupOperation("getTapes", null); Assert.AreEqual(1, operation.getSpecifications().Count); OclPrePostConstraint constraint = (OclPrePostConstraint)operation.getSpecifications()[0]; OclPostConstraint post = (OclPostConstraint)constraint.getPostConditions()[0]; OclExpression oclExpression = ((ExpressionInOclImpl)post.getExpression()).getBodyExpression(); this.checkOperationCallExp(((OperationCallExp)oclExpression), "=", "Boolean"); OperationCallExp opCall = (OperationCallExp)((OperationCallExp)oclExpression); AttributeCallExp attExp = checkAttributeCallExp(opCall.getSource(), "rentalFee", "Integer"); opCall = (OperationCallExp)((AttributeCallExp)opCall.getSource()).getSource(); this.checkOperationCallExp(opCall, "atPre", "Film"); checkImplicitSource(opCall, "self", "Film"); }
public void testProduct_02() { List <object> constraints = doTestContextOK("context Film inv: self.tapes->product(self.Reservation)->isEmpty()", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp, "isEmpty", "Boolean"); Console.WriteLine("type = " + exp.getSource().getType().getName()); checkOperationCallExp(exp.getSource(), "product", "Set(Tuple(first : Tape, second : Reservation))"); }
public void testOperationCall_06() { List <object> constraints = doTestContextOK("context Tape inv: self.theFilm.getRentalFee(1) = self.theFilm.getRentalFee(1)", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp exp = checkOperationCallExp(((OperationCallExp)oclExpression).getSource(), "getRentalFee", "Real"); checkAssociationEndCallExp(exp.getSource(), "theFilm", "Film"); }
public void testSize_05() { List <object> constraints = doTestContextOK("context Film inv: Set{1, 2}->size() > 10", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp.getSource(), "size", "Integer"); checkCollectionLiteralExp(exp.getSource(), "Set(Integer)"); }
public void testSize_04B() { List <object> constraints = doTestContextOK("context Film inv: (self.getTapes()).theFilm->size() > 10", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp.getSource(), "size", "Integer"); checkIteratorExp(exp.getSource(), "Bag(Film)", "collect", "Tape", "iterator"); }
public void testSize_03() { List <object> constraints = doTestContextOK("context Film inv: self.getTapes()->size() > 10", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp.getSource(), "size", "Integer"); checkOperationCallExp(exp.getSource(), "getTapes", "Set(Tape)"); }
public void testSize_08() { List <object> constraints = doTestContextOK("context Film inv: self.name->asOrderedSet()->isEmpty()", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp, "isEmpty", "Boolean"); checkOperationCallExp(exp.getSource(), "asOrderedSet", "OrderedSet(String)"); }
public void visitOperationCalllExpEnd(OperationCallExp exp) { // put parenthesis in the end of operation formula var operation = exp.getReferredOperation(); if (operation != null && !(exp.getSource() is VariableExpImpl)) { formula += ")"; navigationLevel = 0; } }
public void testIterateWithError_03() { List <object> constraints = doTestContextOK("context Film inv: self.tapes->iterate(x : Tape, y : Tape; total : Integer = 0 | total + x.number) > 5", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); Assert.IsTrue(oclExpression is OperationCallExp); OperationCallExp opCallExp = (OperationCallExp)oclExpression; checkIterateExp(opCallExp.getSource(), "Integer", "total", "x", "Tape", "Integer", 2); }
public void testIterate_03() { List <object> constraints = doTestContextOK("context Film inv: self.tapes->iterate(x : Tape; result : Set(Tape) = Set{} | if x.number > 5 then result->including(x) else result endif)->size() > 5", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); Assert.IsTrue(oclExpression is OperationCallExp); OperationCallExp opCallExp = (OperationCallExp)oclExpression; checkIterateExp(((OperationCallExp)(opCallExp.getSource())).getSource(), "Set(Tape)", "result", "x", "Tape", "Set(Tape)", 1); }