using Progress.Lang.*.
using OpenEdge.Core.Assert from propath.

block-level on error undo, throw.

class tests.persistence.flushing_validation.flush_pipeline_regression.TestSurroundingsInnerUndoNoSavepointDmoRollback:

    /* Redmine #11573 — Axis C [MAJOR] (j308385): savepoint-less
     * inner block must perform in-memory rollback for outer-tracked
     * DMO. Observes from inside the outer block after inner UNDO. */

    @Setup.
    method public void setUp():
        for each Book exclusive-lock:
            delete Book.
        end.
    end method.

    @TearDown.
    method public void tearDown():
        for each Book exclusive-lock:
            delete Book.
        end.
    end method.

    @Test.
    method public void TestInnerUndoRevertsInMemoryChangesOnOuterTrackedDmo():
        define variable dbCnt        as integer   no-undo.
        define variable dbTitle      as character no-undo.
        define variable postInnerAv  as logical   no-undo.
        define variable postInnerTtl as character no-undo.

        do transaction:
            create Book.
            assign
                Book.book-id    = 95
                Book.isbn       = "ISBN0095"
                Book.book-title = "outer-write".

            do on error undo, leave:
                find first Book exclusive-lock no-error.
                if available Book then
                    assign Book.book-title = "inner-updated".
                undo, leave.
            end.

            postInnerAv = available Book.
            if postInnerAv then postInnerTtl = Book.book-title.
        end.

        Assert:IsTrue(postInnerAv).
        Assert:Equals("outer-write", postInnerTtl).

        for each Book no-lock:
            dbCnt = dbCnt + 1.
            if Book.book-id = 95 then dbTitle = Book.book-title.
        end.

        Assert:Equals(1, dbCnt).
        Assert:Equals("outer-write", dbTitle).
    end method.

end class.
