Ejemplo n.º 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);
        }
Ejemplo n.º 2
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());
        }