示例#1
0
        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);
        }
示例#2
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"));
        }
示例#3
0
        public void testInvariant()
        {
            AstOclConstraintFactory   factory1 = AstOclConstraintFactoryManager.getInstance(umlModel.getOclPackage());
            AstOclModelElementFactory factory2 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            BooleanLiteralExp      exp1       = factory2.createBooleanLiteralExp(true, getClassifier("Boolean"));
            ExpressionInOcl        expInOcl   = factory1.createExpressionInOcl("name", getClassifier("Film"), exp1);
            OclInvariantConstraint constraint = (OclInvariantConstraint)factory1.createInvariantConstraint("test.ocl", "myInvariant", getClassifier("Film"), expInOcl);

            Assert.AreEqual("inv myInvariant: True", constraint.ToString());

            Assert.IsTrue(getClassifier("Film").getAllInvariants().Contains(constraint));

            getClassifier("Film").deleteAllConstraintsForSource("test.ocl");
            Assert.IsFalse(getClassifier("Film").getAllInvariants().Contains(constraint));
        }
示例#4
0
        public void testBody()
        {
            AstOclConstraintFactory   factory1 = AstOclConstraintFactoryManager.getInstance(umlModel.getOclPackage());
            AstOclModelElementFactory factory2 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            RealLiteralExp  exp1     = factory2.createRealLiteralExp("200.50", getClassifier("Real"));
            ExpressionInOcl expInOcl = factory1.createExpressionInOcl("name", getClassifier("Film"), exp1);

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

            parms.Add(getClassifier("Integer"));
            CoreOperation oper = getClassifier("Film").lookupOperation("getRentalFee", parms);

            OclBodyConstraint constraint = (OclBodyConstraint)factory1.createBodyConstraint("test.ocl", oper, expInOcl, null);

            Assert.AreEqual("body: 200.50", constraint.ToString());

            Assert.AreEqual(constraint, oper.getBodyDefinition());
            Assert.AreEqual(expInOcl, oper.getBodyDefinition().getExpression());

            oper.deleteAllConstraintsForSource("test.ocl");
            Assert.IsNull(oper.getBodyDefinition());
        }