Using MFUPP to Mock a CICS Program

Source code for the following programs can be found in the appendix:

  • CICSHello.cbl
  • MFUT_CICSHello.cpy
  • MFUM_CICSHello.cpy

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.

  1. Create a COBOL source file, CICSHello.cbl, and copy the contents from the appendix into this file.
  2. Produce the catalog file, which extracts the details of each EXEC CICS call within the source file:
    cobol CICSHello.cbl preprocess(mfupp) cics"ignore" mock"cics" exec-report-file endp int"";
    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.

    CICS catalog file
  3. Generate the framework files that are injected into the source code when it is put under test.
    mfurun -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.

  4. Replace the contents of the test case file (MFUT_CICSHELLO.cpy) with the code in the appendix.
  5. Compile the source and its supporting copybook files:
    cobol CICSHello.cbl preprocess(mfupp) cics"ignore" mock"cics" endp int"";

    This compilation is set to ignore all EXEC CICS commands.

  6. Run the test:
    mfurun CICSHello.int

    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.

  7. Edit the MFUM_CICSHello.cpy file and add MOVE "Hello" to WS-MESSAGE-R(4:) to the following section:
               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.)

  8. Recompile the code again with the amended mock code:
    cobol CICSHello.cbl preprocess(mfupp) cics"ignore" mock"cics" endp int"";
  9. Run the test again
    mfurun CICSHello.int

    The test now passes, as it receives some mocked user input that does not trigger a test failure.