Hi Friends, To retrieve difference between two dates with finer details which would display their difference as 2 years 7 weeks 3 days 2 hours 5 mins ago is given below. /** * Returns differnce b/w new Date and old date as Map holding difference in years, weeks, days, hrs, mins & secs */ public static Map...
Hi Friends, I always used to spend lot of time writing integration tests as running even a single test involves loading the complete application, which includes loading complete database every time. Then I realized that data which I use for testing is always the same, why can't we restore the database once created, before we run the...
Hi Friends, I needed to take the backup and restore the selected table(s) of mysql database. And I found Gaurav Chauhan's blog on taking dump of the database and to restore the database. So I tried with the same commands but with table names passed as parameters and that worked. mysqldump -u root -p my_database Table1 Table2 >...
Hi! We had a myForm.html file (accessible only from the third party) where in we needed to update the form containing input/select/check boxes with the values we had in the request params and then render it. So we used xmlslurper for the same. Without much effort, it just worked great. Following is the code we wrote: import...
Recently I encountered a StaleObjectStateException which said "Row was updated or deleted by another transaction." We were just updating multiple objects of the same domain inside a loop. So we used executeUpdate statement instead of myClass.save() method to update the records, which worked. ReserveAccount.executeUpdate("update...
In my project we needed to generate certain pdf reports. Then while exploring the options available, I encountered a PDF plugin, which renders gsp page and returns the PDF report. It looked good for the simple reports but may not be a good idea if the report are complex. Then with the help of one of my collegue, we decided to rather...
Hi Friends, Recently I needed to access my grails application's path while writing an integration test. I tried to do it with servlet context, Application Holder and few more options. But none worked. Then I encountered the simplest way as given below, which worked. System.properties['base.dir'] Cheers! ~~Amit Jain~~ ...
Hello Friends, I was using Jsecurity plugin in my project. There was an action in a controller which needed logged in user information and I was finding it difficult to write an integration test for the same. Then Brent Fisher shared the following code which worked nicely for both services and controllers: import...
Just thought I would share with you few tips or key points we should remember while writing integration test cases: 1. Flush and clear the session object for every single test case for example class FooTests extends GroovyTestCase { def sessionFactory void setUp() { sessionFactory.currentSession.flush() ...
Hi Friends, I was working on the financial application, where the user doesn't want to select merchant provider while feeding in credit card details and yet we needed to know the merchant provider. Following is the code that helped: function getMerchantProvider(cardNo){ //cardNo is the credit card number ...
Let us have a look at the simple javascript code, that can be used to add hotkeys to our web application. I tried using jquery hotkeys plugin and two more plugins, but they didn't work for me. So I ended up handling the keydown event of my own. var isAlt = false; document.onkeyup = function(e) { if (e.which == 18) //18 is...
Hi Friends, Recently I came across a problem, where the url of the links were to be generated dynamically based on the controller and action to be executed and should end with ".html". Reverse url mappings came to my rescue, which can be implemented using <g:link> GSP tag. Then I tried this, In UrlMappings.groovy file : ...