Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC 3.2 JUnit testing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC 3.2 JUnit testing

    Hi, I just upgraded to Spring 3.2 and I'm doing some Spring MVC Unit testing. Here's my code:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath*:controller-servlet.xml")
    @WebAppConfiguration
    public class ErrorsViewAllTest {

    @Autowired
    private WebApplicationContext ctx;

    @Autowired
    private MockHttpSession session;

    private MockMvc mockMvc;

    @Before
    public void setUp() {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.ctx).build ();
    }

    @Test
    public void allErrors() throws Exception {

    mockMvc.perform(get("/report/allerrors").accept(MediaType.TEXT_HTML))
    .andExpect(status().isOk())
    .andExpect(view().name("/report/allerrors.html"));
    }

    }

    The problem is I'm getting a connection error when executing this test on my Intellij IDE. It seems it's having CORBA issues when connecting to glassfish server 3. What am I missing? Hope you can help. Thanks.


    Here's the error I'm getting:

    Feb 05, 2013 3:01:55 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
    INFO: Refreshing org.springframework.web.context.support.GenericWeb ApplicationContext@5d38c394: startup date [Tue Feb 05 15:01:55 EST 2013]; root of context hierarchy
    Feb 05, 2013 3:01:55 PM org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor <init>
    INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
    Feb 05, 2013 3:01:55 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@7205c140: defining beans [org.springframework.context.annotation.internalCon figurationAnnotationProcessor,org.springframework. context.annotation.internalAutowiredAnnotationProc essor,org.springframework.context.annotation.inter nalRequiredAnnotationProcessor,org.springframework .context.annotation.internalCommonAnnotationProces sor,org.springframework.context.annotation.interna lPersistenceAnnotationProcessor,org.springframewor k.context.annotation.ConfigurationClassPostProcess or.importAwareProcessor]; root of factory hierarchy
    org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700 vmcid: OMG minor code: 1 completed: No
    at sun.reflect.GeneratedConstructorAccessor32.newInst ance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Construc tor.java:525)
    at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExte nsion.makeException(CorbaExtension.java:248)
    at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExte nsion.makeException(CorbaExtension.java:95)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerato r.handleFullLogging(WrapperGenerator.java:387)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerato r.access$400(WrapperGenerator.java:107)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerato r$2.invoke(WrapperGenerator.java:511)
    at com.sun.corba.ee.spi.orbutil.proxy.CompositeInvoca tionHandlerImpl.invoke(CompositeInvocationHandlerI mpl.java:99)
    at $Proxy31.connectFailure(Unknown Source)
    at com.sun.corba.ee.impl.transport.SocketOrChannelCon nectionImpl.<init>(SocketOrChannelConnectionImpl.j ava:257)
    at com.sun.corba.ee.impl.transport.SocketOrChannelCon nectionImpl.<init>(SocketOrChannelConnectionImpl.j ava:270)
    at com.sun.corba.ee.impl.transport.SocketOrChannelCon tactInfoImpl.createConnection(SocketOrChannelConta ctInfoImpl.java:129)
    at com.sun.corba.ee.impl.protocol.CorbaClientRequestD ispatcherImpl.beginRequest(CorbaClientRequestDispa tcherImpl.java:223)
    at com.sun.corba.ee.impl.protocol.CorbaClientDelegate Impl.request(CorbaClientDelegateImpl.java:228)
    at com.sun.corba.ee.impl.protocol.CorbaClientDelegate Impl.is_a(CorbaClientDelegateImpl.java:393)
    at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl .java:130)
    at org.omg.CosNaming.NamingContextHelper.narrow(Namin gContextHelper.java:69)
    at com.sun.enterprise.naming.impl.SerialContext$Provi derCacheKey.getNameService(SerialContext.java:1239 )
    at com.sun.enterprise.naming.impl.SerialContext.getRe moteProvider(SerialContext.java:410)
    at com.sun.enterprise.naming.impl.SerialContext.getPr ovider(SerialContext.java:346)
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:504)
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext. java:411)
    at org.springframework.jndi.JndiTemplate$1.doInContex t(JndiTemplate.java:154)
    at org.springframework.jndi.JndiTemplate.execute(Jndi Template.java:87)
    at org.springframework.jndi.JndiTemplate.lookup(JndiT emplate.java:152)
    at org.springframework.jndi.JndiTemplate.lookup(JndiT emplate.java:178)
    at org.springframework.jndi.JndiLocatorSupport.lookup (JndiLocatorSupport.java:104)
    at org.springframework.jndi.JndiLocatorDelegate.looku p(JndiLocatorDelegate.java:38)
    at org.springframework.jndi.JndiLocatorSupport.lookup (JndiLocatorSupport.java:77)
    at org.springframework.jndi.JndiLocatorDelegate.looku p(JndiLocatorDelegate.java:33)
    at org.springframework.jndi.JndiPropertySource.getPro perty(JndiPropertySource.java:82)
    at org.springframework.core.env.PropertySourcesProper tyResolver.getProperty(PropertySourcesPropertyReso lver.java:73)
    at org.springframework.core.env.PropertySourcesProper tyResolver.getProperty(PropertySourcesPropertyReso lver.java:59)
    at org.springframework.core.env.AbstractEnvironment.g etProperty(AbstractEnvironment.java:427)
    at org.springframework.context.support.LiveBeansView. registerApplicationContext(LiveBeansView.java:60)
    at org.springframework.context.support.AbstractApplic ationContext.finishRefresh(AbstractApplicationCont ext.java:951)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:482)
    at org.springframework.test.context.web.AbstractGener icWebContextLoader.loadContext(AbstractGenericWebC ontextLoader.java:116)
    at org.springframework.test.context.web.AbstractGener icWebContextLoader.loadContext(AbstractGenericWebC ontextLoader.java:59)
    at org.springframework.test.context.support.AbstractD elegatingSmartContextLoader.delegateLoading(Abstra ctDelegatingSmartContextLoader.java:100)
    at org.springframework.test.context.support.AbstractD elegatingSmartContextLoader.loadContext(AbstractDe legatingSmartContextLoader.java:248)
    at org.springframework.test.context.TestContext.loadA pplicationContext(TestContext.java:124)
    at org.springframework.test.context.TestContext.getAp plicationContext(TestContext.java:148)
    at org.springframework.test.context.web.ServletTestEx ecutionListener.setUpRequestContextIfNecessary(Ser vletTestExecutionListener.java:103)
    at org.springframework.test.context.web.ServletTestEx ecutionListener.prepareTestInstance(ServletTestExe cutionListener.java:73)
    at org.springframework.test.context.TestContextManage r.prepareTestInstance(TestContextManager.java:313)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.createTest(SpringJUnit4ClassRunner.j ava:211)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner$1.runReflectiveCall(SpringJUnit4Clas sRunner.java:288)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.methodBlock(SpringJUnit4ClassRunner. java:284)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:231)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:88)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRu nner.java:173)
    at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
    at org.springframework.test.context.junit4.statements .RunBeforeTestClassCallbacks.evaluate(RunBeforeTes tClassCallbacks.java:61)
    at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)
    at org.springframework.test.context.junit4.statements .RunAfterTestClassCallbacks.evaluate(RunAfterTestC lassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:220)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:174 )
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunn erWithArgs(JUnit4IdeaTestRunner.java:71)
    at com.intellij.rt.execution.junit.JUnitStarter.prepa reStreamsAndStart(JUnitStarter.java:199)
    at com.intellij.rt.execution.junit.JUnitStarter.main( JUnitStarter.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main (AppMain.java:120)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.CommandLineWrapper.main( CommandLineWrapper.java:75)
    Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFa ctory.createSocket(IIOPSSLSocketFactory.java:339)
    at com.sun.corba.ee.impl.transport.SocketOrChannelCon nectionImpl.<init>

  • #2
    It looks like your configuration (controller-servlet.xml) includes a LiveBeansView, which attempts to get a property through PropertySourcesPropertyResolver for a JndiPropertySource. I'm not sure how the JndiPropertySource gets configured (possibly through an environment or system variable?) but it's the call to JNDI that fails. It doesn't seem related to Spring MVC testing but to loading the configuration. You could experiment with loading the configuration from a main method, i.e. new XmlWebApplicationContext.

    Comment


    • #3
      The JndiPropertySource gets registered automatically in StandardServletEnvironment which is used by GenericWebApplicationContext which in turn is used by the Spring TestContext Framework when loading a WebApplicationContext for integration tests.

      However, the JndiPropertySource should only be registered if the code is running in a JNDI-capable environment.

      So I guess there are two options here:
      1. Figure out why org.springframework.jndi.JndiLocatorDelegate.isDef aultJndiEnvironmentAvailable() returns true when your tests run, or perhaps more importantly figure out why JNDI look-ups are attempting to connect to localhost:3700; and make that not happen.
      2. Remove the LiveBeansView from your application context configuration for your integration tests.

      In general, for integration tests like this you want to make sure that you are not using configuration that points to production configuration or external servers (i.e., hosts and ports) that are unavailable during test execution.

      Regards,

      Sam

      p.s. note that JndiLocatorDelegate.isDefaultJndiEnvironmentAvaila ble() basically returns true if it can instantiate a new InitialContext() without error.

      Comment

      Working...
      X