Source code for the following programs can be found in the appendix:
This example uses a source program that uses EXEC CICS statements to receive and manipulate a text string. The test case makes assertions based on the value of the string, but as the MFUPP preprocessor is set to ignore all EXEC CICS statements, mocking code is required to supply the text string.
cob -vi -C "p(mfupp) cics(ignore) mock(cics) exec-report-file endp" CICSHello.cbl
The CICSHello.mfupp-et catalog file is produced, which contains details of each EXEC CICS statement in CICSHello.cbl. These details will be used in the next step to generate the framework files used to run the test. The following excerpt shows the catalog file; from line 3 onwards shows an entry for each EXEC CICS statement in CICSHello.cbl.
cobmfurun -generate-exec-mock-snippet CICSHello.mfupp-et
The following files are created, which enable the EXEC CICS statements to be mocked: MFUT_CICSHELLO.cpy, MFUM_CICSHELLO.cpy, MFUPD_CICSHELLO.cpy, MFUPDS_CICSHELLO.cpy, MFULK_CICSHELLO.cpy, MFUWS_CICSHELLO.cpy.
cob -vi -C "p(mfupp) cics(ignore) mock(cics)" CICSHello.cbl
This compilation is set to ignore all EXEC CICS commands.
cobmfurun CICSHello
The test should fail initially as the source code is originally supplied input from the user by means of an EXEC CICS statement. As all EXEC CICS statements are now ignored, we need to 'mock' a user response in the test, which will allow the program to run to completion.
MOCK-CID-SEND-EA84590D SECTION. IF MFU-PP-MOCK-EXEC-CRC NOT EQUAL "EA84590D" DISPLAY "CICS Statement changed (EA84590D)" END-IF MOVE "Hello" to WS-MESSAGE-R(4:) MOVE MFU-PP-ACTION-DO-NOTHING TO RETURN-CODE .
The section name is derived from the entry that was cataloged in CICSHelpp.mfupp-et. (The full program can be found in the appendix.)
cob -vi -C "p(mfupp) cics(ignore) mock(cics)" CICSHello.cbl
cobmfurun CICSHello
The test now passes, as it receives some mocked user input that does not trigger a test failure.