package com.vst.dao;
import java.util.List;
import com.vst.dao.BaseDaoTestCase;
import com.vst.model.Material;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.orm.ObjectRetrievalFailureException;
public class MaterialDaoTest extends BaseDaoTestCase {
private Integer materialId = new Integer("1");
private MaterialDao dao = null;
public void setMaterialDao(MaterialDao dao) {
this.dao = dao;
}
public void testAddMaterial() throws Exception {
Material material = new Material();
// set required fields
dao.saveMaterial(material);
// verify a primary key was assigned
assertNotNull(material.getMaterialId());
// verify set fields are same after save
}
public void testGetMaterial() throws Exception {
Material material = dao.getMaterial(materialId);
assertNotNull(material);
}
public void testGetMaterials() throws Exception {
Material material = new Material();
List results = dao.getMaterials(material);
assertTrue(results.size() > 0);
}
public void testSaveMaterial() throws Exception {
Material material = dao.getMaterial(materialId);
// update required fields
dao.saveMaterial(material);
}
public void testRemoveMaterial() throws Exception {
Integer removeId = new Integer("3");
dao.removeMaterial(removeId);
try {
dao.getMaterial(removeId);
fail("material found in database");
} catch (ObjectRetrievalFailureException e) {
assertNotNull(e.getMessage());
} catch (InvalidDataAccessApiUsageException e) { // Spring 2.0 throws this one
assertNotNull(e.getMessage());
}
}
}