mardi 29 septembre 2015

How to create jUnit test cases for a method using DB

I never did jUnit test cases. I looked for how to do but I've just done basics test cases with assertEquals(). I do not know how to do for this method :

public class Apc7Engine extends BaseEngine {

/**
 * This method retrieve plannings 
 * in APC7 configuration
 * 
 * It is an implementation of an abstract method
 * from BaseEngine.java
 *
 */
@Override
public void retrievePlannings() {
    LogCvaultImport.code(200).debug("A7: start retrievePlannings");
    try {
        List importList = DummyApc7DAOFactory.getDAO().getDummyApc7();
        Iterator poIterator = importList.iterator();

        while(poIterator.hasNext()) {
             DummyApc7 dummy = (DummyApc7) poIterator.next();
             PlanningObject planning = new PlanningObject();
             planning.setAchievedDate(dummy.getLastUpdate());
             planning.setAircraftType(dummy.getAcType());
             planning.setBaselineDate(dummy.getLastUpdate());
             planning.setDeliverySite(dummy.getDeliverySite());
             planning.setEventId(dummy.getEvtId());
             planning.setEventName(dummy.getEvent());
             planning.setEventStatus(dummy.getEvtStatus());
             planning.setLastUpdate(dummy.getLastUpdate());
             planning.setModel(dummy.getModel());
             planning.setMsn(dummy.getMsn());
             planning.setOperator(dummy.getOperator());
             planning.setOwner(dummy.getOwner());
             planning.setProgram(dummy.getProg());
             planning.setSerial(dummy.getSerial());
             planning.setTargetDate(dummy.getLastUpdate());
             planning.setVersion(dummy.getVersion());
             planning.setVersionRank(dummy.getVersionRank());
             LogCvaultImport.code(800).info("A7|Event name: "+planning.getEventName()+" - MSN: "+planning.getMsn()+" - Delivery site: "+planning.getDeliverySite());
             listPlanningObject.add(planning);        
        }
    } catch (DAOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    LogCvaultImport.code(1000).debug("A7: end retrievePlannings");
}

}

I retrieve an object from the DB. Then I fill a List from the PlanningObject class with the DB data. I do not have any idea how to realize jUnit test cases about it. I heard about mock?

Thanks guys !

Aucun commentaire:

Enregistrer un commentaire