How to work with collections using axunit

Overview

Collections (basic classes) are used to establish links between standalone entities. These collections link two entities to form an entity relationship.

A data set in 'AXUNIT' tests is generally created, which will in turn create a valid entry at the end of every successful run.

Adding line(s) to a collection

To add a single line to a collection, the syntax is as follows:

 Local Integer I I=fmet RECORD.ADDLINE ("XX011ARL",[V]CST_ALASTPOS) RECORD.XX011ARL (I).ACT_CODE = "E001" RECORD.XX011ARL(I).ROLE_CODE = "RO001"

Where:

To add more than one line to a collection, the syntax is as follows:

 Local Integer I  For I = 1 to 5 I=fmet RECORD.ADDLINE ("XX011ARL",[V]CST_ALASTPOS)  RECORD.XX011ARL (I).ACT_CODE = "E001" RECORD.XX011ARL (I).ROLE_CODE = "RO001" ` Next I

The only addition to the code is to surround the previous code in a “for loop” to enter multiple lines.

Example:
 Subprog XX011ACT_INSERTLocal Instance RECORD Using C_XX011ACTRECORD = NewInstance C_XX011ACT AllocGroup nullLocal Integer OK,IOK = fmet RECORD.AINIT()Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITRECORD.CODE = "E001"RECORD.DESCRIPTION = "Learning Activity"RECORD.STARTDATE = [09/01/2013]RECORD.ENDDATE = [09/05/2013]Call LOG_LINE("Entering roles") From AXUNITI=fmet RECORD.ADDLINE("XX011ARL",[V]CST_ALASTPOS)Call LOG_LINE("Result of ADDLINE I="+num$(I)) From AXUNITCall CHECK_TRUE(I>=0) From AXUNITRECORD.XX011ARL(I).ACT_CODE = "E001"RECORD.XX011ARL(I).ROLE_CODE = "RO001"OK = fmet RECORD.AINSERTCall CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITFreeGroup RECORDEnd

Reading line(s) from a collection

To read one or more lines from a collection, the syntax is as follows:

 For I=1 To maxtab(RECORD.XX011ARL)If RECORD.XX011ARL (I) <>nullCall CHECK_EQUAL (RECORD.XX011ARL (I).ACT_CODE,"E001") From AXUNITCall CHECK_EQUAL (RECORD.XX011ARL (I).ROLE_CODE,"RO001") From AXUNITCall CHECK_EQUAL (RECORD.XX011ARL (I).ROLE_DESC, "Junior Developer C++") From AXUNITEndifNext I

Where:

Example:
 Subprog XX011ACT_AREAD_AFTER_INSERTLocal Instance RECORD Using C_XX011ACTRECORD = NewInstance C_XX011ACT AllocGroup nullLocal Integer OKOK = fmet RECORD.AREAD("E001")Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITCall LOG_LINE("Verify Loan Record can be Read") From AXUNITCall CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITCall CHECK_EQUAL(RECORD.CODE,"E001") From AXUNITCall CHECK_EQUAL(RECORD.DESCRIPTION,"Learning Activity") From AXUNITCall CHECK_EQUAL(RECORD.STARTDATE, [09/01/2013]) From AXUNITCall CHECK_EQUAL(RECORD.ENDDATE, [09/05/2013]) From AXUNITLocal Integer ICall LOG_LINE("Reading collection entries") From AXUNITFor I=1 To maxtab(RECORD.XX011ARL)If RECORD.XX011ARL(I)<>nullCall CHECK_EQUAL(RECORD.XX011ARL(I).ACT_CODE,"E001") From AXUNITCall CHECK_EQUAL(RECORD.XX011ARL(I).ROLE_CODE,"RO001") From AXUNITCall CHECK_EQUAL(RECORD.XX011ARL(I).ROLE_DESC,"Junior Developer C++") From AXUNITEndifNext IFreeGroup RECORDEnd

Deleting line(s) from a collection

To delete a line from a collection, the syntax is as follows:

 OK=fmet RECORD.ADELLINE ("XX011ARL", 2)

Where:

Note: 'AXUNIT' expects an integer as the second argument of ADELLINE. For multiple line deletion, you need to write multiple ADELLINE statements with integer positions. For example:

 OK=fmet RECORD.ADELLINE ("XX011ARL", 1)OK=fmet RECORD.ADELLINE ("XX011ARL", 2)

Example:
 Subprog XX011ACT_UNIQUEENTRY_PASS Local Instance RECORD Using C_XX011ACT RECORD = NewInstance C_XX011ACT AllocGroup null Local Integer OK,I OK = fmet RECORD.AREAD("E001") Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNIT Call LOG_LINE("Trying to add a new role") From AXUNIT I=fmet RECORD.ADDLINE("XX011ARL",[V]CST_ALASTPOS) Call LOG_LINE("Result of ADDLINE I="+num$(I)) From AXUNIT Call CHECK_TRUE(I>=0) From AXUNIT RECORD.XX011ARL(I).ACT_CODE = "E001" RECORD.XX011ARL(I).ROLE_CODE = "RO002" #DELETING SINGLE LINE Call LOG_LINE("Trying to delete the new role") From AXUNIT OK=fmet RECORD.ADELLINE("XX011ARL",2) Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNIT OK = fmet RECORD.AUPDATE Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNIT FreeGroup RECORD End