Testing Add on Maintenance Class
First, to test an add, we need the data. This is provided in the method protected
PageBody getNewEntity(). Here is an example:
protected PageBody getNewEntity() {
PageBody body = new PageBody();
body.put(Maintenance.STRUCTURE.BATCH_CD, "ZZTEST2");
body.put(Maintenance.STRUCTURE.PROGRAM_NAME, "ZZPROG");
body.put(Maintenance.STRUCTURE.ACCUM_ALL_INST_SW, Boolean.FALSE);
body.put(Maintenance.STRUCTURE.DESCR, "Test service");
body.put(Maintenance.STRUCTURE.LAST_UPDATE_DTTM,
LAST_UPDATE_TIMESTAMP);
body.put(Maintenance.STRUCTURE.LAST_UPDATE_INST, BigInteger.ZERO);
body.put(Maintenance.STRUCTURE.NEXT_BATCH_NBR, BigInteger.ZERO);
ItemList itemList = body.newItemList
(Maintenance.STRUCTURE.list_BCP.name);
ListBody listBody = itemList.newListBody();
listBody.put(Maintenance.STRUCTURE.list_BCP.BATCH_CD, "ZZTEST2");
listBody.put(Maintenance.STRUCTURE.list_BCP.SEQ_NUM,
BigInteger.valueOf(10));
listBody.put(Maintenance.STRUCTURE.list_BCP.BATCH_PARM_NAME,
"param1");
listBody.put(Maintenance.STRUCTURE.list_BCP.BATCH_PARM_VAL, "val1");
listBody.put(Maintenance.STRUCTURE.list_BCP.REQUIRED_SW,
Boolean.FALSE);
listBody.put(Maintenance.STRUCTURE.list_BCP.DESCR50, "Parameter 1");
listBody.prepareToAdd();
return body;
}
This may look like a considerable amount of typing, but any IDE that offers code-completion (such as Eclipse) will facilitate this kind of code entry.
If the maintenance performs some server-side defaulting (changing of the data), and the
result after the add differs from the data above, you will need to override
protected PageBody getNewReadEntity(PageBody original). This method
gets the original data from the method above, and allows manipulation to bring it to the
expected form after a read from the database.
In order to actually perform the read, the read header should be specified in protected abstract PageHeader getReadHeader(). For example:
protected PageHeader getReadHeader() {
PageHeader header = new PageHeader();
header.put(Maintenance.HEADER.BATCH_CD, "ZZTEST2");
return header;
}
