Getting error while trying to test Spring WS client with JAX-WS

1,247 views
Skip to first unread message

Nihar Ranjan Pattanaik

unread,
Nov 10, 2013, 11:28:25 PM11/10/13
to smock...@googlegroups.com
Dear Team,

I have written Spring JAX-WS client to consume SOAP Service. I'm trying to test the same using SMOCK, however i'm getting exception while loading the spring context. Same is working fine if i'm not running SMOCK test class. Could someone please help.
Attached my test class and config file for reference. The exception i got 

java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productsPort' defined in URL [file:resources/billing_app_context_1.xml]: Invocation of init method failed; nested exception is java.lang.AssertionError: No further connections expected
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 25 more
Caused by: java.lang.AssertionError: No further connections expected
at net.javacrumbs.smock.extended.client.connection.MockConversation.getActiveConnection(MockConversation.java:71)
at net.javacrumbs.smock.extended.client.connection.threadlocal.ThreadLocalMockWebServiceServer.getActiveConnection(ThreadLocalMockWebServiceServer.java:47)
at net.javacrumbs.smock.http.client.connection.threadlocal.http.ThreadLocalMockHttpUrlConnection.<init>(ThreadLocalMockHttpUrlConnection.java:30)
at net.javacrumbs.smock.http.client.connection.threadlocal.http.Handler.openConnection(Handler.java:37)
at net.javacrumbs.smock.http.client.connection.threadlocal.http.Handler.openConnection(Handler.java:32)
at java.net.URL.openConnection(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
at javax.xml.ws.Service.create(Unknown Source)
at org.springframework.remoting.jaxws.LocalJaxWsServiceFactory.createJaxWsService(LocalJaxWsServiceFactory.java:137)
at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.prepare(JaxWsPortClientInterceptor.java:334)
at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.afterPropertiesSet(JaxWsPortClientInterceptor.java:316)
at org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean.afterPropertiesSet(JaxWsPortProxyFactoryBean.java:42)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
... 40 more


Regards,
Nihar
TestClient.java
billing_app_context_1.xml

Lukáš Křečan

unread,
Nov 11, 2013, 4:47:18 AM11/11/13
to smock...@googlegroups.com
Hi,
  it seems that your bean productsPort is trying to access some web service on initialization and the mock is not configured yet. There are two options. Either postpone the network call or initialize the mock before application context start.
   Cheers
     Lukas
--
Tuto zprávu jste obdrželi, protože jste přihlášeni k odběru skupiny smock-info ve Skupinách Google.
Pokud chcete zrušit odběr skupiny, aby vám z ní již nechodily e-maily, zašlete e-mail na adresu smock-info+...@googlegroups.com.
Další možnosti najdete na adrese https://groups.google.com/groups/opt_out.

Nihar Ranjan Pattanaik

unread,
Nov 11, 2013, 11:11:50 PM11/11/13
to smock...@googlegroups.com
Hi Lukas,

Many thanks for your response. I'm still struggling to get it work. Both the option you have pointed out i have re-looked

1 - The mock server is getting started before the context loads as i'm extending my test class to AbstractSmockClientTest.
2 - The live service is also available and i'm able to invoke with the same bean configuration file directly without SMOCK test class.

Ideally if mock server is started the test framework should not look into the live service. Could you please help ?

Regards,
Nihar


--
Tuto zprávu jste obdrželi, protože jste přihlášeni k odběru tématu ve skupině „smock-info“ v rámci Skupin Google.
Pokud chcete odběr tématu zrušit, přejděte na https://groups.google.com/d/topic/smock-info/1yvvA64N85Y/unsubscribe.
Pokud chcete zrušit odběr skupiny a všech témat v ní, zašlete e-mail na adresu smock-info+...@googlegroups.com.

Lukáš Křečan

unread,
Nov 12, 2013, 10:09:03 AM11/12/13
to smock...@googlegroups.com
I am sorry, I will not have time to help you.
�� Lukas


On 12/11/13 05:11, Nihar Ranjan Pattanaik wrote:
Hi Lukas,

Many thanks for your response. I'm still struggling to get it work. Both the option you have pointed out i have re-looked

1 - The mock server is getting started before the context loads as i'm extending my test class to�AbstractSmockClientTest.
2 - The live service is also available and i'm able to invoke with the same bean configuration file directly without SMOCK test class.

Ideally if mock server is started the test framework should not look into the live service. Could you please help ?

Regards,
Nihar


On Mon, Nov 11, 2013 at 3:17 PM, Luk� K�e�an <lu...@krecan.net> wrote:
Hi,
ďż˝ it seems that your bean productsPort is trying to access some web service on initialization and the mock is not configured yet. There are two options. Either postpone the network call or initialize the mock before application context start.
�� Cheers
���� Lukas
ďż˝

On 11/11/13 05:28, Nihar Ranjan Pattanaik wrote:
Dear Team,

I have written Spring JAX-WS client to consume SOAP Service. I'm trying to test the same using SMOCK, however i'm getting exception while loading the spring context. Same is working fine if i'm not running SMOCK test class. Could someone please help.
Attached my test class and config file for reference. The exception i gotďż˝
--
Tuto zpr�vu jste obdr�eli, proto�e jste p�ihl�eni k odb�ru skupiny smock-info ve Skupin�ch Google.
Pokud chcete zru�it odb�r skupiny, aby v�m z n� ji� nechodily e-maily, za�lete e-mail na adresu smock-info+...@googlegroups.com.
Dal�� mo�nosti najdete na adrese https://groups.google.com/groups/opt_out.

--
Tuto zprďż˝vu jste obdrďż˝eli, protoďż˝e jste pďż˝ihlďż˝eni k odbďż˝ru tďż˝matu ve skupinďż˝ „smock-info“ v rďż˝mci Skupin Google.
Pokud chcete odb�r t�matu zru�it, p�ejd�te na https://groups.google.com/d/topic/smock-info/1yvvA64N85Y/unsubscribe.
Pokud chcete zru�it odb�r skupiny a v�ech t�mat v n�, za�lete e-mail na adresu smock-info+...@googlegroups.com.
Dal�� mo�nosti najdete na adrese https://groups.google.com/groups/opt_out.

--
Tuto zpr�vu jste obdr�eli, proto�e jste p�ihl�eni k odb�ru skupiny smock-info ve Skupin�ch Google.
Pokud chcete zru�it odb�r skupiny, aby v�m z n� ji� nechodily e-maily, za�lete e-mail na adresu smock-info+...@googlegroups.com.
Dal�� mo�nosti najdete na adrese https://groups.google.com/groups/opt_out.

Lukáš Křečan

unread,
Nov 16, 2013, 8:47:53 AM11/16/13
to smock...@googlegroups.com
Hi,
�Yes, the mock server is started, but no mock responses were defined yet. Which causes the issue. The flow is in my opinion following

1) The mock server starts
2) Spring is initializing beans
3) productsPort is trying to invoke some service upon initialization
4) No mock response was defined yet, so an exception is thrown

It's hard to help you without having access to the code. Can you please send me the test? But In think that it should be sufficient to define some mock response just after the place where you setup the mock server.
�� Cheers
����� Lukas



On 12.11.2013 05:11, Nihar Ranjan Pattanaik wrote:
Hi Lukas,

Many thanks for your response. I'm still struggling to get it work. Both the option you have pointed out i have re-looked

1 - The mock server is getting started before the context loads as i'm extending my test class to�AbstractSmockClientTest.
2 - The live service is also available and i'm able to invoke with the same bean configuration file directly without SMOCK test class.

Ideally if mock server is started the test framework should not look into the live service. Could you please help ?

Regards,
Nihar
On Mon, Nov 11, 2013 at 3:17 PM, Luk� K�e�an <lu...@krecan.net> wrote:
Hi,
ďż˝ it seems that your bean productsPort is trying to access some web service on initialization and the mock is not configured yet. There are two options. Either postpone the network call or initialize the mock before application context start.
�� Cheers
���� Lukas
ďż˝

On 11/11/13 05:28, Nihar Ranjan Pattanaik wrote:
Dear Team,

I have written Spring JAX-WS client to consume SOAP Service. I'm trying to test the same using SMOCK, however i'm getting exception while loading the spring context. Same is working fine if i'm not running SMOCK test class. Could someone please help.
Attached my test class and config file for reference. The exception i gotďż˝
--
Tuto zpr�vu jste obdr�eli, proto�e jste p�ihl�eni k odb�ru skupiny smock-info ve Skupin�ch Google.
Pokud chcete zru�it odb�r skupiny, aby v�m z n� ji� nechodily e-maily, za�lete e-mail na adresu smock-info+...@googlegroups.com.
Dal�� mo�nosti najdete na adrese https://groups.google.com/groups/opt_out.

--
Tuto zprďż˝vu jste obdrďż˝eli, protoďż˝e jste pďż˝ihlďż˝eni k odbďż˝ru tďż˝matu ve skupinďż˝ „smock-info“ v rďż˝mci Skupin Google.
Pokud chcete odb�r t�matu zru�it, p�ejd�te na https://groups.google.com/d/topic/smock-info/1yvvA64N85Y/unsubscribe.
Pokud chcete zru�it odb�r skupiny a v�ech t�mat v n�, za�lete e-mail na adresu smock-info+...@googlegroups.com.
Dal�� mo�nosti najdete na adrese https://groups.google.com/groups/opt_out.

--
Tuto zpr�vu jste obdr�eli, proto�e jste p�ihl�eni k odb�ru skupiny smock-info ve Skupin�ch Google.
Pokud chcete zru�it odb�r skupiny, aby v�m z n� ji� nechodily e-maily, za�lete e-mail na adresu smock-info+...@googlegroups.com.
Dal�� mo�nosti najdete na adrese https://groups.google.com/groups/opt_out.

jan.sik...@gmail.com

unread,
Jun 27, 2014, 4:30:47 AM6/27/14
to smock...@googlegroups.com
Hi.

I had similar issue. I try to do real call to web service and after that i mock the WebServiceTemplate for some different test by:
MockWebServiceServer mockServer = MockWebServiceServer.createServer(client.getWebServiceTemplate());
Test work but i had several similar tests... Firsts tests were OK but another FAIL if i start all tests. But if i start single test to some else web service (which fail - in testing all tests) then test pass.

REASON:
You probably configure in your application context the WebServiceTemplat which is used on all web services. This mean that my first test do real call to web servece, then i mock the WebServiceTemplat by code above and ALL others test which works with the WebServiceTemplat work with mocked version. And of cource... mock need some expectations. Then when i try to call real web service in other test i couldn't because WebServiceTemplate was corrupted by mock.

SOLUTION:
Use the @DirtiesContext annotation inside thet that probably corrupt your WebServiceTemplat.

I hope that this is solution of your issue or this will help to somebody else.
Good luck.


Reply all
Reply to author
Forward
0 new messages