#!/usr/bin/env python

import coral
from coral.util.search.query import *
import coral.util.search.util as U

prj=coral.loadDocument("testNewQuery.xmi")

target_model=None
query_set=coral.Set()
start_q=None
for root in prj.contents():
    if root.name == "Target":
        target_model=root

    if root.name == "Query":
        for elem in root.ownedElement:
            query_set.append(elem)
            if elem.oclIsKindOf(coral.lang.UML14.Association):
                start_q=elem
#            if elem.name == "*":
#                start_q=elem

assert target_model
assert not query_set.isEmpty()
assert start_q

q2t=search(U.get_all_parts(query_set), target_model,start_q)
print "**** RESULTS ****"
num=0
for map in q2t:
    num+=1
    print str(num)+":"
    for k,v in map.items():
        print k,"->",v
    print

print "started with"
print start_q,
assert len(q2t)==2
