Recent Posts
Archives

Archive for the ‘General’ Category

PostHeaderIcon Sonar / Constructor Calls Overridable Method

How to fix the Sonar’s following report?
[java]Constructor Calls Overridable Method [/java]

In the constructor of your class, assign the parameters to the right fields using the ‘=’ operator, and not the setXXX() methods. Indeed, the latter may be overriden by subclass.
Eg:
Replace:
[java]public Constructor(Param param){
setField(param);
}[/java]
With:
[java]public Constructor(Param param){
this.field = param;
}[/java]

PostHeaderIcon Sonar / Dead store of null to local variable

How to fix the Sonar’s following report?
[java]Dodgy – Dead store of null to local variable[/java]

Remove assignments at null of local variables that will not be read. Since Java 6, they have no interest and no effect on garbage collector.
Eg: remove the last assignment, in the line#4 [java]void foo(){
String goo = "hello world";
(…)
goo = null;
}[/java]

PostHeaderIcon Twitter within GoogleReader

Let’s say immediatly there is no miracle solution and it required a bit of work…

If the title is not explicit enough, the goal of this post is to give a way to include Twitter flow within your GoogleReader. IMHO, the main features of GoogleReader over regular Twitter are the following:

  • posts are stored on long term
  • posts can be searched or filtered by keywords
  • easy integration with Google Plus share button
  • ability to give a priority to feeds (as in Google Plus’s circles)
  • a simple interface to monitor all feeds

Unlike, following Twitter accounts on Google Reader (or even any other RSS aggregator) makes you lose the real time feature of Twitter.

This said, how to include your Twitter follow list within Google Reader syndication?

  • For each of the accounts you follow on Twitter, get the userId.
  • The easiest is to select a tweet > right click > source code > search the attribute “data-user-id”, get the associated number, eg: 813286 for @BarackObama, 50055701 for @MittRomney and 248309482 for my prefered one: @John_the_Cowboy ;-).
  • Alternatively, you can request the following service: http://www.idfromuser.com
  • In Google Reader, add a feed: https://twitter.com/statuses/user_timeline/XYZ.rss. Replace “XYZ” with the actual number retrieved before

Of course, this is not easy at all, as said in the disclaimer above. It is long, takes much time, and can become fastidious if you follow tens of people. Anyway, Google Reader users are geeks rather than newbies. You may create a Groovy script of setup a Mule instance to automatize de process ;-).

I suggest you to create one or many folders to gather the Twitter feeds.

PostHeaderIcon Move AVD default location on Windows

Two days ago, I twitted this:

Windows I hate you “PANIC: Could not open AVD config file”

Indeed, I tried to run an AVD (Android Virtual Device) from IntelliJ IDEA, in order to test my Android application. So far, I always ran AVD from KUbuntu, but a specific need I had to run on Windows Seven. The emulator could not start, because it was searching the actual AVD img file in the default folder, eg C:\Documents and Settings\<yourLogin>\.android\avd on Windows XP. Unfortunately, the folder could not be retrieved (a story of French special characters, such as ‘é’, ‘è’, ‘ç’, etc.).
Therefore, the question is: on Windows, how to change AVD default location?

I tried many more or less tricky solutions, but the simplest is the following:

  • close IDEA and AVD Manager
  • create an environment variable ANDROID_SDK_HOME (keys Windows + Pause), pointing to your target folder, eg: D:\workarea\honeycomb-sdk
  • create a .android subfolder, eg: D:\workarea\honeycomb-sdk\.android
    • if Windows does not allow you to create a folder of which name starts with a dot, then create it through Cygwin’s mkdir.
  • startup IDEA

PostHeaderIcon Training: Test Driven Development and Unit Testing Cooking Book

Last Tuesday I led a training session about Test Driven Development (TDD) in general, and Unit Tests in particular. I presented a series of best practices related to unit tests, as a set of “receipts”.
The target audience is developpers, either Java coders or other ones. The exercises have no interest from a Java perspective, but are intented at teaching the main concepts and tricks of unit testing.

The exercices are the following:

  • basics
  • methods within methods
  • layers and mocks
  • private methods
  • exceptions
  • loggers
  • new Date()

Here is the presentation:

The original OpenOffice file is hosted by GoogleDocs: Test Driven Development and Unit Testing Cooking Book

The source code of exercises and corrections are available at this link.

PostHeaderIcon How to call external shell in Groovy?

Going on learning Groovy, I faced the following case: how to call an external shell (or MS-DOS) command from a Groovy script?

It is very easy. The following example show how to display the Subversion status of the current folder:
[java]def proc = &quot;svn st&quot;
def sb = new StringBuffer()
proc.consumeProcessErrorStream(sb)

println proc.text + &quot;\n&quot; + sb.toString()
[/java]

PostHeaderIcon Error grabbing Grapes — [unresolved dependency: com.oracle#ojdbc14;10.2.0.4.0: not found]

I have learnt Groovy since the beginning of the week.
I had to import some classes from Oracle JDBC driver. As a newbie, I wrote the following annotation:
[java]@Grab(group = ‘com.oracle’, module = ‘ojdbc14’, version = ‘10.2.0.4.0’)[/java]

I got the following error:
[java]Error grabbing Grapes — [unresolved dependency: com.oracle#ojdbc14;10.2.0.4.0: not found][/java]

To sum up, adding a dependency to Oracle driver raises two issues:

  • adding any external dependency
  • adding a dependency to any JDBC driver

Indeed, Grab requires a kind of Maven repository, and you can catch the link between the @Grab annotation below and classic Maven 2 <dependency> tag. As I understood, Grab instructions are closer to Ivy than to Maven system. In my situation, having no “Grab repo” (I don’t know how to call that), I had to download the jars from a Maven repo. To fix it, two operations are needed: hint at Maven (or Ivy) repo, and allow Groovy to access the network.

Regarding the second issue, it is answered by added a @GrabConfig annotation.
Therefore, to fix the original issue:

  • replace [java]@Grab(group = ‘com.oracle’, module = ‘ojdbc14’, version = ‘10.2.0.4.0’)[/java]
    with[java]@GrabConfig(systemClassLoader=true)
    @GrabResolver(name=’nameOfYourMavenRepo, root=’http://url-of-your-maven-repo:port’)
    @Grab(group = ‘com.oracle’, module = ‘ojdbc14’, version = ‘10.2.0.4.0’)
    [/java]
  • at first run, if needed, hint at the proxy to allow Grab to download the Jars, eg: [java]groovy -Dhttp.proxyHost=myProxyHost -Dhttp.proxyPort=8080[/java]

You may notice the needed JAR will be written in the $USER_HOME/.groovy/grapes folder.

PostHeaderIcon Certified Scrum Master!

From now and then, I am certified Scrum Master. Certified Scrum Master

I attended the training lead by Jeff Sutherland (co-founder of Scrum method, CEO of Scrum Inc.).
Jeff gathers both practical knowledge from his personnal experience, and a deep work of research and reflexion on IT and processes around IT. As s skilled manager, engineer and orator, his training brings a lot of information and added value. Many thanks to him!

I’d like to thank Xebia France for their welcome, and, of course, Sungard Global Services and the BKN “Lean and Agile” for investing in its architects continuous improvement.

Jonathan LALOU and Jeff Sutherland - Paris, France, December 13th 2011

PostHeaderIcon How to export Oracle DB content to DBUnit XML flatfiles?

Case

From an Agile and TDD viewpoint, performing uni tests on DAO is a requirement. Sometimes, instead of using DBUnit datasets “out of the box”, the developper need test on actual data. In the same vein, when a bug appears on production, isolating and reproducing the issue is a smart way to investigate, and, along the way, fix it.
Therefore, how to export actual data from Oracle DB (or even MySQL, Sybase, DB2, etc.) to a DBUnit dataset as a flat XML file?

Here is a Runtime Test I wrote on this subject:

Fix

Spring

Edit the following Spring context file, setting the login, password, etc.
[xml]
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!– don’t forget to write this, otherwise the application will miss the driver class name, and therfore the test will fail–>
<bean id="driverClassForName" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="java.lang.Class"/>
<property name="targetMethod" value="forName"/>
<property name="arguments">
<list>
<value>oracle.jdbc.driver.OracleDriver</value>
</list>
</property>
</bean>
<bean id="connexion" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
depends-on="driverClassForName">
<property name="targetClass" value="java.sql.DriverManager"/>
<property name="targetMethod" value="getConnection"/>
<property name="arguments">
<list>
<value>jdbc:oracle:thin:@host:1234:SCHEMA</value>
<value>myLogin</value>
<value>myPassword</value>
</list>
</property>
</bean>

<bean id="databaseConnection" class="org.dbunit.database.DatabaseConnection">
<constructor-arg ref="connexion"/>
</bean>
<bean id="queryDataSet" class="org.dbunit.database.QueryDataSet">
<constructor-arg ref="databaseConnection"/>
</bean>
</beans>[/xml]

The bean driverClassForName does not look to be used ; anyway, if Class.forName("oracle.jdbc.driver.OracleDriver") is not called, then the test will raise an exception.
To ensure driverClassForName is created before the bean connexion, I added a attribute depends-on="driverClassForName". The other beans will be created after connexion, since Spring will deduce the needed order of creation via the explicit dependency tree.

Java

[java]public class Oracle2DBUnitExtractor extends TestCase {
private QueryDataSet queryDataSet;

@Before
public void setUp() throws Exception {
final ApplicationContext applicationContext;

applicationContext = new ClassPathXmlApplicationContext(
"lalou/jonathan/Oracle2DBUnitExtractor-applicationContext.xml");
assertNotNull(applicationContext);

queryDataSet = (QueryDataSet) applicationContext.getBean("queryDataSet");

}

@Test
public void testExportTablesInFile() throws DataSetException, IOException {
// add all the needed tables ; take care to write them in the right order, so that you don’t happen to fall on dependencies issues, such as ones related to foreign keys

queryDataSet.addTable("MYTABLE");
queryDataSet.addTable("MYOTHERTABLE");
queryDataSet.addTable("YETANOTHERTABLE");

// Destination XML file into which data needs to be extracted
FlatXmlDataSet.write(queryDataSet, new FileOutputStream("myProject/src/test/runtime/lalou/jonathan/output-dataset.xml"));

}
}[/java]

PostHeaderIcon Jonathan LALOU recommends… Jean-Pierre ISOARD

I wrote the following notice on Jean-Pierre ISOARD‘s profile on LinkedIn:

I have worked with Jean-Pierre for almost two years. Jean-Pierre has a wide knowledge of Java technologies and frameworks, plus a large experience of project management and team leading. Very committed to his tasks, Jean-Pierre releases a high quality work. Open-minded, he does not hesitate to challenge his ideas and positions, spotting at one point: provide the technical solution that fits the best the functional need. Therefore, I warmly recommend Jean-Pierre.