java - JavaScript Exeption when using DataTable.create() in JUnit with GWTTestCase -
for school project, have test 1 of classes. after writing , executing test got next error. here failure trace:
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, wich later can filled columns , rows.
i want test if info beingness set correctly. in class, testing initial info beingness reformatted can used gwt graphs. take big datatable , convert arraylist of smaller datatables. far know, test didn't create far testing specific method, got stuck in @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 for(int = 0; < data.getnumberofcolumns()-1; i++) { for(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(); for(int i=1; i<4; i++) { for(int j=0; j<5; j++) { double number = random.nextdouble() % 1000.0; mydata.setcell(j, i, number, double.tostring(number), null); } } info = mydata; } @override public string getmodulename() { homecoming "com.gwt.agraralpha_v1"; } }
unfortunaly wasn't able find out how prepare 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 next way:
class test extends gwttestcase{ @test public void testsomething{ runnable onloadcallback = new runnable() { public void run() { ... } }; visualizationutils.loadvisualizationapi(onloadcallback, table.package); } }
java javascript gwt junit datatable
No comments:
Post a Comment