2016-05-02 5 views
0

Hallo, ich versuche, meinen Webservice mit JUnit im Frühjahr zu testen. Ich habe diesen Test geschrieben:Fehler beim Testen eines Spring-Webdienstes mit JUnit 4

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = {"classpath:META-INF/applicationContext.xml"}) 
@TransactionConfiguration 
@Transactional 

@SuppressWarnings("unused") 
public class SiteTest { 

@Mock 
public IBusiness siteBusiness; 
@Autowired 
public ManageImpl managesiteI; 

List<GeographicSite> sitesJson = null; 

@Before 
public void init() { 
    MockitoAnnotations.initMocks(this); 
    siteApplicationImpl=new ManageSiteImpl(siteApplicationBusiness); 
} 
@Test 
public void testSizeOfSIte() throws ExceptionApiV2 { 
try { 

    when(managesiteI.geographicSitesAPIV2(Mockito.eq((Integer)10), Mockito.eq((Integer)0), Mockito.anyString(), Mockito.anyString(), 
      Mockito.eq("CI00002384"),Mockito.eq("CI00002394"), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), 
      Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString(), Mockito.anyString())).thenReturn(resultat); 



    } catch (Exception e) { 
     System.out.println("ERRO MOCKITO: "+e); 
    } 
    sitesJson=managesiteI.geographicSitesAPIV2(10, 0, "site.id", null, "CI00002384" , "CI00002394", null, null, null, null, null, null, null, null, null, null); 

ich hinzugefügt haben, die applicationContext.xml alle Abhängigkeiten hinzugefügt, die ich dachte, ich benötigt, doch ist es nicht funktioniert, erste bekam ich einen Fehler von log dieser Art:

log4j:WARN No appenders could be found for logger (com.mchange.v2.log.MLog). 
log4j:WARN Please initialize the log4j system properly. 

schaffte ich es mit einer statischen Methode zu überspringen, aber ich habe immer diese Fehlermeldung:

Destroying singletons in org.springframework.beans.factory.suppo[email protected]: defining beans [propertyConfigurer,getActor.proxyFactory,getActor,actorBusinessImpl,manageSiteSoapProxy,manageSiteSoapProxyFactory,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionInterceptor,transactionManager,transactionAttributes,autoProxyTransactionCreator,dataSource,siterefEntityManagerFactory,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0]; root of factory hierarchy 
Caught exception while allowing TestExecutionListener [org.springframewor[email protected]8fb4c62] to prepare test instance [[email protected]] 
java.lang.IllegalStateException: Failed to load ApplicationContext 
at  org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157) ~[spring-test-3.1.0.RELEASE.jar:3.1.0.RELEASE] 

Und ich habe dies als verursacht durch:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [META-INF/jpaDaoContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'siterefEntityManagerFactory' defined in class path resource [META-INF/jpaDaoContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/resource/spi/XATerminator 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) ~[spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE] 

EDIT

ich habe diesen Fehler vor teh zuletzt: Ich glaube nicht, dass ich das gleiche Problem wie die andere Frage;

Caused by: org.springframework.beans.factory.BeanCreationException: Error  creating bean with name 'siterefEntityManagerFactory' defined in class path  resource [META-INF/jpaDaoContext.xml]: Invocation of init method failed; nested  exception is java.lang.NoClassDefFoundError: javax/resource/spi/XATerminator 

**** Edit 2 ***
Nach dem Hinzufügen der Abhängigkeit von javax.resource Ich habe diese/

Bean 'siterefEntityManagerFactory' of type [class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
Pre-instantiating singletons in org.s[email protected]72ee3d51: defining beans [propertyConfigurer,getActor.proxyFactory,getActor,.....]; root of factory hierarchy 
FactoryBean threw exception from getObjectType, despite the contract saying  that it should return null if the type of its object cannot be determined yet` 

Jeder eine Idee? Was vermisse ich ? , wenn Sie denken, dass ich sollte Detail etwas lassen Sie mich wissen, Danke für Sie Antworten und Kommentare

+0

nicht u die Frage bearbeitet haben, diesen Punkt zu klären :) –

+0

Ist das ein Fehler oder eine Warnung? Es sollte dort im Protokoll sein. – randominstanceOfLivingThing

+0

können Sie Ihre applicationContext.xml auch posten. – randominstanceOfLivingThing

Antwort

0

nested exception is java.lang.NoClassDefFoundError: javax/resource/spi/XATerminator

ein Anzeichen dafür ist, dass Sie das Glas fehlen in Sie classpath, wenn die Teststandalone läuft. Sie scheinen die Java-Ressourcen-API im Klassenpfad zu vermissen. Wenn Sie Maven verwenden, müssen Sie diese Abhängigkeit zum Testen hinzufügen.

<dependency> 
<groupId>javax.resource</groupId> 
<artifactId>javax.resource-api</artifactId> 
<version>1.7</version> 
<scope>test</scope> 
</dependency> 

Verwandte post

+0

Vielen Dank für Ihre Antwort, ich habe diese Abhängigkeit nicht hinzugefügt, und man bekommt nicht mehr den vorherigen Fehler, stattdessen habe ich diesen, in der zweiten Bearbeitung –