Announcement

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

    Mocking isomorphic DataSource for Junit Testing

    Hi,

    I have a method written in service class which takes DSRequest as a input parmeter. In that method I am using the following code snippet to populate my DTO.
    MyClient client = new MyClient();
    dsRequest.getDataSource().setProperties(dsRequest.getValues(), client);
    where client is a DTO object.

    Now, I am not able to write a Junit test case for this method, as I dont know how to populate DataSource in DSRequest.

    In my Junit test case I am creating DSRequest object as
    DSRequest dsRequest = new DSRequest();

    Please tell me how to populate DataSource object in DSRequest or else is there any better approach to Unit test my service class. I am using JUnit 4.0
    Last edited by pgupta84; 22 Sep 2009, 06:43.

    #2
    You don't actually need to populate that attribute. Just use the constructor that takes a dataSourceName as a String, and call execute(). The DSRequest will find the appropriate DataSource via the same method used when running within the servlet engine.

    Comment


      #3
      Getting NPE

      Hi Isomorphic,
      I tried this but got following exception. I think there is some issue while creating DataStructCache. Please help.

      java.lang.NullPointerException
      at com.isomorphic.io.ISCFile.<init>(ISCFile.java:145)
      at com.isomorphic.store.DataStructCache.XMLOrJSFile(DataStructCache.java:267)
      at com.isomorphic.store.DataStructCache._getInstanceFile(DataStructCache.java:231)
      at com.isomorphic.store.DataStructCache.getInstanceFile(DataStructCache.java:184)
      at com.isomorphic.datasource.DataSource.forName(DataSource.java:150)
      at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:89)
      at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:96)
      at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:76)
      at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:56)
      at com.isomorphic.datasource.DSRequest.getDataSource(DSRequest.java:1052)
      at com.isomorphic.application.AppBase.execute(AppBase.java:427)
      at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1175)
      at com.ias.er.service.dmi.EstimateDMIImplTest.updateEstimate(EstimateDMIImplTest.java:39)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      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.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
      at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
      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)

      Comment


        #4
        Call com.isomorphic.base.ISCInit.go() before calling any other SmartClient code.

        Comment


          #5
          Hi Isomorphic,

          I am still getting the same exception. My Test case code is

          public void updateEstimate(){
          ISCInit.go();
          DSRequest dsRequest = new DSReques("manageEstimateDS","update");
          dsRequest.execute();
          }

          I am having a manageEstimateDS.ds.xml as my datasource file. This file is located under /shared/ds folder. This manageEstimateDS file is referring to other ds files kept under the same folder

          Please help.

          Comment


            #6
            Which exact version of SmartClient are you using?

            Comment


              #7
              I am using Smart Client LGPL Server version SmartClient 7.0RC2

              Comment


                #8
                The LGPL version of SmartClient does not include the server - presumably you're using the Eval version. Do you see the following message in the log immediately before the NullPointerException: "Configured for containerIO, but servletContext not available"?

                Comment


                  #9
                  If so, you need to modify the "webroot" setting in server.properties to point to an actual filesystem path where you have placed the resources of the smartclientSDK, since when running standalone, the servlet container is not there to allow us to load files.

                  Comment


                    #10
                    The sub-tag is <operationBinding>, not <binding>

                    Comment


                      #11
                      This is now calling your DMI code and you are calling dsRequest.execute(). What kind of DataSource is this? If it's not one of the builtin persistence engines (serverType="sql" or "hibernate") then it won't know how to perform an update, which is what it's telling you.

                      Comment


                        #12
                        Able to solve it

                        Hi Isomorphic,

                        At last I was able to solve this problem and run my Junit Test case around my service class.

                        Solution was to create the DSRequest as suggested by you and instead of called dsRequest.execute(), directly call the method defined in the service class.

                        Once again thanks a lot for your support and prompt reply.

                        Comment


                          #13
                          Just in case anyone else is reading: that's not the correct solution. See Isomorphic's previous response regarding what execute() should be expected to do.

                          Comment

                          Working...
                          X