java - JavaScriptException when using DataTable.create() in JUnit with GWTTestCase -
for school project, have test 1 of classes. after writing , executing test, got following error message , stacktrace:
com.google.gwt.core.client.javascriptexception: (null) @com.google.gwt.visualization.client.datatable::create()([]): null @ com.google.gwt.dev.shell.browserchannelserver.invokejavascript(browserchannelserver.java:249) @ com.google.gwt.dev.shell.modulespaceoophm.doinvoke(modulespaceoophm.java:136) @ com.google.gwt.dev.shell.modulespace.invokenative(modulespace.java:576) @ com.google.gwt.dev.shell.modulespace.invokenativeobject(modulespace.java:284) @ com.google.gwt.dev.shell.javascripthost.invokenativeobject(javascripthost.java:91) @ com.google.gwt.visualization.client.datatable$.create(datatable.java) @ com.gwt.client.vizualizationmanagertest.gwtsetup(vizualizationmanagertest.java:150) ...
from read, problem method: datatable.create()
, creates default datatable
may later filled columns , rows.
i want test if data being set correctly. in class, testing verify initial data being reformatted can used gwt graphs
. take large datatable
, convert arraylist
of smaller datatables
. far know, test didn't make far testing specific method, got stuck in the: @before
method: gwtsetup()
on datatable.create()
.
here code of test:
package com.gwt.client; import static org.junit.assert.*; import java.util.random; import org.junit.before; import org.junit.test; import com.google.gwt.core.client.javascriptobject; import com.google.gwt.junit.client.gwttestcase; import com.google.gwt.user.client.ui.label; import com.google.gwt.visualization.client.abstractdatatable; import com.google.gwt.visualization.client.datatable; import com.google.gwt.visualization.client.abstractdatatable.columntype; public class vizualizationmanagertest extends gwttestcase { @test public void testpreparedata() { visualizationmanager.tabledata = (datatable) data; visualizationmanager.preparedata(); assertequals(data.getnumberofcolumns(), visualizationmanager.data.length); assertequals(data.getnumberofrows(), visualizationmanager.data[visualizationmanager.data.length-1].getnumberofrows()); //check cells equality (int = 0; < data.getnumberofcolumns()-1; i++) { (int j = 0; j < data.getnumberofrows(); j++) { string test1 = visualizationmanager.data[i].getformattedvalue(j, 0); string tested1 = data.getformattedvalue(j, i+1); assertequals(tested1, test1); } } } public abstractdatatable data; @before public void gwtsetup() { datatable mydata = datatable.create(); mydata.addcolumn(columntype.string, "country"); mydata.addcolumn(columntype.number, "2011"); mydata.addcolumn(columntype.number, "2010"); mydata.addcolumn(columntype.number, "2009"); mydata.addrows(5); mydata.setcell(0, 0, "switzerland", "switzerland", null); mydata.setcell(1, 0, "germany", "germany", null); mydata.setcell(2, 0, "austria", "austria", null); mydata.setcell(3, 0, "slovakia", "slovakia", null); mydata.setcell(4, 0, "czech republic", "czech republic", null); random random = new random(); (int i=1; i<4; i++) { (int j=0; j<5; j++) { double number = random.nextdouble() % 1000.0; mydata.setcell(j, i, number, double.tostring(number), null); } } data = mydata; } @override public string getmodulename() { return "com.gwt.agraralpha_v1"; } }
unfortunately, wasn't able find out how fix problem. can't tell if has set of whole test or can't test class datatable
, or maybe different...
i using eclipse luna java 7 update 71 on os x yosemite (10.10).
thank help!! cheers, romi
the problem gwt visualization stuff (in actual code , in junit , gwttestcase) needs reloaded on web. means, has gwt visualization needs written following way:
class test extends gwttestcase{ @test public void testsomething{ runnable onloadcallback = new runnable() { public void run() { ... } }; visualizationutils.loadvisualizationapi(onloadcallback, table.package); } }
Comments
Post a Comment