Thursday, August 26, 2010

Run all your Groovy test cases using Ant

I needed to run all my Groovy unit test cases using Junit ant task, but for whatever reason I was not able to do it. I was able to do it using the following:

Wednesday, August 25, 2010

XML and Unit testing

I had to verify some XML using simple a String to verify. The code is the following:

public class FetchMessageServiceTest {
private static final String XML_INCOMING = "secretpassword876512345098765432155225testing 1,2";

public void shouldReturnAnXml() throws SAXException, IOException {
FetchMessageService service = new FetchMessageService(jmsTemplate, incomingService);
Redirection redirectionMock = getRedirection();
String xml = service.getXml(redirectionMock);
assertEquals(XML_INCOMING, xml);

When I ran the Junit task in Eclipse, everything was fine. But when I ran it in Junit Ant task, I got the following error:

[junit] expected:<<?xml version=["1.0" encoding="UTF-8"]?>    [junit] <redirection><aut...> but was:<<?xml version=['1.0' encoding='UTF-8']?>
[junit] <redirection><aut...>
[junit] <redirection><aut...> but was:<<?xml version=['1.0' encoding='UTF-8']?>
[junit] <redirection><aut...>

I then decided to use XMLUnit. Once I end up doing this, everything worked perfect. I am not sure if it is something with the output of the Ant or if it's something with String. The code is the following:

public void shouldReturnAnXml() throws SAXException, IOException {
FetchMessageService service = new FetchMessageService(jmsTemplate, incomingService);
Redirection redirectionMock = getRedirection();
String xml = service.getXml(redirectionMock);
XMLAssert.assertXMLEqual(XML_INCOMING, xml);

Everything seems to be working fine. I'm not sure if the problem with the test was with the output of Ant. I believe that it might be something to do with the output of the console and the encoding that it uses, but either way XMLUnit seems to be a great candidate for testing any type of XML regardless of the format.

Monday, August 23, 2010

Marshalling XML- Castor vs. Groovy MarkupBuilder

I worked on a small project where I needed to use some type of XML marshalling. I end up using Spring's (version 3) integration with Castor and JMS (ActiveMQ). I find it not that much flexible and eventually ended up using Groovy's XML libraries (really nice).

We had problems using the "conversion" of JMS (from object to JMS message), we find it easier to use an XML to transfer the messages in the JMS queue. The object that I wanted to convert to XML was a value object (immutable no setters) and using static factory. The object is the following:

public final class Redirection {

private RegisteredDate registeredDate;
private Authentication authentication;
private OperatorAndService operatorService;
private TextMessage textMessage;

private Redirection() {}

private Redirection(Authentication authentication,
OperatorAndService operatorService, TextMessage textMessage, Date date) {
this.authentication = authentication;
this.operatorService = operatorService;
this.textMessage = textMessage;
registeredDate = RegisteredDate.get( date!=null?date:new Date());


public static Redirection get(Authentication authentication,
OperatorAndService operatorService, TextMessage textMessage, Date date) {
return new Redirection(authentication, operatorService, textMessage, date);


public Authentication getAuthentication() {
return authentication;

public OperatorAndService getOperatorAndService() {
return operatorService;

public TextMessage getTextMessage() {
return textMessage;

public RegisteredDate getRegisteredDate() {
return registeredDate;

public String toString() {
return "Authentication: " + authentication + ", operator service: "
+ operatorService + ", text message: " + textMessage +
", registed date: " + registeredDate;

The implementation of the Castor is pretty simple using Spring 3:

I used the mapping, since I needed to pass three objects to the static factory to create my Redirection object (Authentication, OperatorAndService, and Textmessage). The mapping file was the following:

Mapping for the redirection object

The "get-method" is exactly what it means, is the method that you will use to fetch the object. The set-method is in case you have any setters (perfect for DTOs). However, my class is immutable so there are no setters. Instead, there is one static method that contains the three parameters that I needed to pass. There is a way to create an object without a constructor "verify-construcable=false". I wanted to see if there is a way to pass all the four object to my static factory, however, this did not work. The creation of the XML worked but not the creation of the object from the XML. I got the following error:

Castor unmarshalling exception; nested exception is org.exolab.castor.xml.MarshalException: unable to find matching public constructor for class

I try to look for a solution, but I had to tweak a lot of things to create a Redirection object. I then decided to look at Groovy's MarkupBuilder.

class XmlService {
private XmlService() {}

public static String getXml(Redirection redirect) {
if(redirect == null) {
throw new IllegalArgumentException("Redirection is invalid or null")

Authentication credentials = redirect.getAuthentication()
OperatorAndService operAndServ = redirect.getOperatorAndService()
TextMessage sms = redirect.getTextMessage()

def xml = new groovy.xml.StreamingMarkupBuilder()
xml.encoding = "UTF-8"
def redirection = {
redirection() {
authentication() {
operatorAndservice() {

return xml.bind(redirection);

public static Redirection toRedirection(String xml) {
if(Validation.isEmpty(xml)) {
throw new IllegalArgumentException("The application needs to have an xml")

def redirectionXml = new XmlParser().parseText(xml)
String username = redirectionXml.authentication.username.text()
String password = redirectionXml.authentication.password.text()
def authentication = Authentication.get(username, password)

//Operator and service
String serviceId = redirectionXml.operatorAndservice.serviceId.text()
String operatorId = redirectionXml.operatorAndservice.operatorId.text()
def operatorAndService = OperatorAndService.get(operatorId, serviceId)

//Text message
String phone =
String shortcode = redirectionXml.textmessage.shortcode.text()
String message = redirectionXml.textmessage.message.text()
def textMessage = TextMessage.get(phone, shortcode, message)

String registerDate = redirectionXml.registerdate[0].'@date'
def registeredDate = RegisteredDate.get(registerDate)

return Redirection.get(authentication,
operatorAndService, textMessage,
Groovy is a better candidate for this application. Its simplicity and flexibility beats Castor. The only thing that concerned me is the performance. I did noticed that the test cases using Castor were much faster. In case that performance is an issue, consider using Castor or other type of XML marshaling. I heard from one of my coworkers that xstream is very fast.

Wednesday, July 28, 2010

Keep your pulse on your business model

A friend told me about an anecdote of a start-up that was obviously heading in the wrong path. The company was quickly loosing money and yet the market was huge. The CEO fired the head of sales and marketing and decided to manage the department. Luckily, they had one thing in their favor, a lot of data. After some analysis and data mining, they realized that the B2C business model was no sustainable. Worse, there were signs of this about a year ago (sales plummeted). They did a small market research and talked with the customers. At the end, they found out the following based on their analysis:
  1. Accounts receivables were taking a nose dive
  2. There were several disruptive technologies and the market had changed
  3. Customers were unhappy with the current business model (the payable from our customers were lower than 70%)
  4. The B2C product had become a commodity and the only way to compete was through money (lower profits)
  5. Customers were looking into a more enterprise product

At the end, the company decided that a new product was needed. A product focused on B2B. With a small pilot they were able to "test the waters" and provide a successful use case. They are now selling the product and making sure that the same mistake doesn't happen again.

I've seem this type of behavior in current businesses. I'm a believer that when you get encountered with this type of issues, departments try to tackled it by using "brute force". I don't believe that this company's sales and marketing department were oblivious of the problem. Instead, I believe that they were just sticking to their strategy. They were too caught up with the every day details of trying to maintain their quota and get more customers. But, they didn't have the pulse on the market. In other words, no one checked if the business model was working.

A few weeks ago, I sat down with a founder of a company which I respect very much. The company was founded by three individuals. He was the COO, another founder became the head of sales, and the last one was a series entrepreneur. He explained that most of their success was mostly due to the management style of the sales manager (company started about 4 years ago and it was worth above $44 million). They called it, "One Hundred Days". Senior management would come up with a goal for the entire company that needed to be executed in the next 100 days. Then, whatever decision, customer, sales had to answered the following questions:

  • Is this according to the plan?
  • Would this get us closer to the plan?
  • Lets check the plan again.

I really like the idea. However, I would add a check and balance approach. You can easily loose focus in the every day task just like the head of marketing and sales in my friend's company. It is what Eric Ries calls "the pivot point".
Pivot is the ability to change direction in response to failure. Within every failure is a good idea waiting for the right circumstance or application. Pivot is an incremental and "zig-zagging path" towards the right market fit. The faster the pivot, the more likely a startup will find success before running out of money.
Ries contends that startups must be "built to learn", meaning validated learning about what customers want has to be the unit of measurement for company success. Turning ideas into products, and testing those ideas against reality, allows the company to pivot effectively, enabling customer-centered testing to be done by the dozen, or even, by the hundred.

A few months ago, I read a blog You're in a Museum by Steve Woodruff. He explained, the fact that there is always room for improvement and we should constantly try to seek for better solutions. He proposed to start thinking in different direction by asking the following questions:
  1. What is actually not working?
  2. What is missing and should be created?
  3. How could this be better?
  4. What new connections can be made?
  5. What do I want to leave behind as a legacy?
  6. How can ideal become real?
  7. What would I REALLY want to make happen if there were no limits?
  8. Why? And, while we're at it - why not?
In other words - question the status quo. We need to know when to change course or when our strategy is no longer working.

Friday, July 23, 2010

Groovy on Grails

I've been playing with Groovy and Grails for the past month. We had a demand of a few sites that needed to be constructed. The sites were small and needed to have some basic CRUD method and a small business rules. Then, we had to tie it with our SMS Gateway that we have developed. We evaluated a few languages, but at the end we chose Groovy for the following reasons:
  1. Dynamic language
  2. It sits in the JVM
  3. Easy to develop sites
We have been playing with the following versions:
  • Grails 1.3.3
  • Groovy 1.6.0_20
I have the most respect for the team who build this programming language. The language is very easy to read and the learning curve is very small. The integration that they did with Java, Spring, and Hibernate is very nice. The ORM tool that they created, GORM is very nice and very easy and quiet frankly it's my favorite.

class User {

String userId
String password
String homepage
Date dateCreated
Profile profile


User has a one to one relation with profile.

class Profile {
static belongsTo = User

byte[] photo
String fullName
String bio
String homepage
String email
String timezone
String country
String jabberAddress

static constraints = {
fullName(nullable: true)
bio(nullable: true, maxSize: 1000)
homepage(url: true, nullable: true)
email(email: true, nullable: true)
photo(nullable: true)
country(nullable: true)
timezone(nullable: true)
jabberAddress(email: true, nullable: true)


String toString() {
"Profile for ${fullName} (${id})"

The belongsTo is assigned the owning class, which means the relationship is unidirectional. You can get to a Profile via a User, but there’s no link back from a Profile to a User

class Post {
String content
Date dateCreated

static constraints = {
content(blank: false)
static belongsTo = [user: User]

static mapping = {
profile lazy: false
sort dateCreated: "desc"

static hasMany = [tags: Tag]

You can sort automatically within the mapping closure. In this example, all queries to the Post object will return in a descending order.

We use the map style of belongsTo, where we create a bidirectional link between User and Post classes. This creates a new field on Post called user that is the bidirectional mapping back to the owning User

Another useful technique is the validation of the fields. In the constraint closure you can specify the fields that need to be validated and the validation type. For example, in this case, content cannot be blank (null or empty).

The first deployment that I made was using "grails war". The con of this approach is that I look the dynamic compilation. So, if any change to the code, you would have to create the war once again, and deploy it. You gain performance but you loose the dynamism of Groovy. If performance is not a big issue, you can use "grails run-war". According to the documentation:
This is very similar to the previous option, but Tomcat runs against the packaged WAR file rather than the development sources. Hot-reloading is disabled, so you get good performance without the hassle of having to deploy the WAR file elsewherthe application is compiled with Java native code. Therefore, every change that I have to make I have to do it in Grails and deploy it once again.

I welcome your feedback in case I'm wrong.

Wednesday, May 26, 2010

What I've learned about business

I just found out that my answer was chosen as one of the winners in a book giveaway done by online MBA. The book giveaway was basically answering the question, "What I have learned about business". I honestly wanted to win. The price was one out of ten of my favorite books (I got Drive by Daniel H. Pink). The answer explored some of deep feelings towards management and business. What I have learned about business are four things:

  1. LOOOVE! what you do: people talk about it, but it's true...if you love what you do, you never have to work for the rest of your life. For people that love their job, they can't think of doing anything different or stop doing it. I've seen this in open-source project. Programmers who work in open-souce projects don't get paid and love to work on it...for FREE! These type of people are motivated to their core. Best of all, they are contagious! They act as a catalyst when they work with a team. When someone asks me about my job, it is like comparing my son's feeling towards Iron Man. Yes, programming and management are my Iron Man :)
  2. Never stop learning: always have a thirst for knowledge. I have noticed this with my son (he's eight-years-old) and he absolutely loves anything with the solar system. He picks up any type of book, movie, or anything that has to do with this subject. I also noticed this with former CIO Tom Clark and also with my friend Alsonso E Rhenals. They enjoy what they do and take a great pleasure in learning new things. Also, people who I consider mentors, regularly send me a post, article, or call me regarding on something that they just learned (Tom and Alonso do that all the times); they have the child-like curiosity for learning.
  3. Become a great communicator: a clear direction goes a long way. I've seen this with many individuals in business and politics. HBR did an interesting article talking about this specific thing,
    Scrupulously avoid impeding progress by changing goals autocratically, being indecisive, or holding up resources
  4. Maintain a humble attitude: we sometimes take for granted that we spend most of your time at work and at times it might be very frustrating. The only way you can get in and out of work and keep your friends is being humble. This is perhaps the hardest thing to do. I have only met one person, my friend Alex Fontanez. I have never met anyone who thinks badly about Alex or anyone that doesn't think Alex is not humble.

So, there you have it, the four things that I have learned about business.

Cell Phone Operating Systems

Online MBA provided this very interested information about cell-phone OS.
According to the latest estimates by Gartner, Android is supposed to surpass iPhone by 2012 with 14.5% of the market. The other interesting information is regarding the Comparison of App Stores. As we all know, there are more than 140,000 available apps for iPhone compared to Android's 30,000. However, Android is more developer friendly with its $25 fee rather than Apple's $99/year fees.

Cell Phone Operating Systems
Via: Online MBA

STARS - transition management

The STARS model is a great guide for a transition strategy. It's hard to know when you need to make a transition in your company, but a greater challenge is to know what type of strategy to use when making the transition. I found a very interesting article in the Harvard Business Review (January 2009) by Michael D. Watkins named "Picking the Right Transition Strategy". The article's emphasis is with the "state" of the company.
Once you understand the state of the organization or initiative you've heading up, you can more effectively apply certain fundamental principles (several of them listed here) to ease your transition and increase your odds of long-term success. Your business situation should shape how you apply those principles.
Using the author's STARS model, leaders can figure out which state the company is in and, more important, how to tailor their strategies for organizational and personal change accordingly.

The STARS model stands for the five different states of a company:
  • Start-Up
  • Turnaround
  • Accelerated Growth
  • Realignment
  • Sustaining Success

Start-UpTurnaroundAccelerated GrowthRealignmentSustaining Success
Assembling the capabilities (people, financing, and technology) to get a new business or initiative off the ground
Saving a business or initiative widely acknowledge to be in serious troubleManaging a rapidly expanding businessReenergizing a previously successful organization that now faces problemsComing in on the heels of a highly regarded leader with a stellar record of accomplishment
Building the strategy, structure, and systems from scratch without a clear framework or boundaries

Recruiting and welding together a high-performing team

Making do with limited resources
Reenergizing demoralized employees and other stakeholders

Making effective decisions under time pressure

Going deep enough with painful cuts and difficult personnel choices
Putting in place structure and systems to permit scaling

Integrating many new employees
Convincing employees that change is necessary

Carefully restructuring the top team and refocusing the organization
Living in the shadow of the former leader and managing the team he or she created

Playing good defense before embarking on too many new initiatives

Finding ways to take the business to the next level
You can do things right from the beginning.

People are energized by the possibilities.

There are no rigid preconceptions.
Everyone recognizes that change is necessary

Affected constituencies offer significant external support

A little success goes a long way
The potential for growth helps to motivate people

People will be inclined to stretch themselves and those who work form them
The organization has significant pockets of strength

People want to continue to see themselves as successful
A strong team may already be in place

People are motivated to continue their history of success

A foundation for continued success (such as long product pipeline) may be in place

Tuesday, May 18, 2010

Twitter is growing...BIG TIME!

As I mentioned before, Twitter is without a doubt a disruptive innovation in many different aspects and specially in premium text message/short messages (PSMS). As a definition, disruptive innovation is a term used in business and technology literature to describe innovations that improve a product or service in ways that the market does not expect, typically by lowering price or designing for a different set of consumers. Twitter's traffic is growing by leaps and bounds. The latest statistics based on comScore are:

And based on the latest keynote by Twitter CEO Evan Williams, the numbers are simple staggering:
  • 105 million registered users and they add 300k uses every day
  • 3 billion API request a day (equivalent to Yahoo traffic)
  • 55 million new tweets every day
  • 600 million search queries every day
  • 175 employees
  • 75% traffic comes from third party clients
  • 60% tweets come from third party clients
  • 100,000 registered apps
  • 180 million unique visitors on (you don’t have to be a user)
  • FlockDB, their social graph database that they just open sourced, stores 13 billion edges
  • They started using "Murder" a new BitTorrent platform to transfer files during development. This reduced the transfer time from 40 minutes to 12 seconds
  • Made deals with 65 (telco) carriers
  • 37% of active users use Twitter on their phone (@ev wants this number to be 100%)

What does this means for those companies that have their core strategy based on premium SMS? To be honest, I'm not sure. I do know that if your strategy is to offer text messages to DJs or SMS through TV tickers, then that's no a good long strategy. And as I mentioned previously, neither is a "joke" or "horoscope" subscription for $6.99. The bottom line is that it is hard as it is to fight against a trend such as Twitter, but it is even a bigger challenge to change someone minds about a brand or a product. Currently, Twitter is the de facto of users to communicate their thoughts to the world using mobile phones.

Tuesday, May 4, 2010

PSMS and Operators...c'mon lets get it together!

Last month T-Mobile deployed its 3PG (third party gateway) network to counteract the regulations of premium SMS (PSMS) making it harder to monetize from this model. One can argue that this is better for the consumer, but is also a great deal of headache for companies that build their strategy on PSMS. T-Mobile followed the footsteps of Verizon and AT&T. 3PG is a "billing platform" which provides a two phase charging (initiate/authorize & charge) to avoid spam or fraudulent transactions in mobile SMS.

The problem is that billing transactions in the US are through MT (mobile terminated) rather than MO (mobile originated). This means that if a customer wants to purchase a ringtone, the end-user will be charged once he receives the message/ringtone. This model, contrast to most Latin America and European market, has one flaw: spam. Individuals can potentially spam PSMS. The solution is through a validation process or a "two phase charging" process. This means that if the SMS has a tariff, it will be subjected to some validation.

As per December 2009 study, the US operator market share is composed with the following:
  1. Verizon : 31.2%
  2. AT&T : 25.0%
  3. T-Mobile : 12.1%
  4. Sprint : 12.1%
  5. Tracfone : 4.8%
  6. MetroPCS : 2.3%
  7. US Cellular : 2.2%
  8. Boost Mobile : 2.1%
  9. Cricket : 1.7%
  10. Virgin Mobile : 1.7%
  11. Others : 5.0%
Currently each of the top three operators have different platforms. Verizon has OIOO, AT&T has OPPC, and now T-Mobile has 3PG. All these platforms are different and they all tackle the same problem. In reality, all these operators are trying to develop a better mousetrap. Marketing companies are aware of this problems and agreed that something should be done. However, the operators or the government need to actually sit down and come up with some type of standardization.

In conclusion, marketing companies whose strategy are based on PSMS needs to really look at this model and considered if its worth it. In the book Good to Great, Jim Collins devoted an entire chapter on "confronting the brutal facts". Collins stated, that a "great" company cannot make a series of good decisions without confronting the brutal facts. At the end of the day, if you want to deal with PSMS you have to know that:
  1. You have to maintain different type of platforms specially if you just want to have the top three US operators
  2. The industry is becoming more and more regulated from both the carriers and the marketing companies to initiate campaigns
The choice is yours.

Wednesday, February 3, 2010

Want to motivate workers? Just ask, "any blocks?"

A manager can make a different when it comes to progress and can control it. As a manager, there are moments when the team makes great strides and everything seems to be humming. These are moments when our constituencies and business owners are happy that we are making progress. Most important, these are the moments when the team is extremely motivated. For over three years, I thought that these moments were out of my control. It all started three years ago when I worked with a team of ThoughtWorks. One of the project manager said,
...when you are a high level manager, you don't make a big difference at work.
Later at a bar we dissected that sentence. When you are a manager, progress is mostly made by people under you, but you are not doing the work per-se. You can measure, forecast, but you really can't increase the speed/velocity of the project.

On December, I read the article What Really Motivates Workes by Teresa M Amabile and Steven J. Krammer on HBR and found out that the top motivator for workers is progress. They based a research purely on understanding the power of progress. The authors found out that
on days when workers have the sense they're making headway in their jobs, or when they receive support that helps them overcome obstacles, their emotions are most positive and their drive to succeed is at its peak.
As a manager the key motivation turns out to be largely within my control. Manager have a large influence over events that facilitate or undermine progress. This enforces the Scrum methodology of having the daily 15-20 minute meetings and asking the three questions:
  1. What'd you do yesterday?
  2. What you gonna do today?
  3. Do you have any blocks?
I have to admit, I always focused on the first two questions. I did pay attention to the "blocks", but I didn't prioritized them as I should've been. I was under the impression that if we finished/burned tasks yesterday, and we were committed to burning some points today, we were making progress. Now, it's the opposite. The authors suggest to
Scrupulously avoid impeding progress by changing goals autocratically, being indecisive, or holding up resources.
I take a great care of dealing with this blockages ASAP. I don't just focus on the blockages. I take a great care to clarify overall goals, ensure that people's effort are properly supported, and reframe from exerting time pressure to intense that minor glitches are perceived as crises rather than learning opportunities. The other item that I need to focus is on cultivating a culture of helpfulness.

I was pretty impressed with this article and I made adequate changes after I read it. After a few weeks, I noticed some pretty good outcomes specially on my junior programmers. Not so much with my senior developers. One of the reasons is "changing context". When one of the junior developer/engineers gets stuck they would jump to ask the questions to the senior developers. As everyone knows, context changing is very expensive. I'm trying to put some type of threshold for the junior developers to ask a question (20-30 minutes). I was also thinking of making some new rules so that the senior developers don't get bother when they are focused on a particular tasks. One of the ideas was using headphones. If someone is wearing headphones that means that he's focusing on some type of task. I'm still trying to figure out how I can make this balance work, but so far it is good to know that I'm on control of it.