Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Junit written for the server method throws error

    Hi Isomorphic!
    On the server side, we're using DSRequest objects. In my junit test method, I'm creating a DSRequest object, using the constructor that passes in the datasource name and the operation type (OP_ADD or OP_UPDATE or OP_FETCH).
    I'm also calling dsRequest.execute passing in a Map of values to create the object. The problem is that when it gets to the part of the real code where I have the "dsRequest.getDataSource()" statement, it throws an Exception. This only happens with the junit method, not in the real app.


    Please help me on the same.

    Thanks,
    Manjula

    #2
    Start by reading the Standalone DataSource Usage overview, which covers special concerns for this use case.

    Then, if you need help, post the actual server logs as required by the forums - please never just say there was an exception, that’s quite useless.

    Comment


      #3
      Hi Isomorphic,

      I tried to change the server.properties file, it doesn't help.

      Below is the actual method to which the test case is written. When my compiler executes the line "req1.execute()" it throws null for the req1.getDataSource().

      Actual:
      public DSResponse update(DSRequest dsRequest, HttpServletRequest request, RPCManager rpcManager) throws Exception {

      // Get the record to update
      SenderRecord sender = new SenderRecord();
      DataTools.setProperties(dsRequest.getValues(), sender);

      DSRequest req1 = new DSRequest("customtable", "fetch", rpcManager);
      req1.setCriteria("type", "1");

      DSResponse Response = req1.execute();
      }

      Test :
      @Test
      public void updateTest() throws Exception {

      MockHttpSession session = new MockHttpSession();
      session.setAttribute("session", user);
      MockHttpServletRequest request = new MockHttpServletRequest();
      request.setHttpSession(session);
      RPCManager rpcManager = Mockito.mock(RPCManager.class);

      // Mocking DSRequest
      DSRequest dsrequest = Mockito.mock(DSRequest.class);

      testClass.update(dsrequest, request, rpcManager);
      }

      My stack trace :

      java.io.IOException: Configured for containerIO, but servletContext not available! You need to install the Init servlet
      at com.isomorphic.io.ISCFile.newInstance(ISCFile.java:151)
      at com.isomorphic.io.ISCFile.newInstance(ISCFile.java:180)
      at com.isomorphic.store.DataStructCache.XMLOrJSFile(DataStructCache.java:357)
      at com.isomorphic.store.DataStructCache._getInstanceFile(DataStructCache.java:300)
      at com.isomorphic.store.DataStructCache.getInstanceFile(DataStructCache.java:233)
      at com.isomorphic.datasource.DataSource.loadDS(DataSource.java:482)
      at com.isomorphic.datasource.DataSource.forName(DataSource.java:460)
      at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:134)
      at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:153)
      at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:1179)
      at com.isomorphic.pool.ISCKeyedObjectPool.borrowObject(ISCKeyedObjectPool.java:106)
      at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:92)
      at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:171)
      at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:121)
      at com.isomorphic.datasource.DSRequest.getDataSource(DSRequest.java:2352)
      at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:3291)
      at com.bp2s.xproducts.cts.server.datasource.dmi.DMISender.updateClient(DMISender.java:63)
      at com.bp2s.xproducts.cts.server.datasource.dmi.DMISenderTest.updateClientTest(DMISenderTest.java:70)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:79)
      at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:85)
      at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
      at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
      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)


      Console log :
      === SmartClient Init: log4j.isc.config.xml not found in CLASSPATH. Assuming log4j configuration for com.isomorphic is located in some other log4j configuration file.
      log4j:WARN No appenders could be found for logger (org.eclipse.jetty.util.log).
      log4j:WARN Please initialize the log4j system properly.
      log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
      Problem loading builtinTypes.xml
      Exception when loading from __USE_CONTAINER__/isomorphic/system/schema/builtinTypes.xml:
      java.io.IOException: Configured for containerIO, but servletContext not available! You need to install the Init servlet
      at com.isomorphic.io.ISCFile.newInstance(ISCFile.java:151)
      at com.isomorphic.io.ISCFile.newInstance(ISCFile.java:180)
      at com.isomorphic.xml.XML.getXMLDocument(XML.java:434)
      at com.isomorphic.xml.XML.toDSRecords(XML.java:442)
      at com.isomorphic.xml.XML.toDSRecords(XML.java:446)
      at com.isomorphic.xml.XML.toDSRecords(XML.java:451)
      at com.isomorphic.datasource.DataSource.<clinit>(DataSource.java:1110)
      at com.isomorphic.datasource.DSRequest.<clinit>(DSRequest.java:3437)
      at sun.reflect.GeneratedSerializationConstructorAccessor2.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
      at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:48)
      at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73)
      at org.mockito.internal.creation.instance.ObjenesisInstantiator.newInstance(ObjenesisInstantiator.java:19)
      at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:47)
      at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25)
      at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
      at org.mockito.internal.MockitoCore.mock(MockitoCore.java:69)
      at org.mockito.Mockito.mock(Mockito.java:1895)
      at org.mockito.Mockito.mock(Mockito.java:1804)
      at com.test.server.datasource.dmi.TestClass.updateTest(TestClassTest.java:65)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:79)
      at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:85)
      at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
      at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
      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)


      Could you please help on this.


      Thanks,
      Manjula

      Comment


        #4
        The Standalone DataSource Overview, previously linked, covers how to handle this - since, in JUnit, there are no servlets, you need to tell us the directory paths to use in server.properties.

        You made a mention of server.properties without saying what you did, which is useless in terms of helping you. For now, all we can tell you is: read those docs again, and follow the instructions more carefully.

        Comment

        Working...
        X