package com.vst.service;
import java.util.List;
import java.util.ArrayList;
import com.vst.service.BaseManagerTestCase;
import com.vst.dao.AuthentificationElementDao;
import com.vst.model.AuthentificationElement;
import com.vst.service.impl.AuthentificationElementManagerImpl;
import org.jmock.Mock;
import org.springframework.orm.ObjectRetrievalFailureException;
public class AuthentificationElementManagerTest extends BaseManagerTestCase {
private final String authentificationElementId = "1";
private AuthentificationElementManagerImpl authentificationElementManager = new AuthentificationElementManagerImpl();
private Mock authentificationElementDao = null;
protected void setUp() throws Exception {
super.setUp();
authentificationElementDao = new Mock(AuthentificationElementDao.class);
authentificationElementManager.setAuthentificationElementDao((AuthentificationElementDao) authentificationElementDao.proxy());
}
protected void tearDown() throws Exception {
super.tearDown();
authentificationElementManager = null;
}
public void testGetAuthentificationElements() throws Exception {
List results = new ArrayList();
AuthentificationElement authentificationElement = new AuthentificationElement();
results.add(authentificationElement);
// set expected behavior on dao
authentificationElementDao.expects(once()).method("getAuthentificationElements")
.will(returnValue(results));
List authentificationElements = authentificationElementManager.getAuthentificationElements(null);
assertTrue(authentificationElements.size() == 1);
authentificationElementDao.verify();
}
public void testGetAuthentificationElement() throws Exception {
// set expected behavior on dao
authentificationElementDao.expects(once()).method("getAuthentificationElement")
.will(returnValue(new AuthentificationElement()));
AuthentificationElement authentificationElement = authentificationElementManager.getAuthentificationElement(authentificationElementId);
assertTrue(authentificationElement != null);
authentificationElementDao.verify();
}
public void testSaveAuthentificationElement() throws Exception {
AuthentificationElement authentificationElement = new AuthentificationElement();
// set expected behavior on dao
authentificationElementDao.expects(once()).method("saveAuthentificationElement")
.with(same(authentificationElement)).isVoid();
authentificationElementManager.saveAuthentificationElement(authentificationElement);
authentificationElementDao.verify();
}
public void testAddAndRemoveAuthentificationElement() throws Exception {
AuthentificationElement authentificationElement = new AuthentificationElement();
// set required fields
// set expected behavior on dao
authentificationElementDao.expects(once()).method("saveAuthentificationElement")
.with(same(authentificationElement)).isVoid();
authentificationElementManager.saveAuthentificationElement(authentificationElement);
authentificationElementDao.verify();
// reset expectations
authentificationElementDao.reset();
authentificationElementDao.expects(once()).method("removeAuthentificationElement").with(eq(new Long(authentificationElementId)));
authentificationElementManager.removeAuthentificationElement(authentificationElementId);
authentificationElementDao.verify();
// reset expectations
authentificationElementDao.reset();
// remove
Exception ex = new ObjectRetrievalFailureException(AuthentificationElement.class, authentificationElement.getAuthentificationId());
authentificationElementDao.expects(once()).method("removeAuthentificationElement").isVoid();
authentificationElementDao.expects(once()).method("getAuthentificationElement").will(throwException(ex));
authentificationElementManager.removeAuthentificationElement(authentificationElementId);
try {
authentificationElementManager.getAuthentificationElement(authentificationElementId);
fail("AuthentificationElement with identifier '" + authentificationElementId + "' found in database");
} catch (ObjectRetrievalFailureException e) {
assertNotNull(e.getMessage());
}
authentificationElementDao.verify();
}
}