I use SmartGWT 4.1 and I want to have a Junit Test to test the DMI server side logic, and I use Spring 3.2.6.Release
I already have application running well and so the applicationContext.xml is tested, but I want to write Junit Test for continuous testing...
I meet the following error message at junit test result,
The junit test print out is as following
I have read the following link and follow already
http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/StandaloneDataSourceUsage.html
Also, I have added the servlet-api.jar in my class path...
I have added the following in my web.xml
server.properties is also config well and seem the log show that it can load the file correctly...
And follow the document to have following Junit Test
Any missing config?
I already have application running well and so the applicationContext.xml is tested, but I want to write Junit Test for continuous testing...
I meet the following error message at junit test result,
Code:
java.lang.Exception: RequestContext is missing the ServletContext. Please ensure you privide either a PageContext, a Servlet, or a ServletContext to your RequestContex.instance() call. at com.isomorphic.rpc.ServerObject.<init>(ServerObject.java:225) at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:218) at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:64) at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2557) at com.isomorphic.datasource.DataSource.fetch(DataSource.java:2890) at com.jpmorgan.am.web.server.AccountPagingServerTest.test(AccountPagingServerTest.java:38) 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:601) 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.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.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:236) 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)
Code:
Feb 19, 2014 12:18:30 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.GenericApplicationContext@6c60efe7: startup date [Wed Feb 19 12:18:30 CST 2014]; root of context hierarchy Feb 19, 2014 12:18:30 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init> INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring Feb 19, 2014 12:18:30 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5a311ade: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy ISC: Configuring log4j from: file:/C:/FAST/DeveloperDesktop/workspaces/default/my-gwtshowcase/target/classes/log4j.isc.config.xml === 2014-02-19 12:18:30,980 [main] INFO ConfigLoader - Attempting to load framework.properties from CLASSPATH === 2014-02-19 12:18:31,124 [main] INFO ConfigLoader - Successfully loaded framework.properties from CLASSPATH at location: jar:file:/C:/FAST/fastas/3.3.1/FAST_AS_331/fcHome/m2rep/com/smartgwt/isomorphic_core_rpc/4.1d/isomorphic_core_rpc-4.1d.jar!/framework.properties === 2014-02-19 12:18:31,124 [main] INFO ConfigLoader - Attempting to load project.properties from CLASSPATH === 2014-02-19 12:18:31,125 [main] INFO ConfigLoader - Unable to locate project.properties in CLASSPATH === 2014-02-19 12:18:31,132 [main] INFO ConfigLoader - Successfully loaded isc_interfaces.properties from CLASSPATH at location: jar:file:/C:/FAST/fastas/3.3.1/FAST_AS_331/fcHome/m2rep/com/smartgwt/isomorphic_core_rpc/4.1d/isomorphic_core_rpc-4.1d.jar!/isc_interfaces.properties === 2014-02-19 12:18:31,132 [main] INFO ConfigLoader - Attempting to load server.properties from CLASSPATH === 2014-02-19 12:18:31,136 [main] INFO ConfigLoader - Successfully loaded server.properties from CLASSPATH at location: file:/C:/FAST/DeveloperDesktop/workspaces/default/my-gwtshowcase/target/test-classes/server.properties === 2014-02-19 12:18:31,148 [main] INFO ISCInit - Isomorphic SmartClient/SmartGWT Framework - Initializing === 2014-02-19 12:18:31,151 [main] INFO Logger - Logging system started. === 2014-02-19 12:18:31,153 [main] INFO ISCInit - Using Configured webRoot: C:/FAST/DeveloperDesktop/workspaces/default/my-gwtshowcase/src/main/webapp === 2014-02-19 12:18:31,155 [main] INFO ISCInit - Isomorphic SmartClient/SmartGWT Framework (SNAPSHOT_v9.1d_2013-11-24/PowerEdition Deployment 2013-11-24) - Initialization Complete === 2014-02-19 12:18:31,225 [main] DEBUG XML - Parsed XML from C:\FAST\DeveloperDesktop\workspaces\default\my-gwtshowcase\src\main\webapp\showcase\sc\system\schema\builtinTypes.xml: 10ms === 2014-02-19 12:18:31,284 [main] INFO PoolManager - SmartClient pooling started for 'simpleTypes' objects === 2014-02-19 12:18:31,432 [main] DEBUG XML - Parsed XML from C:\FAST\DeveloperDesktop\workspaces\default\my-gwtshowcase\src\main\webapp\ds\NavigationMenu.ds.xml: 2ms === 2014-02-19 12:18:31,441 [main] DEBUG XML - Parsed XML from C:\FAST\DeveloperDesktop\workspaces\default\my-gwtshowcase\src\main\webapp\showcase\sc\system\schema\DataSource.ds.xml: 8ms === 2014-02-19 12:18:31,549 [main] DEBUG XML - Parsed XML from C:\FAST\DeveloperDesktop\workspaces\default\my-gwtshowcase\src\main\webapp\showcase\sc\system\schema\DataSourceField.ds.xml: 8ms === 2014-02-19 12:18:31,598 [main] DEBUG XML - Parsed XML from C:\FAST\DeveloperDesktop\workspaces\default\my-gwtshowcase\src\main\webapp\showcase\sc\system\schema\OperationBinding.ds.xml: 6ms === 2014-02-19 12:18:31,627 [main] DEBUG XML - Parsed XML from C:\FAST\DeveloperDesktop\workspaces\default\my-gwtshowcase\src\main\webapp\showcase\sc\system\schema\ServerObject.ds.xml: 3ms === 2014-02-19 12:18:31,635 [main] DEBUG DSRequest - Caching instance 10 of DS NavigationMenu from DSRequest.getDataSource() === 2014-02-19 12:18:31,641 [main] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null === 2014-02-19 12:18:31,650 [main] INFO ServerObject - DMI on Spring bean: navigationMenuDS Feb 19, 2014 12:18:31 PM org.springframework.context.support.AbstractApplicationContext doClose INFO: Closing org.springframework.context.support.GenericApplicationContext@6c60efe7: startup date [Wed Feb 19 12:18:30 CST 2014]; root of context hierarchy INFO: Closing org.springframework.context.support.GenericApplicationContext@6c60efe7: startup date [Wed Feb 19 12:18:30 CST 2014]; root of context hierarchy
http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/StandaloneDataSourceUsage.html
Also, I have added the servlet-api.jar in my class path...
I have added the following in my web.xml
Code:
<listener> <listener-class>com.isomorphic.base.InitListener</listener-class> </listener> <servlet> <servlet-name>Init</servlet-name> <servlet-class>com.isomorphic.base.Init</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
And follow the document to have following Junit Test
Code:
package test.package; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.isomorphic.datasource.DSRequest; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:**/applicationContext.xml" }) public class NavigationMenuServerTest { @BeforeClass public static void setUpBeforeClass() throws Exception { } @AfterClass public static void tearDownAfterClass() throws Exception { } @Before public void setUp() throws Exception { } @After public void tearDown() throws Exception { } @Test public void test() throws Exception { DSRequest dsReq = new DSRequest("NavigationMenu", "fetch"); Map criteria = new HashMap(); criteria.put("menuCode", "inputs"); dsReq.setCriteria(criteria); List records = dsReq.execute().getDataList(); } }