private List <object> createCollectionParts()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            OclExpression elem1           = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            OclExpression elem2           = factory1.createIntegerLiteralExp(200, getClassifier("Integer"));
            OclExpression elem3           = factory1.createIntegerLiteralExp(300, getClassifier("Integer"));
            List <object> collectionParts = new List <object> ();

            collectionParts.Add(factory1.createCollectionItem(elem1));
            collectionParts.Add(factory1.createCollectionItem(elem2));
            collectionParts.Add(factory1.createCollectionItem(elem3));

            return(collectionParts);
        }
        public void testOperationCallExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

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

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

            paramTypes.Add(getClassifier("Integer"));

            CoreOperation operation = getClassifier("Film").lookupOperation("getRentalFee", paramTypes);

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

            arguments.Add(factory1.createIntegerLiteralExp(100, getClassifier("Integer")));

            OperationCallExp exp = factory1.createOperationCallExp(source, operation, arguments,
                                                                   operation.getReturnType(), false);

            Assert.AreEqual("abc.getRentalFee(100)", exp.ToString());
            Assert.AreEqual("Real", exp.getType().getName());

            CollectionLiteralExp literalCollection = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                                                         factory1.createSetType(
                                                                                             getClassifier("Integer")));
            CollectionTypeImpl type1          = (CollectionTypeImpl)factory1.createSetType(getClassifier("Integer"));
            CoreOperation      collectionOper = type1.lookupOperation("size", new List <object>());

            OperationCallExp exp1 = factory1.createOperationCallExp(literalCollection, collectionOper, new List <object>(),
                                                                    getClassifier("Integer"), false);

            Assert.IsNotNull(exp1);
        }
Beispiel #3
0
        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 testIntegerLiteralExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());
            IntegerLiteralExp         exp1     = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));

            Assert.AreEqual("100", exp1.ToString());
            Assert.AreEqual("Integer", exp1.getType().getName());
        }
        public void testCollectionLiteralExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            CollectionLiteralExp exp = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                                           factory1.createSetType(
                                                                               getClassifier("Integer")));

            Assert.AreEqual("Set{ 100, 200, 300 }", exp.ToString());
            Assert.AreEqual("Set(Integer)", exp.getType().getName());

            CollectionLiteralExp exp2 = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                                            factory1.createSetType(
                                                                                getClassifier("Integer")));

            Assert.AreEqual("Set{ 100, 200, 300 }", exp2.ToString());
            Assert.AreEqual("Set(Integer)", exp2.getType().getName());

            exp = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                      factory1.createBagType(getClassifier("Integer")));
            Assert.AreEqual("Bag{ 100, 200, 300 }", exp.ToString());
            Assert.AreEqual("Bag(Integer)", exp.getType().getName());

            exp = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                      factory1.createSequenceType(getClassifier("Integer")));
            Assert.AreEqual("Sequence{ 100, 200, 300 }", exp.ToString());
            Assert.AreEqual("Sequence(Integer)", exp.getType().getName());

            exp = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                      factory1.createOrderedSetType(getClassifier("Integer")));
            Assert.AreEqual("OrderedSet{ 100, 200, 300 }", exp.ToString());
            Assert.AreEqual("OrderedSet(Integer)", exp.getType().getName());

            OclExpression   elem1 = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            OclExpression   elem2 = factory1.createIntegerLiteralExp(200, getClassifier("Integer"));
            CollectionRange range = factory1.createCollectionRange(elem1, elem2);
            List <object>   parts = new List <object> ();

            parts.Add(range);
            exp = factory1.createCollectionLiteralExp(parts, factory1.createSetType(getClassifier("Integer")));
            Assert.AreEqual("Set{ 100 .. 200 }", exp.ToString());
            Assert.AreEqual("Set(Integer)", exp.getType().getName());
        }
        public void testLetExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            OclExpression       initExp  = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Integer"), initExp);

            OclExpression varExp     = factory1.createVariableExp(variable);
            OclExpression intLiteral = factory1.createIntegerLiteralExp(200, getClassifier("Integer"));
            List <object> paramTypes = new List <object>();

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

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

            args.Add(intLiteral);
            OclExpression inExp = factory1.createOperationCallExp(varExp, oper, args, getClassifier("Integer"), false);

            LetExp exp = factory1.createLetExp(variable, inExp);

            Assert.AreEqual("let abc : Integer = 100 in abc + 200", exp.ToString());
            Assert.AreEqual("Integer", exp.getType().getName());
        }
        public void testIfExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable  = factory1.createVariableDeclaration("abc", getClassifier("Boolean"), null);
            VariableExp         condition = factory1.createVariableExp(variable);

            IntegerLiteralExp thenExp = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            RealLiteralExp    elseExp = factory1.createRealLiteralExp("247.49", getClassifier("Real"));

            IfExp exp = factory1.createIfExp(condition, thenExp, elseExp);

            Assert.AreEqual("if abc then 100 else 247.49 endif", exp.ToString());
            Assert.AreEqual("Real", exp.getType().getName());
        }
        public void testVariableExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            OclExpression       init1    = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Integer"), init1);

            VariableExp exp1 = factory1.createVariableExp(variable);
            VariableExp exp2 = factory1.createVariableExp(variable);

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

            Assert.AreEqual("abc", exp2.ToString());
            Assert.AreEqual("Integer", exp2.getType().getName());

            Assert.AreEqual("100", variable.getInitExpression().ToString());
        }
        public void testTupleLiteralExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            OclExpression       init1 = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            VariableDeclaration part1 = factory1.createVariableDeclaration("a", getClassifier("Integer"), init1);

            OclExpression       init2 = factory1.createRealLiteralExp("100.38", getClassifier("Real"));
            VariableDeclaration part2 = factory1.createVariableDeclaration("b", getClassifier("Real"), init2);

            OclExpression       init3 = factory1.createBooleanLiteralExp(true, getClassifier("Boolean"));
            VariableDeclaration part3 = factory1.createVariableDeclaration("c", getClassifier("Boolean"), init3);

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

            parts.Add(part1);
            parts.Add(part2);
            parts.Add(part3);

            TupleTypeImpl tupleType = (TupleTypeImpl)factory1.createTupleType();

            tupleType.addElement("a", getClassifier("Integer"));
            tupleType.addElement("b", getClassifier("Real"));
            tupleType.addElement("c", getClassifier("Boolean"));
            Assert.AreEqual("Tuple(a : Integer, b : Real, c : Boolean)", tupleType.getName());

            //		TuplePartType part1Type = factory1.createTuplePartType(tupleType, "a", getClassifier("Integer"));
            //		TuplePartType part2Type = factory1.createTuplePartType(tupleType, "b", getClassifier("Real"));
            //		TuplePartType part3Type = factory1.createTuplePartType(tupleType, "c", getClassifier("Boolean"));

            OclExpression exp = factory1.createTupleLiteralExp(parts, tupleType);

            Assert.AreEqual("Tuple{ a : Integer = 100, b : Real = 100.38, c : Boolean = True }", exp.ToString());

            Assert.AreEqual("Tuple(a : Integer, b : Real, c : Boolean)", exp.getType().getName());

            Assert.IsNotNull(exp.getType().lookupAttribute("a"));
            Assert.IsNull(exp.getType().lookupAttribute("d"));
        }
        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 testOperationCallExpWithAtPre()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

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

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

            paramTypes.Add(getClassifier("Integer"));

            CoreOperation operation = getClassifier("Film").lookupOperation("getRentalFee", paramTypes);

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

            arguments.Add(factory1.createIntegerLiteralExp(100, getClassifier("Integer")));

            OperationCallExp exp = factory1.createOperationCallExp(source, operation, arguments,
                                                                   operation.getReturnType(), true);

            Assert.AreEqual("abc.getRentalFee@pre(100)", exp.ToString());
            Assert.AreEqual("Real", exp.getType().getName());
        }