
now i am posting my code here . i got error of sessionfactory. so tell me where i declare sessionfactory method ........
package net.action;
import org.hibernate.Session; import org.hibernate.SessionFactory; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.orm.hibernate3.SessionFactoryUtils; import org.springframework.orm.hibernate3.SessionHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.web.context.WebApplicationContext;
import com.opensymphony.xwork2.Action;
public class TestNew extends TestBase {
protected FileSystemXmlApplicationContext context = null; protected SessionFactory sessionFactory=null ; protected ApplicationContext applicationContext; private AccountAction currentAction;
public String getContextLocations() { return "/applicationContext.xml"; }
protected void init() { servletContext.setAttribute( WebApplicationContext.ROOTWEBAPPLICATIONCONTEXTATTRIBUTE, applicationContext); }
/** * setup method is called before test */ protected void setUp() throws Exception { super.setUp();
//String[] contextLocations = new String[1]; //contextLocations[0] = "test/applicationContext.xml"; //contextLocations[1] = "src/test/applicationContext.xml"; context = new FileSystemXmlApplicationContext("test/applicationContext.xml"); System.out.println("see ");
sessionFactory = (SessionFactory) context.getBean("sessionFactory"); System.out.println("pl check it"); Session session = SessionFactoryUtils.getSession(sessionFactory,false); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); }
@Test public void tests() throws Exception {
request.setAttribute("account.username", "hello"); request.setAttribute("account.password", "test");
// code to set test action environment createAction("/create", "Test", "list");
// code to execute test action String result = proxy.execute();
// code to test action result assertEquals("valid Page...", Action.SUCCESS, result);
System.out.println("List successfully dispalyed ....");
}
/** * @param currentAction * the currentAction to set */ public void setCurrentAction(AccountAction currentAction) { this.currentAction = currentAction; }
/** * @return the currentAction */ public AccountAction getCurrentAction() { return currentAction; }
public SessionFactory getSessionFactory(){
return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory){ this.sessionFactory=sessionFactory;
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.