Tuesday, March 29, 2011

Gwt JSNI gotchas

1. Expression evaluation
http://code.google.com/p/google-web-toolkit/issues/detail?id=2912


Mock Mock Mock

Mocking is serious business for evolved coding monkeys these days. There are few good frameworks which help in mocking like easymock, jMockit, mockrunner etc

PowerMock
SmartGWT is a GWT widget library which has design issues as its classes doesnt mostly implement interfaces. But the problem is we have to use it as it has nice widgets.

Question: how do we unit test these classes which have native code and hard to mock?
 Powermock came to rescue us. It can re-engineer the class and supress static block and method.
Eg:
@RunWith(PowerMockRunner.class)
@PrepareForTest( {Appender.class})
@SuppressStaticInitializationFor({"com.google.gwt.user.client.ui.UIObject","com.smartgwt.client.widgets.BaseWidget"})
@MockPolicy({Slf4jMockPolicy.class, Log4jMockPolicy.class})
public class MyStaticTest{
}
The above supresses static blocks which have wierd native calls and helps us continue our junit as usual. But its a bit slow (worth it i believe).
More on usage here



jMock vs. EasyMock

Comparison of jmock & easy mock

Both have similar features. jMock has a DSL (domain specific language) while easy mock has record-replay style.

Apparently jMock seems to be better in terms of readability and usability. Would prefer the more intuitive framework like jMock than Easy mock.

Will post more when I actually try using jMock. Till than easy mock.

Useful links
1. EasyMock http://www.easymock.org
2. JMock  http://www.jmock.org
3. Mackinnon, T., et al. 2000. Endo-Testing: Unit Testing with Mock Objects. In Proceedings of XP 2000. http://www.mockobjects.com/files/endotesting.pdf
4. Freeman, S., et al. 2004. Mock Roles, not Objects. In Proceedings of OOPLSA 2004. http://www.mockobjects.com/files/mockrolesnotobjects.pdf
5. Walls, C. 2008. Spring in Action, 2nd Edition. Manning Publications Co., Greenwich, CT. §B.2.1.
6. Stewart, S. 2004. Approaches to Mocking. http://www.onjava.com/lpt/a/4526
7. Fowler, M. 2007. Mocks Aren't Stubs. http://martinfowler.com/articles/mocksArentStubs.html




Sunday, March 13, 2011

Batch script to load developer environment

Wrote a simple windows bat script to start my project work environment.
This would save me
4 + 2 + 3 + 2+2 = 14 mouse clicks
4+2 + 5 = 11 keystroke
3 + 3 = 6 copy paste
Saving me from making 14+ 3 + 6= 23 decisions.. lol
The effort involved to build this script is 1 hour though. On a long run saves my time and energy for making these 23 decisions.. Worth it i believe.
What this does is : start mysql server , tomcat, eclipse, mysql query browser and open command prompt into your current project
------------------
net start mysql5.1
f:
cd F:\apache-tomcat-6.0.29\bin\
start F:\apache-tomcat-6.0.29\bin\startup-debug.bat
start D:\tools\IDE\eclipse-jee-helios-SR2-win32\eclipse\eclipse_jee_helios.exe
"C:\Program Files\MySQL\MySQL Tools for 5.0\MySQLQueryBrowser.exe" -ulportal -pdontshow -hlocalhost
cd F:\project
-----------------

Wednesday, March 9, 2011

Smart GWT Gotchas


1. ListGrid - Change color of a row or individual cell
2. Dynamic Form
           StaticTextItem
3. JSON parsing :
                JavaScriptObject jsObject = JSON.decode(responseData);
                JSONArray accountNames = XMLTools.selectObjects(jsObject, "accounts");
                final JSONValue jsonAccount = accountObjs.get(0);
                final String accountNumber = jsonAccount.isObject().get("AccountNumber").isString().stringValue();
4. Mock Presenter gotcha :
   Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable in client 
     Fix : GWTMockUtilities.disarm();   More here

5. Speed up gwt compile time : here

6. Error processing request: The response could not be deserialized
             Annonying issue in dev mode from eclipse. See that the default compile target is set to ../web-inf/classes in eclipse. Restart eclipse. clean up target classes folder. Got it working...after a redeploy of war again...strange..cant point to one specific thing (as i did clear browser cache/eclipse classes output/restart eclipse)
Apparently workaround seems to be try redeploying app whenever this issue occurs..

7. Wrap text in list grid:
listGrid
.setFixedRecordHeights(false);
listGrid
.setWrapCells(true);

8. Listgrid pagination related issues(issues with page scroll based pagination):
Serendipity might have already solved the pagination and csv export : http://code.google.com/p/crmdipity/downloads/list
think best if we have traditional pagination approach. and have as PaginatedListGrid which will solve all list grid related issues:
  - sorting
  - export to excel
  - print
  - slow page load
  - less browser load (as only one page of data is available at any point of time)