#!/usr/bin/env python
#

# The objective of this test is to verify a bug where we have a property that accepts Booleans,
# and the default value is set to "true". Regardless of whether we set the value to False
# True is saved


import coral
import coral.modeler
import coral.modeler.modeler

TM = coral.getTransactionManager()

L = coral.lang.DIML10
DI = coral.lang.XMIDI20

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

model = prj.contents()[0]

assert model

mapp = model.ownedElement.select(lambda x: x.oclIsKindOf(L.ElementToXMIDIMapping))[0]

assert mapp

assert mapp.acceptsConnectors == "true"

TM.beginModifyCmd()
try:
    mapp.acceptsConnectors = False
finally:
    TM.endModifyCmd()

assert mapp.acceptsConnectors == "false"


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



TM.beginModifyCmd()
try:
    prj.invalidate()
finally:
    TM.endModifyCmd()


prj2 = coral.loadDocument("tmp/tmpMapping.xml")

assert prj != prj2


model2 = prj2.contents()[0]

assert model2

mapp2 = model2.ownedElement.select(lambda x: x.oclIsKindOf(L.ElementToXMIDIMapping))[0]

assert mapp2

assert mapp2.acceptsConnectors == "false"
