Announcement

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

    junit testing of server components

    Hi! 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). I'm also calling dsRequest.setValue 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. How do I setup DSRequest obejct in the junit method so that dsRequest.getDataSource() will not throw an Exception?

    #2
    Can you show the Exception message and stack trace? It may also be necessary to see some sample code.

    Comment


      #3
      I'm also trying to create a JUnit test to test a data source on the server side. I've changed my server.properties webroot setting to point to the file system path where the smartgwtpower.jar and other Iso jars are. What additional setup is needed?

      Here is my test case code.
      Code:
      package com.islandpacific.gui.server.test;
      
      import java.util.HashMap;
      import java.util.Map;
      
      import junit.framework.TestCase;
      
      import com.isomorphic.base.ISCInit;
      import com.isomorphic.datasource.DSRequest;
      import com.isomorphic.datasource.DSResponse;
      
      
      public class IpPkdefTest extends TestCase {
      
      	public void test1() throws Exception {
      		ISCInit.go();
      		DSRequest req = new DSRequest("IPPKDEF", "fetch");
      		req.setOperationId("commonSKU");
      		req.addToTemplateContext("csLib", "IPTSFILZ");
      		Map criteria = new HashMap();
      		criteria.put("PKCLS", 280);
      		criteria.put("PKVEN", 280);
      		criteria.put("PKSTY", 124);
      		criteria.put("PKCLR", 100);
      		criteria.put("PKSIZ", 1000);
      		req.setCriteria(criteria);
      		DSResponse resp = req.execute();
      		System.out.println(resp.getRecords());
      	}
      }
      This is the stack trace I get when I run it.
      Code:
      java.io.IOException: Configured for containerIO, but servletContext not available!  You need to install the Init servlet
      	at com.isomorphic.io.ISCFile.<init>(ISCFile.java:139)
      	at com.isomorphic.store.DataStructCache.XMLOrJSFile(DataStructCache.java:274)
      	at com.isomorphic.store.DataStructCache._getInstanceFile(DataStructCache.java:237)
      	at com.isomorphic.store.DataStructCache.getInstanceFile(DataStructCache.java:190)
      	at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:63)
      	at com.isomorphic.datasource.DataSource.forName(DataSource.java:156)
      	at com.isomorphic.datasource.DataSource.forName(DataSource.java:148)
      	at com.isomorphic.datasource.DataSource.forName(DataSource.java:143)
      	at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:95)
      	at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:102)
      	at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:82)
      	at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:62)
      	at com.isomorphic.datasource.DSRequest.getDataSource(DSRequest.java:1281)
      	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1362)
      	at com.islandpacific.gui.server.test.IpPkdefTest.test1(IpPkdefTest.java:27)
      	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 junit.framework.TestCase.runTest(TestCase.java:164)
      	at junit.framework.TestCase.runBare(TestCase.java:130)
      	at junit.framework.TestResult$1.protect(TestResult.java:106)
      	at junit.framework.TestResult.runProtected(TestResult.java:124)
      	at junit.framework.TestResult.run(TestResult.java:109)
      	at junit.framework.TestCase.run(TestCase.java:120)
      	at junit.framework.TestSuite.runTest(TestSuite.java:230)
      	at junit.framework.TestSuite.run(TestSuite.java:225)
      	at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
      	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)
      This is what shows up in the log.
      Code:
      ISC: Configuring log4j from: file:/Users/jfisher/helios/workspace/IPGui/war/WEB-INF/classes/log4j.isc.config.xml
      === 2011-02-02 10:48:08,179 [main] INFO  ISCInit - Isomorphic SmartClient Framework - Initializing
      === 2011-02-02 10:48:08,185 [main] INFO  ConfigLoader - Attempting to load framework.properties from CLASSPATH
      === 2011-02-02 10:48:08,292 [main] INFO  ConfigLoader - Successfully loaded framework.properties from CLASSPATH at location: jar:file:/Users/jfisher/helios/workspace/IPGui/war/WEB-INF/lib/isomorphic_core_rpc.jar!/framework.properties
      === 2011-02-02 10:48:08,292 [main] INFO  ConfigLoader - Attempting to load project.properties from CLASSPATH
      === 2011-02-02 10:48:08,298 [main] INFO  ConfigLoader - Unable to locate project.properties in CLASSPATH
      === 2011-02-02 10:48:08,306 [main] INFO  ConfigLoader - Successfully loaded isc_interfaces.properties from CLASSPATH at location: jar:file:/Users/jfisher/helios/workspace/IPGui/war/WEB-INF/lib/isomorphic_core_rpc.jar!/isc_interfaces.properties
      === 2011-02-02 10:48:08,307 [main] INFO  ConfigLoader - Attempting to load server.properties from CLASSPATH
      === 2011-02-02 10:48:08,317 [main] INFO  ConfigLoader - Successfully loaded server.properties from CLASSPATH at location: file:/Users/jfisher/helios/workspace/IPGui/war/WEB-INF/classes/server.properties
      === 2011-02-02 10:48:08,325 [main] INFO  Logger - Logging system started.
      === 2011-02-02 10:48:08,326 [main] INFO  ISCInit - Isomorphic SmartClient Framework (SC_SNAPSHOT-2011-01-29/PowerEdition Deployment 2011-01-29) - Initialization Complete
      === 2011-02-02 10:48:08,327 [main] INFO  ISCInit - No ServletContext available yet - using container IO for now
      === 2011-02-02 10:48:08,343 [main] INFO  ISCInit - No ServletContext available yet - using container IO for now
      === 2011-02-02 10:48:08,409 [main] INFO  PoolManager - SmartClient pooling disabled for 'IPPKDEF' objects
      === 2011-02-02 10:48:08,448 [main] INFO  RepoRegistry - RepoRegistry unavailable: can't find RepoRegistry.ds.xml - using datasources.repo.default

      Comment


        #4
        Sorry. I probably should have put this on the SmartGWT forum.

        Comment


          #5
          Are you running Init.go()? That's the equivalent of using the Init servlet but for a command-line application.

          Comment


            #6
            If you mean ISCInit.go() then yes. That is the first thing I call.

            Comment


              #7
              Just tried changing to Init.go and got the same stack trace.

              Comment


                #8
                Sorry. My mistake. It's working now. Thanks.

                Comment


                  #9
                  This got me as well. There is no servlet context. Do I need to run a servlet environment (like this: http://jakarta.apache.org/cactus/wri..._testcase.html ) to run tests that use DataSources?




                  Code:
                  ISC: Configuring log4j from: file:/workspace/project/war/WEB-INF/classes/log4j.isc.config.xml
                  === 2011-08-09 08:37:15,045 [main] INFO  ISCInit - Isomorphic SmartClient Framework - Initializing
                  === 2011-08-09 08:37:15,053 [main] INFO  ConfigLoader - Attempting to load framework.properties from CLASSPATH
                  === 2011-08-09 08:37:15,160 [main] INFO  ConfigLoader - Successfully loaded framework.properties from CLASSPATH at location: jar:file:/workspace/project/war/WEB-INF/lib/isomorphic_core_rpc.jar!/framework.properties
                  === 2011-08-09 08:37:15,160 [main] INFO  ConfigLoader - Attempting to load project.properties from CLASSPATH
                  === 2011-08-09 08:37:15,161 [main] INFO  ConfigLoader - Unable to locate project.properties in CLASSPATH
                  === 2011-08-09 08:37:15,164 [main] INFO  ConfigLoader - Successfully loaded isc_interfaces.properties from CLASSPATH at location: jar:file:/workspace/project/war/WEB-INF/lib/isomorphic_core_rpc.jar!/isc_interfaces.properties
                  === 2011-08-09 08:37:15,164 [main] INFO  ConfigLoader - Attempting to load server.properties from CLASSPATH
                  === 2011-08-09 08:37:15,167 [main] INFO  ConfigLoader - Successfully loaded server.properties from CLASSPATH at location: file:/workspace/project/war/WEB-INF/classes/server.properties
                  === 2011-08-09 08:37:15,172 [main] INFO  Logger - Logging system started.
                  === 2011-08-09 08:37:15,172 [main] INFO  ISCInit - Isomorphic SmartClient Framework (SC_SNAPSHOT-2011-08-02/Pro Deployment 2011-08-02) - Initialization Complete
                  === 2011-08-09 08:37:15,173 [main] INFO  ISCInit - No ServletContext available yet - using container IO for now
                  === 2011-08-09 08:37:15,448 [main] INFO  ISCInit - No ServletContext available yet - using container IO for now
                  Problem loading builtinTypes.xml
                  Exception when loading from __USE_CONTAINER__/KISS/sc/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.<init>(ISCFile.java:139)
                  	at com.isomorphic.store.ProcessedFileCache.getObjectFromFile(ProcessedFileCache.java:138)

                  Comment


                    #10
                    There are now docs here on how to run standalone.

                    Comment


                      #11
                      Great. Thank you.

                      Comment


                        #12
                        It turns out my problem was having a space in my project's path name.

                        Is there any easy way to have two server.properties files? (one that specifies webRoot as the local machine path and one that specifies __AUTODETECT__) I guess I can do this by creating a new project and linking the source files from the old project.

                        Comment


                          #13
                          Hi,

                          using 3.0

                          I tried both,

                          Init.go() + new DSReqest("datasource.ds.xml", "add");

                          and

                          DataSourceManager.get("datasource.ds.xml")


                          and got


                          === 2011-11-16 09:47:56,271 [main] INFO ISCInit - No ServletContext available yet - using container IO for now
                          Problem loading builtinTypes.xml
                          Exception when loading from __USE_CONTAINER__/portal/sc/system/schema/builtinTypes.xml:
                          java.io.IOException: Configured for containerIO, but servletContext not available! You need to install the Init servlet


                          You can help me out, how to solve this?

                          The Test should read the same server.properties, which is used for application

                          Comment


                            #14
                            Read the rest of the overview on standalone apps, specifically about setting webroot.

                            Comment


                              #15
                              setting webroot helps solving the error,
                              but datasource is still null.

                              server.properties is in classpath.

                              Is there a way to debug or get more informations about the environment?

                              Comment

                              Working...
                              X