vendredi 30 octobre 2015

Session closed exception thrown while testing Spring+Hibernate Service using TestNG

I am trying to learn testing web services with TestNG. I got some project code from my friend.It uses spring for auto-wiring and hibernate for database connectivity.So I was trying to test a service.But its throwing exception

    Session is closed!; nested exception is javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed! 

But I tested the same with JUnit and no such exception was thrown.The service code is perfect and I am sure about it.So I believe that its an issue with my testing code.

The java test class is:

    @ContextConfiguration(locations={"classpath:testapplicationContext.xml"})
    @Transactional
    @TransactionConfiguration(transactionManager = "jpaTransactionManager", defaultRollback = false)
    public class TreatmentTypeManagementServiceImplTest extends AbstractTestNGSpringContextTests 
    {


      @Autowired
      TreatmentTypeManagementService treatmentTypeManagementService;  

      @Test()
      public void addTreatmentTypeTest() {
          TreatmentTypeUI TreatmentType = new TreatmentTypeUI();
          LoginUserInfo loginUserInfo = new LoginUserInfo();
          TreatmentType.setLabelText("fever");
          loginUserInfo.setSessionCompanyNid(555646);
          loginUserInfo.setUserNid(26416161);


          treatmentTypeManagementService.addTreatmentType(TreatmentType, loginUserInfo);
      } 
    }

The configuration xml is running fine with JUnit, So I believe there is no error in that.can you help me find a solution.

Aucun commentaire:

Enregistrer un commentaire