#!/usr/bin/env python
import coral
import coral.modeler
import coral.modeler.modeler
import coral.addins.constraint.engine as E
UL = coral.lang.UML14
CL = coral.lang.CONSTRAINT10

constrprj = coral.loadDocument("../UML14Constraints.xml")
targetprj = coral.loadDocument("testTrace.xml")

targetModel = None
for part in targetprj.contents():
    if part.oclIsKindOf(UL.Model) and part.name == "model2":
        targetModel = part

testPack = CL.Package()
CM = CL.ConstraintModel(target = targetModel, package = testPack)

for part in constrprj.contents().select(lambda p:p.oclIsKindOf(CL.Package)):
    for elem in part.__getAllParts__().select(lambda l:l.oclIsKindOf(CL.Constraint)):
        if elem.name=="TraceClientsInSameModel":
            CM.constraint.append(elem)
        if elem.name=="TraceSuppliersInSameModel":
            CM.constraint.append(elem)
        if elem.name=="TraceClientSupplierModelElements":
            CM.constraint.append(elem)
        if elem.name=="TraceClientSupplierModel":
            CM.constraint.append(elem)

E.loadConstraintModel(CM)
E.activateCM(CM)
assert len(CM.result) == 13
