#!/usr/bin/env python
import coral

tm = coral.getTransactionManager()
tm.beginModifyCmd()
try:
    st = coral.Project()
finally:
    tm.endModifyCmd()


tr = tm.getCurrentTransaction()
assert tr.size() == 1
c = tr[0]
print c
assert isinstance(c, coral.NewProjectCommand)

hrefname = "coral/core/hello.xmi"
fname = coral.installation_path + "/" + hrefname

tm.beginModifyCmd()
try:
    st.setFilename(fname)
finally:
    tm.endModifyCmd()

tr = tm.getCurrentTransaction()
assert tr.size() == 1
c = tr[0]
assert isinstance(c, coral.ProjectNameChangeCommand)
assert c.getProject() == st
assert c.getOldFilename() == ""
assert c.getOldHrefFilename() == ""

assert st.getFilename() == fname
assert st.getHrefFilename() == hrefname
tm.undo()

assert st.getFilename() == ""
assert st.getHrefFilename() == ""
tm.redo()

assert st.getFilename() == fname
assert st.getHrefFilename() == hrefname
tm.undo()
