Monday, 19 March 2012

Maven is cool, but repeatably typing the long maven commands is little bit boring and waste of time. one simple solution is to create set of batch files for the repeatably used commands.

Most of us use our own set of batch files, I thought of organizing them in single place (atleast for me whenever I move to new project I don't need to create my own batch files again and again). I have created a project in github for this purpose and have included very minimum number of very frequently used commands.

you can download that and place it your classpath to save your time with maven commands.

Purposefully I have kept the number of commands as minimum, please send me your frequently used commands by raising a issue at https://github.com/nutpan/Maven-Shortcuts/issues or by adding a comment here, I would like to grow the collection in this way on need basis, so that it will have only the most wanted comments.

For Windows, copy all the batch files in to a folder and add the folder in classpath
For linux/unix, you can copy the sh files into bin folder and give executable permission using commands in makeItExec.sh

Sunday, 18 March 2012

There is an option in Liquibase to prompt for permission if the database it connects to is not in local system.
By default this option is turned off as per the Liquibase documentation, but when execute through maven Liquibase plugin seems like this default is other way round and by default it is true and even if add the property

promptOnNonLocalDatabase=false

to liquibase properties file, it is not changing its behavior, when we execute this in non head environments like unix, it does through following exception

No X11 DISPLAY variable WAS set, this program aims Performed year operation Which Requires it. at java.awt.GraphicsEnvironment.checkHeadless (GraphicsEnvironment.java: 159) at java.awt.Window.(Window.java: 407) at java.awt.Frame.(Frame.java: 402) at java.awt.Frame.(Frame.java: 367) at $ javax.swing.SwingUtilities SharedOwnerFrame.(SwingUtilities.java: 1731) at javax.swing.SwingUtilities.getSharedOwnerFrame (SwingUtilities.java: 1808) at javax.swing.JOptionPane.getRootFrame (JOptionPane.java: 1673) at javax.swing.JOptionPane.showOptionDialog (JOptionPane.java: 846) at javax.swing.JOptionPane.showConfirmDialog (JOptionPane.java: 779) at javax.swing.JOptionPane.showConfirmDialog (JOptionPane.java: 741) at liquibase.SwingUIFacade.promptForNonLocalDatabase (SwingUIFacade.java: 15)

Thursday, 1 March 2012

verification part of the test can not be executed right after the setup of test due to the latency in the mail delivery (due to milliseconds delay the test may fail).

setup and maintenance may cost its own penalties

Especially in CI and Unit testing, testing email part of the code is not so easy.

There are few good alternatives with Mock Mail testing, one of the interesting and very handy options is Mock-JavaMail. It does not require any additional setup or configuration, just drop the jar into classpath, that's all it requires.

It redirects all the mails to in-memory mail box which can be easily used in unit tests.

Lets see this with small example.

Maven Dependency configuration

Include the following dependency in maven (if not using maven, just drop the jar to classpath)

<dependency>

<groupId>org.jvnet.mock-javamail</groupId>

<artifactId>mock-javamail</artifactId>

<version>1.9</version>

<scope>test</scope>

</dependency>

Example Mail Code

I have used Apache Commons Mail api for this example for simplicity, but works fine with any implementation of Java Mail.

First Test uses the regular Javamail approach for reading the mail and the other one uses the Mock-JavaMail approach to read the mails from the Mock Email Server. I have included the whole import statements to show the different apis from where the classes imported (JavaMail and some from Mock-JavaMail).