//$Id: TestCase.java,v 1.2 2003/12/17 17:37:41 turin Exp $
package org.hibernate.admin.test;
import java.util.HashMap;
import org.hibernate.admin.action.*;
import org.hibernate.admin.component.*;
import org.hibernate.admin.model.*;
import com.opensymphony.xwork.ActionContext;
import net.sf.hibernate.HibernateException;
/**
* @author Gavin King
*/
public class TestCase extends junit.framework.TestCase {
private HibernateSession hs;
private static final HibernateSessionFactory hsf;
static {
hsf = new HibernateSessionFactory();
hsf.init();
}
public void init(HibernateSessionAware action) throws HibernateException {
hs = new HibernateSession();
hs.setHibernateSessionFactory(hsf);
action.setHibernateSession(hs);
if ( ActionContext.getContext().getSession()==null )
ActionContext.getContext().setSession( new HashMap() );
}
public void dispose() throws Exception {
hs.disposeSession();
}
public void testSearchUsers() throws Exception {
SearchUsersAction su = new SearchUsersAction();
init(su);
//su.getUserExampleName().setFirstName("Foo");
su.getUserExample().setEmail("foo%");
su.getUserExampleName().setInitial( new Character('F') );
su.setRoleName("A Role");
su.setMaxUsers(5);
su.execute();
assertTrue( su.getUsers()!=null );
dispose();
}
public void testCreateUser() throws Exception {
CreateUserAction cu = new CreateUserAction();
init(cu);
User u = cu.getUser();
u.setEmail("
[email protected]");
u.setHandle("foonew");
u.setPassword("bar");
u.getName().setFirstName("Foo");
cu.execute();
dispose();
}
public void testCreateRole() throws Exception {
CreateRoleAction cr = new CreateRoleAction();
init(cr);
Role r = cr.getRole();
r.setName("A Role");
r.setDescription("A role for testing");
cr.execute();
dispose();
}
public void testListRoles() throws Exception {
ListRolesAction lr = new ListRolesAction();
init(lr);
lr.execute();
assertTrue( lr.getRoles()!=null );
dispose();
}
public void testCreateUserRole() throws Exception {
CreateUserAction cu = new CreateUserAction();
init(cu);
User u = cu.getUser();
u.setEmail("
[email protected]");
u.setHandle("fooBar");
u.setPassword("bar");
u.getName().setFirstName("Foo");
cu.execute();
dispose();
CreateRoleAction cr = new CreateRoleAction();
init(cr);
Role r = cr.getRole();
r.setName("Another Role");
r.setDescription("A role for testing");
cr.execute();
dispose();
}
}