How to work with collections using axunit
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.
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"
RECORD
is the instance of XX011ACT table.ADDLINE
is the method.“XX011ARL”
is the collection name.[V] CST_ALASTPOS
is the last available position in the collection.RECORD
.collectionName (subscript).fieldName] - Adding values to the fields in the collection table “XX011ARL”.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
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
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
RECORD
is the instance of XX011ACT table.“XX011ARL”
is the collection name.RECORD.XX011ARL
)] will calculate the number of lines in the Collection.RECORD.XX011ARL
(I) <> null will check whether the current line is not Null.CHECK_EQUAL
command to validate successful reads.RECORD.XX011ARL
(I).ROLE_CODE,"RO001"] checks the value “RO001” against the field name 'ROLE_CODE' in "XX011ARL" collection. 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
To delete a line from a collection, the syntax is as follows:
OK=fmet RECORD.ADELLINE ("XX011ARL", 2)
RECORD
is the instance of XX011ACT table.ADELLINE
is the method.“XX011ARL”
is the collection name.2
is the position of line in the collection.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)
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