package com.vst.service;
import java.util.List;
import java.util.ArrayList;
import com.vst.service.BaseManagerTestCase;
import com.vst.dao.DefectZoneDao;
import com.vst.model.DefectZone;
import com.vst.service.impl.DefectZoneManagerImpl;
import org.jmock.Mock;
import org.springframework.orm.ObjectRetrievalFailureException;
public class DefectZoneManagerTest extends BaseManagerTestCase {
private final String defectZoneId = "1";
private DefectZoneManagerImpl defectZoneManager = new DefectZoneManagerImpl();
private Mock defectZoneDao = null;
protected void setUp() throws Exception {
super.setUp();
defectZoneDao = new Mock(DefectZoneDao.class);
defectZoneManager.setDefectZoneDao((DefectZoneDao) defectZoneDao.proxy());
}
protected void tearDown() throws Exception {
super.tearDown();
defectZoneManager = null;
}
public void testGetDefectZones() throws Exception {
List results = new ArrayList();
DefectZone defectZone = new DefectZone();
results.add(defectZone);
// set expected behavior on dao
defectZoneDao.expects(once()).method("getDefectZones")
.will(returnValue(results));
List defectZones = defectZoneManager.getDefectZones(null);
assertTrue(defectZones.size() == 1);
defectZoneDao.verify();
}
public void testGetDefectZone() throws Exception {
// set expected behavior on dao
defectZoneDao.expects(once()).method("getDefectZone")
.will(returnValue(new DefectZone()));
DefectZone defectZone = defectZoneManager.getDefectZone(defectZoneId);
assertTrue(defectZone != null);
defectZoneDao.verify();
}
public void testSaveDefectZone() throws Exception {
DefectZone defectZone = new DefectZone();
// set expected behavior on dao
defectZoneDao.expects(once()).method("saveDefectZone")
.with(same(defectZone)).isVoid();
defectZoneManager.saveDefectZone(defectZone);
defectZoneDao.verify();
}
public void testAddAndRemoveDefectZone() throws Exception {
DefectZone defectZone = new DefectZone();
// set required fields
// set expected behavior on dao
defectZoneDao.expects(once()).method("saveDefectZone")
.with(same(defectZone)).isVoid();
defectZoneManager.saveDefectZone(defectZone);
defectZoneDao.verify();
// reset expectations
defectZoneDao.reset();
defectZoneDao.expects(once()).method("removeDefectZone").with(eq(new Long(defectZoneId)));
defectZoneManager.removeDefectZone(defectZoneId);
defectZoneDao.verify();
// reset expectations
defectZoneDao.reset();
// remove
Exception ex = new ObjectRetrievalFailureException(DefectZone.class, defectZone.getDefectZoneId());
defectZoneDao.expects(once()).method("removeDefectZone").isVoid();
defectZoneDao.expects(once()).method("getDefectZone").will(throwException(ex));
defectZoneManager.removeDefectZone(defectZoneId);
try {
defectZoneManager.getDefectZone(defectZoneId);
fail("DefectZone with identifier '" + defectZoneId + "' found in database");
} catch (ObjectRetrievalFailureException e) {
assertNotNull(e.getMessage());
}
defectZoneDao.verify();
}
}