#!/usr/bin/env python

import coral
import coral.modeler
import coral.modeler.modeler
import coral.addins.constraint.engine as E

#E.loadModelFromFile("testEngineEvaluate.xml")

prj=coral.loadDocument("testEngineEvaluate.xml")

model=None
cmodel=None
for part in prj.contents():
    if part.oclIsKindOf(coral.lang.CONSTRAINT10.Package):
        print "Activate"
        for CM in part.__getAllParts__().select(lambda p: p.oclIsKindOf(coral.lang.CONSTRAINT10.ConstraintModel)):
            cmodel=CM
            print CM
            E.loadConstraintModel(CM)
            E.activateCM(CM)
            

before=len(CM.result)
print before

#E.deActivateCM(CM)

CM.result.resetSlot()


for part in prj.contents():
    if part.oclIsKindOf(coral.lang.UML14.Model):
        print "Check"
        for p in part.__getAllParts__():
            print p
            E.evaluate(p)


E.updateResults()

#assert len(cmodel.result) == len(CM.result)
assert len(cmodel.result) == 6, str(len(cmodel.result))
assert len(cmodel.result) == before

prj.setFilename("tmp/testEngineEvaluate.xml")
coral.saveDocument(prj)
