Announcement

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

    Is there a simple way to override server.properties for automated tests?

    Thread http://forums.smartclient.com/showthread.php?p=30977 points out that webRoot needs to point to the absolute path (of the war) when running unit tests. I'd like to do this for JUnit tests but leave the default server.properties alone for development. So far I've tried this...

    Properties p = new Properties();
    InputStream is = ClassLoader.getSystemResourceAsStream("server.properties");
    p.load(is);
    Properties conf = new Properties(p);
    conf.setProperty("webRoot", "/Users/me/.../MyApp_SmartGWT/");
    conf.setProperty("project.datasources", "$webRoot/war/ds");
    Config c = Config.initGlobalConfig();
    c.putAll(conf);
    ISCInit.go();

    This loads the properties OK (e.g., no error about not finding ds files etc.) but the following exception still happens. My test runs OK with no exceptions is I just change webRoot in server.properties, but, I want to keep the test config separate from the development config.

    java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
    at com.isomorphic.datasource.BasicDataSource.buildFieldData(BasicDataSource.java:426)
    at com.isomorphic.datasource.BasicDataSource.init(BasicDataSource.java:218)
    at com.isomorphic.sql.SQLDataSource.init(SQLDataSource.java:151)
    at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:165)
    at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:337)
    at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:110)
    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:1267)
    at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1348)
    at com.me.server.UserDMI.addAdressesToUsers(UserDMI.java:19)
    at com.me.server.UserDMITest.addAdressesToUsers(UserDMITest.java:44)
    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.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    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.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)


    thanks!
    ,boz

    #2
    Reverse the order of calls. It's not valid to do *anything* with any SC libraries until you've called go().

    Comment


      #3
      I reversed the call order to ...

      ISCInit.go();
      Properties p = new Properties();
      InputStream is = ClassLoader.getSystemResourceAsStream("server.properties");
      p.load(is);
      Properties conf = new Properties(p);
      conf.setProperty("webRoot", "/Users/me/.../MyApp_SmartGWT/");
      conf.setProperty("project.datasources", "$webRoot/war/ds");
      Config c = Config.initGlobalConfig();
      c.putAll(conf);

      and still get the same exception. I'm confused why these settings would affect BasicDataSource.buildFieldData(...)

      The properties are being loaded because changing them does affect the flow. For example, removing the "webRoot" override property results in an error about not finding ds files (as expected).

      Thanks for the help!
      ,boz

      Comment


        #4
        The actual test code and class under test are listed in this thread...
        http://forums.smartclient.com/showthread.php?t=18692

        Comment


          #5
          I was missing a "gwtModuleName" property override. The path would vary based on your project setup. Mine's based on the ds-dmi sample app which has a 'war' folder with a sub-folder named for my application ('myapp' in this case) so the needed setting is conf.setProperty("gwtModuleName", "war/myapp");

          So it all becomes...

          ISCInit.go();
          Properties p = new Properties();
          InputStream is = ClassLoader.getSystemResourceAsStream("server.properties");
          p.load(is);
          Properties conf = new Properties(p);
          conf.setProperty("webRoot", "/Users/me/.../MyApp_SmartGWT/");
          conf.setProperty("project.datasources", "$webRoot/war/ds");
          conf.setProperty("gwtModuleName", "war/myapp");
          Config c = Config.initGlobalConfig();
          c.putAll(conf);

          Comment

          Working...
          X