0

Zeta problem

asked 2009-05-07 07:46:30 +0800

A gravatar image A
117 2

updated 2009-05-07 07:49:21 +0800

hi,all
I create a project and use the Zeta Form Wizard,but how can i use junit4.4 in my project?
When I was tested as usual,i get the following exception

Caught exception while allowing TestExecutionListener [org.springframewor[email protected]13af084] to prepare test instance [[email protected]1b8]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mo.org.sgvd.dao.TsaletypeDAOTest': Injection of resource fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tsaletypeDAO': Scope 'idspace' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: Unable to get idspace scope bean: tsaletypeDAO. Do you access it in ZK event listener?
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:293)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:957)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:93)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:130)
	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tsaletypeDAO': Scope 'idspace' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: Unable to get idspace scope bean: tsaletypeDAO. Do you access it in ZK event listener?
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:312)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:671)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:610)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:423)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:502)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180)
	at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:290)
	... 18 more
Caused by: java.lang.IllegalStateException: Unable to get idspace scope bean: tsaletypeDAO. Do you access it in ZK event listener?
	at org.zkoss.spring.web.context.request.IdSpaceScope.get(IdSpaceScope.java:80)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
	... 27 more
2009-5-7 13:43:15 org.springframework.context.support.AbstractApplicationContext doClose

Any ides?
thx
by Cary

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2009-05-07 07:56:08 +0800

A gravatar image A
117 2

test code
TsaletypeDAOTest.java

public class TsaletypeDAOTest extends BaseDAOTestCaseJunit44 {

	private Tsaletype saletype;
	
	@Resource
	protected TsaletypeDAO beanDAO;

	public TsaletypeDAO getDAO() {
		return beanDAO;
	}

	public void setDAO(TsaletypeDAO beanDAO) {
		this.beanDAO = beanDAO;
	}

	
	@Before
	public void init(){
	}
	
	@Test
	public void save(){
		saletype = new Tsaletype();
		saletype.setSaletypeid(new BigDecimal(2));
		saletype.setSaletypename("djfk");
		beanDAO.persist(saletype);
		//BigDecimal primaryKey = saletype.getSaletypeid();
		//assertTrue(" The return value must not be null", primaryKey > 0);
		assertEquals("djfk", saletype.getSaletypename());
	}
}


BaseDAOTestCaseJunit44.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
		"classpath:/mo/org/sgvd/config/application-context.xml",
		"classpath:/mo/org/sgvd/config/datasource-context.xml" })
@TransactionConfiguration(transactionManager = "transactionManager",
		defaultRollback = true)
@Transactional
public class BaseDAOTestCaseJunit44 {

}

link publish delete flag offensive edit

answered 2009-05-07 07:57:19 +0800

A gravatar image A
117 2

My DAO
TsaletypeDAO.java

package mo.org.sgvd.dao;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import mo.org.sgvd.domain.Tsaletype;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.zkoss.spring.jpa.BasicDAO;
import org.zkoss.spring.jpa.EntityNotFoundException;

@Scope("idspace")
@Repository
public class TsaletypeDAO {
	@Resource
	protected BasicDAO basicDAO;

	public BasicDAO getBasicDao() {
		return basicDAO;
	}

	public void setBasicDao(BasicDAO basicDao) {
		this.basicDAO = basicDao;
	}
	
	@SuppressWarnings("unchecked")
	@Transactional(readOnly=true)
	public List<Tsaletype> find(String queryString, int offset, int maxResults, Map<String,?> params) {
		List<?> all = this.basicDAO.find(queryString, offset, maxResults, params);
		return (List<Tsaletype>) all;
	}
	
	@SuppressWarnings("unchecked")
	@Transactional(readOnly=true)
	public Object findSingle(String queryString, Map<String,?> params) {
		return this.basicDAO.findSingle(queryString, params);
	}
	
	@Transactional(readOnly=false,propagation = Propagation.REQUIRED)
	public void persist(Tsaletype bean){
		this.basicDAO.persist(bean);
	}
	
	@Transactional(readOnly=false,propagation = Propagation.REQUIRED)
	public void delete(Tsaletype bean) throws EntityNotFoundException {
		BigDecimal pk = bean.getSaletypeid();

		this.basicDAO.remove(Tsaletype.class, pk);
	}

	@Transactional(readOnly=false,propagation = Propagation.REQUIRED)
	public void merge(Tsaletype bean) throws EntityNotFoundException {
		this.basicDAO.merge(bean);
	}
}

link publish delete flag offensive edit
link publish delete flag offensive edit

answered 2009-05-08 04:34:51 +0800

A gravatar image A
117 2

hi,dennis
Thank you for response,but i use 3.6.0 for now,i want to know how can i test my DAO with junit.
by cary

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-05-07 07:46:30 +0800

Seen: 1,346 times

Last updated: May 08 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More