From af6e77091e0b943464acd476870ed9836ce8f38f Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 12 Nov 2013 17:27:44 +0000 Subject: [PATCH] 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 --- pom.xml | 8 +- src/main/webapp/WEB-INF/web.xml | 13 +-- .../client/GwtTestWidgetCommonEvent.java | 98 +++++++++---------- .../{test => }/WidgetCommonEventJUnit.gwt.xml | 5 +- 4 files changed, 55 insertions(+), 69 deletions(-) rename src/test/resources/org/gcube/portlets/user/td/widgetcommonevent/{test => }/WidgetCommonEventJUnit.gwt.xml (85%) diff --git a/pom.xml b/pom.xml index 055fde3..8070bee 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ 3.0.1 - + @@ -141,7 +141,9 @@ maven-surefire-plugin 2.16 - true + + **/GwtTest*.java + @@ -161,6 +163,7 @@ + test resources @@ -169,6 +172,7 @@ WidgetCommonEvent.html ${webappDirectory} org.gcube.portlets.user.td.widgetcommonevent.WidgetCommonEvent + **/GwtTest*.java diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index c22c80d..1292c3f 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -6,10 +6,7 @@ - - TDGWTService - org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl - + jUnitHostImpl @@ -17,19 +14,15 @@ - - TDGWTService - tdgwtservice/TDGWTService - jUnitHostImpl - TDInformationManagerWidgets/junithost/* + WidgetCommonEvent/junithost/* - Information.html + WidgetCommonEvent.html diff --git a/src/test/java/org/gcube/portlets/user/td/widgetcommonevent/client/GwtTestWidgetCommonEvent.java b/src/test/java/org/gcube/portlets/user/td/widgetcommonevent/client/GwtTestWidgetCommonEvent.java index 19a41ef..37f23d6 100644 --- a/src/test/java/org/gcube/portlets/user/td/widgetcommonevent/client/GwtTestWidgetCommonEvent.java +++ b/src/test/java/org/gcube/portlets/user/td/widgetcommonevent/client/GwtTestWidgetCommonEvent.java @@ -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 integration tests must extend GWTTestCase. - * Using "GwtTest*" 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" + * g.panichi@isti.cnr.it + * */ 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() { - - - @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()); + } + } } diff --git a/src/test/resources/org/gcube/portlets/user/td/widgetcommonevent/test/WidgetCommonEventJUnit.gwt.xml b/src/test/resources/org/gcube/portlets/user/td/widgetcommonevent/WidgetCommonEventJUnit.gwt.xml similarity index 85% rename from src/test/resources/org/gcube/portlets/user/td/widgetcommonevent/test/WidgetCommonEventJUnit.gwt.xml rename to src/test/resources/org/gcube/portlets/user/td/widgetcommonevent/WidgetCommonEventJUnit.gwt.xml index f123262..349d200 100644 --- a/src/test/resources/org/gcube/portlets/user/td/widgetcommonevent/test/WidgetCommonEventJUnit.gwt.xml +++ b/src/test/resources/org/gcube/portlets/user/td/widgetcommonevent/WidgetCommonEventJUnit.gwt.xml @@ -1,8 +1,8 @@ - + + - @@ -10,5 +10,4 @@ -