Added Test Example

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widget-common-event@85383 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2013-11-12 17:27:44 +00:00
parent 9eba1033bc
commit af6e77091e
4 changed files with 55 additions and 69 deletions

View File

@ -104,7 +104,7 @@
<version>3.0.1</version>
</dependency>
<!-- LOGGING -->
<dependency>
@ -141,7 +141,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skipTests>true</skipTests>
<excludes>
<exclude>**/GwtTest*.java</exclude>
</excludes>
</configuration>
<!-- TODO check if needed -->
<dependencies>
@ -161,6 +163,7 @@
<executions>
<execution>
<goals>
<goal>test</goal>
<goal>resources</goal>
</goals>
</execution>
@ -169,6 +172,7 @@
<runTarget>WidgetCommonEvent.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<module>org.gcube.portlets.user.td.widgetcommonevent.WidgetCommonEvent</module>
<includes>**/GwtTest*.java</includes>
</configuration>
</plugin>

View File

@ -6,10 +6,7 @@
<web-app>
<!-- Servlets -->
<servlet>
<servlet-name>TDGWTService</servlet-name>
<servlet-class>org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>jUnitHostImpl</servlet-name>
@ -17,19 +14,15 @@
</servlet>
<!-- Servlets Mapping -->
<servlet-mapping>
<servlet-name>TDGWTService</servlet-name>
<url-pattern>tdgwtservice/TDGWTService</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jUnitHostImpl</servlet-name>
<url-pattern>TDInformationManagerWidgets/junithost/*</url-pattern>
<url-pattern>WidgetCommonEvent/junithost/*</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Information.html</welcome-file>
<welcome-file>WidgetCommonEvent.html</welcome-file>
</welcome-file-list>
</web-app>

View File

@ -1,20 +1,18 @@
package org.gcube.portlets.user.td.widgetcommonevent.client;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.ImportTableEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ImportTableType;
import org.junit.Test;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.web.bindery.event.shared.SimpleEventBus;
/**
* GWT JUnit <b>integration</b> tests must extend GWTTestCase.
* Using <code>"GwtTest*"</code> naming pattern exclude them from running with
* surefire during the test phase.
* Test Event
*
* If you run the tests using the Maven command line, you will have to
* navigate with your browser to a specific url given by Maven.
* See http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html
* for details.
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GwtTestWidgetCommonEvent extends GWTTestCase {
@ -23,62 +21,54 @@ public class GwtTestWidgetCommonEvent extends GWTTestCase {
*/
@Override
public String getModuleName() {
return "org.gcube.portlets.user.td.widgetcommonevent.test.WidgetCommonEventJUnit";
return "org.gcube.portlets.user.td.widgetcommonevent.WidgetCommonEventJUnit";
}
/**
* This test will send a request to the server
* Test Events fire
*/
@Test
public void testEvents() {
// Create the service that we will test.
//TDGWTServiceAsync tdGXTService = GWT.create(TDGWTService.class);
//ServiceDefTarget target = (ServiceDefTarget) tdGXTService;
//System.out.println(GWT.getModuleBaseURL() + "/TDGWTService");
//target.setServiceEntryPoint(GWT.getModuleBaseURL() + "/TDGWTService");
// Since RPC calls are asynchronous, we will need to wait for a response
// after this test method returns. This line tells the test runner to wait
// up to 10 seconds before timing out.
//delayTestFinish(2000);
//finishTest();
// Send a request to the server.
/*try {
TDGXTServiceAsync.INSTANCE.getTabResource(
new AsyncCallback<TabResource>() {
@Override
public void onSuccess(TabResource result) {
assertTrue(result!=null);
System.out.println(result);
// Now that we have received a response, we need to tell the test runner
// that the test is complete. You must call finishTest() after an
// asynchronous test finishes successfully, or the test will time out.
finishTest();
}
SimpleEventBus eventBus=new SimpleEventBus();
eventBus.addHandler(ImportTableEvent.TYPE,
new ImportTableEvent.ImportTableHandler() {
@Override
public void onFailure(Throwable caught) {
// The request resulted in an unexpected error.
fail("Request failure: " + caught.getMessage());
@Override
public void onImportTable(ImportTableEvent event) {
doImportTable(event.getImportType());
}
});
eventBus.fireEvent(new ImportTableEvent(ImportTableType.SDMX));
eventBus.fireEvent(new ImportTableEvent(ImportTableType.CSV));
eventBus.fireEvent(new ImportTableEvent(ImportTableType.JSON));
}
});
} catch (TDGXTServiceException e) {
System.out.println("Error in comunications: "+e.getLocalizedMessage());
e.printStackTrace();
}
*/
}
private void doImportTable(ImportTableType importType) {
System.out.println("doImportTable importType: " + importType);
try {
switch (importType) {
case SDMX:
System.out.println("Start Import SDMX");
break;
case CSV:
System.out.println("Start Import CSV");
break;
case JSON:
System.out.println("Start Import JSON");
break;
default:
break;
}
} catch (Exception e) {
System.out.println("doImportTable Error : " + e.getLocalizedMessage()
+ " \n " + e.getMessage());
}
}
}

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to="WidgetCommonEventJUnit">
<module rename-to="GwtTestWidgetCommonEventJUnit">
<!-- Inherit our applications main module. -->
<!-- <inherits name='org.gcube.portlets.user.td.gwtservice.TDGWTService' /> -->
<!-- Specify the path to any remote services. -->
<!-- <servlet path="/TDGWTService"
class="org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl" /> -->
@ -10,5 +10,4 @@
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='test' />
</module>