Exemple #1
0
        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 visitAttributeCallExp(AttributeCallExp exp)
        {
            if (exp.getSource() is AssociationEndCallExpImpl)
            {
                string typeName, name;
                getTableReference(exp, out name, out typeName);

                var columnName = string.Format("{0}_{1}", typeName.ToLower(), name.ToLower());
                formula += string.Format("{0}[{1}]", currentClassifier.getName(), columnName);

                otherFormula += string.Format(",COL({0}[{1}]))", typeName, name);
                columnToFormula.Add(columnName, otherFormula);
            }
            else
            {
                string typeName, name;
                getTableReference(exp, out name, out typeName);

                // format table_name[column_name] (same of classifier.attribute)
                formula += string.Format("{0}[{1}]", typeName, name);

                if (currentClassifier == null)
                {
                    currentClassifier = (CoreClassifier)exp.getReferredAttribute().getElemOwner();
                }
            }
        }
Exemple #3
0
        public void testAttributeCallExp_02()
        {
            List <object>    constraints   = doTestContextOK("context Empregado inv: self.nome = nome", getCurrentMethodName());
            OclExpression    oclExpression = getConstraintExpression(constraints);
            AttributeCallExp attExp        = checkAttributeCallExp(((OperationCallExp)oclExpression).getSource(), "nome", "String");

            checkImplicitSource(attExp, "self", "Empregado");
        }
        protected AttributeCallExp checkAttributeCallExp(OclExpression oclExpression, String attName, String attType)
        {
            Assert.IsTrue(oclExpression is AttributeCallExp);
            AttributeCallExp attExp = (AttributeCallExp)oclExpression;

            Assert.AreEqual(attName, attExp.getReferredAttribute().getName());
            Assert.AreEqual(attType, attExp.getType().getName());
            return(attExp);
        }
Exemple #5
0
        public void testClassifierAttribute_04()
        {
            List <object> constraints = doTestContextOK("context Rental inv: self.maxDaysToReturn > 10",
                                                        getCurrentMethodName());

            OclExpression    oclExpression = getConstraintExpression(constraints);
            AttributeCallExp attExp        = checkAttributeCallExp(((OperationCallExp)oclExpression).getSource(), "maxDaysToReturn", "Integer");

            checkImplicitSource(attExp, "self", "Rental");
        }
Exemple #6
0
        public void testMoreThanOneNavigation_08()
        {
            List <object> constraints = doTestContextOK("context Tape inv: self.theFilm.name = self.theFilm.name",
                                                        getCurrentMethodName());

            OclExpression    oclExpression = getConstraintExpression(constraints);
            AttributeCallExp attExp        = checkAttributeCallExp(((OperationCallExp)oclExpression).getSource(), "name", "String");

            Assert.IsTrue(attExp.getSource() is AssociationEndCallExp);
            AssociationEndCallExp exp = (AssociationEndCallExp)attExp.getSource();

            Assert.AreEqual("Film", exp.getType().getName());
        }
Exemple #7
0
        public void testAttributeCall_Superclass_02()
        {
            List <object> constraints = doTestContextOK("context SpecialFilm inv: self.tapes[1].number > 10",
                                                        getCurrentMethodName());

            OclExpression oclExpression = getConstraintExpression(constraints);

            Assert.IsTrue(((OperationCallExp)oclExpression).getSource() is AttributeCallExp);
            AttributeCallExp exp = (AttributeCallExp)((OperationCallExp)oclExpression).getSource();

            Assert.AreEqual("Tape", exp.getReferredAttribute().getFeatureOwner().getName());
            Assert.AreEqual("number", exp.getReferredAttribute().getName());
            Assert.AreEqual("Integer", exp.getType().getName());
        }
Exemple #8
0
        public void testClassifierAttribute_01()
        {
            List <object> constraints = doTestContextOK("context Film inv: Rental::maxDaysToReturn > SpecialFilm::days",
                                                        getCurrentMethodName());

            OclExpression oclExpression = getConstraintExpression(constraints);

            Assert.IsTrue(((OperationCallExp)oclExpression).getSource() is AttributeCallExp);
            AttributeCallExp exp = (AttributeCallExp)((OperationCallExp)oclExpression).getSource();

            Assert.AreEqual("Rental", exp.getReferredAttribute().getFeatureOwner().getName());
            Assert.AreEqual("maxDaysToReturn", exp.getReferredAttribute().getName());
            Assert.AreEqual("Integer", exp.getType().getName());
        }
        public void testAttributeCallExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Film"), null);
            VariableExp         source1  = factory1.createVariableExp(variable);
            VariableExp         source2  = factory1.createVariableExp(variable);

            CoreAttribute attribute = getClassifier("Film").lookupAttribute("name");

            AttributeCallExp exp1 = factory1.createAttributeCallExp(source1, attribute, false);
            AttributeCallExp exp2 = factory1.createAttributeCallExp(source2, attribute, true);

            Assert.AreEqual("abc.name", exp1.ToString());
            Assert.AreEqual("String", exp1.getType().getName());

            Assert.AreEqual("abc.name@pre", exp2.ToString());
            Assert.AreEqual("String", exp2.getType().getName());
        }
        public void testIterateExp()
        {
            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("lateReturnFee");
            AttributeCallExp attCall = factory1.createAttributeCallExp(iterRef, attr, false);

            IntegerLiteralExp   initExp = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            VariableDeclaration result  = factory1.createVariableDeclaration("result", getClassifier("Integer"), initExp);


            List <object> paramTypes = new List <object>();

            paramTypes.Add(getClassifier("Integer"));
            CoreOperation oper = getClassifier("Integer").lookupOperation("+", paramTypes);

            VariableExp   resultExp = factory1.createVariableExp(result);
            List <object> args      = new List <object>();

            args.Add(attCall);
            OclExpression body = factory1.createOperationCallExp(resultExp, oper, args, getClassifier("Integer"), false);

            List <object> iterators = new List <object>();

            iterators.Add(iter);

            IterateExp exp = factory1.createIterateExp(getClassifier("Integer"), source, body, iterators, result);

            Assert.AreEqual("abc->iterate(iter : SpecialFilm ; result : Integer = 100 | result + iter.lateReturnFee)",
                            exp.ToString());
            Assert.AreEqual("Integer", exp.getType().getName());
        }
        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());
        }
        private void getTableReference(AttributeCallExp exp, out string name, out string typeName)
        {
            // get referred attribute name
            var attribute = exp.getReferredAttribute();

            name     = attribute.getName();
            typeName = null;

            // get attribute source to get type (classifier) name
            if (exp.getSource() is VariableExpImpl)
            {
                var expsource = (VariableExp)exp.getSource();
                var variable  = expsource.getReferredVariable();
                var type      = variable.getType();
                typeName = type.getName();
            }
            else if (exp.getSource() is AssociationEndCallExpImpl)
            {
                var expsource      = (AssociationEndCallExp)exp.getSource();
                var associationEnd = expsource.getReferredAssociationEnd();
                var type           = associationEnd.getType();
                typeName = type.getName();
            }
        }