#!/usr/bin/env python
import coral
from coral.modeler.project import *
import coral ; 
prj=Project(["UML", 1, 4])    # Create a project
sm=StateMachine(top=CompositeState())  # Create a state machine
prj.setRoot(sm)
# Add an initial state to top
sm.top.subvertex.insert(Pseudostate(kind=PseudostateKind.pk_initial))
# Begin a strict transaction
try:
    coral.getTransactionManager().beginModifyCmd(1)
    try:
        # We add a second initial state (this is wrong)
        sm.top.subvertex.insert(Pseudostate(kind=PseudostateKind.pk_initial))
        # Now the top state has two subvertices
        assert(sm.top.subvertex.size()==2)
        # We try to commit the strict transaction, we will get a WFR Exception
        ok=0
    finally:
        coral.getTransactionManager().endModifyCmd()
except coral.WFRException,e:
    ok=1
    print "You got an exception (as expected): ",e
assert(ok)
# Now the second initial state has disappeared
assert(sm.top.subvertex.size()==1)
