Author Archives: jfnavin

Romania

Romania is an amazing country and one I highly recommend to any traveler coming to Europe. It has beautiful scenery ranging from rolling farmland to steep craggy mountains and dense forest, a rich history with a huge number of castles and churches, and (coming from Australia) is very affordable. The people are also very friendly and the country is very easy to travel in as a foreigner.

I arrived by plane into Bucharest and met up with my friend Chris. We spent a day seeing some of the sights of Bucharest in the pouring rain. Bucharest old town is pretty special – lots of interesting cobbled streets and impressive buildings. What surprised us though was the prevalence of massage parlors! Every block had at least one and many more were advertised in hotel lobbies. The most impressive sight though is definitely the Peoples Palace. This enormous building is the second largest in the world and was famously built by the dictator Nicolae Ceaușescu at great expense before he and his family were shot on Christmas day 1989 during the revolution. Today the palace is home to the Romanian government. It is enormous and extravagant – there are over 1300 chandeliers and 1 million cubic meters of marble.

Peoples Palace, Bucharest

While in Bucharest we also had a go at an ‘escape room’. This is kind of like a real-life computer game. You are placed in a room filled with clues that lead you to ‘solve’ the room. The first one we played had a war theme and the goal was to defuse a bomb. To be honest we kinda sucked. We over thought lots of things and missed really simple things. The staff member observing must have thought we were idiots! It was heaps of fun though – so much that we played again a week later when we got back to Bucharest. We were much better the second time round – we completed the room with 10mims to spare. Booya!

From Bucharest we hired a car and headed up into Transylvania. We spent a couple nights in Sinaia and used it as a base to see Peles, Bran and Rasnov castles, all of which were great in their own way. Peles was the royal castle for a number of years and is comparatively modern by castle standards. It still has all of its furnishings and is richly decorated which makes it appears like something out of a fairy tale. Bran castle is famous for its (rather tenuous) link to the Dracula story. It is pretty much the quintessential image of a Transylvanian castle even if the interior is less than authentic. Rasnov castle, in comparison, is huge and dates back to roman times. Not a lot is left of it now, but the views from the walls across the valley to the Carpathians are spectacular.

Peles Castle

After some intensive castle-visiting we spent a couple of days mountain biking. In Sinaia we caught the cable car to the cota 2000 station and rode through some beautiful alpine terrain for a couple of hours before descending along the road back to the valley. The most surprising part of that day was encountering shepherds in the alpine meadows and getting stuck in a sheep traffic jam for a good 20mins along a narrow road. The next day we rode with a guide from Brasov, north of Sinaia, up into the ski fields. The way up was basically 1.5hrs of grinding up fire trails, but it was worth it for the couple of hours descending back to Brasov along some really well made flowing single track. And as a bonus I only stacked once on a nasty steep tree-root filled descent. Luckily I managed to make it over the handlebars and land on my feet without any injury…

Riding above Sinaia

Brasov was a great town – of all the places in Romania I saw it is the one I could see myself living in. The old town has a great feel to it and it is surrounded by mountain biking, climbing and skiing. What more could you ask for?!? It was also home to the best meal I’ve had so far this trip – boar, bear and deer salami with cheese and dates to start; with a rich stew and polenta for mains; and apple pie and ice cream for desert. All washed down with a litre of really nice red wine and all for under $25AUD!

After Brasov we headed to Sighisoara – famous for its walled medieval city. Our accommodation was in a pension in the city walls themselves dating back to 1797 and restored over a number of years. On the way we visited a small town called Viscri which is a beautifully preserved Saxon village with a fortified church. The church is one of several in the area that are UNESCO listed and were built in smaller towns that did not have a fortress or castle as a way of defending the church and providing refuge for townspeople in times of conflict. The Viscri church is of particular note because Prince Charles is associated with the village and its restoration efforts.

Viscri church

Sighisoara old town itself is also beautiful. It has a maze of brightly colored houses packed together along cobbled streets and well-preserved city walls complete with intact guard towers named for the guilds that were once responsible for defending them (we stayed near the Weaver’s tower). Our host was a very friendly guy who gave us homemade schnapps (very strong!!) and recommended some sights along the road for the next day, including a church in a nearby town called Laslea.

The thing about this particular church is that it is not usually open to the public but we were reliably told that it can be accessed by “asking around town for the key”. This turned into a bit of an epic. We first tried at the hospital adjacent the church, but with no luck. We then decided to try the police station down the road. The local policeman had no idea who had the key (and told us he had never heard of anyone trying to get into the church before) but he was very friendly and decided that he too would like to know. So he made a few phone calls. Then a few more. Then he got a lead that it might be at the hospital, so we walked back down and he made some inquiries. They yielded nothing so he made a few more calls – all the while we are trying to tell him that its not really that important and we were just curious. But he was on a mission now. Finally he got another lead and jumped in his police car, returning 10mins later with a little old lady in her slippers who did indeed have the key! All told it took nearly an hour to get into the church! And it turned out to really just be a church. But given the trouble it took we felt obliged to look around in detail and make appreciative faces at everything. It did have an very cool watch tower though, which we asked if we could look inside. The policeman and key-lady were amused that we wanted to look in the obviously disused tower but told us to go right ahead. When we stuck our heads in there were some very old ladders leading up 4-5 very rickety landings to the top. So we climbed them… (No such thing as suing for stupidity in Romania…). When we got back down we discovered that the town’s only other policeman had arrived to look at the church too!

The church tower at Laslea

We spent that night in the old town of Sibiu, and then the next day we drove to Pitesti along the Transfagarason – a road made famous as the “best road in the world” by BBC Top Gear. And to be honest – it is an amazing road to drive. It starts through some villages in a valley and then winds its way up to a pass in the mountains with amazing corners and sheer drops and spectacular views. The road takes about 4 hrs to drive, and the scenery goes from steep mountains to deep forest and pretty lakes. Also along the way is Peionari castle perched high above the valley floor. This is the actual castle of Vlad Tepes the Impaler, and is the one associated with his infamous impaling of his enemies. Today the castle is mostly ruins but worth visiting – even with the 1500 stairs you have to climb to reach it.

The following day we drove the few hours between Pitesti and Bucharest where we returned the hire car and caught an overnight train to Moldova, which I’ll write about in my next post.

The big trip – Departure and Croatia

I’m sitting on the balcony watching a storm roll over Hvar town on the island of Hvar, Croatia. Its quite a cool sight but it does mean todays plans to explore the Pakleni islands have been put on hold. A good excuse to sit down and write a blog post on my travels so far.

Departure

Departure was surprisingly unstressed. After putting in some long hours at work in an effort to get things finished I was able to take a couple of days off before my flight out which gave me plenty of time to pack my bag and double check that everything was in order before I got on the bus to Sydney airport.

Getting to Croatia from Australia isn’t the most direct flight in the world. I ended up going Sydney-Singapore-Zurich-Split for a total of 36hrs transit, which meant I was pretty tired by the time I stepped off the plane into the Croatian heat.

Croatia

Croatia has been a great way to start my travels. I have been hanging out with my good friends Adam and Alana Kerz who are 14 months into their honeymoon. They have been traveling in a camper van through Europe and have adopted the relaxed lifestyle that comes with having time and flexible work commitments (Adam works several hours a week from his laptop – pretty good life if you ask me).

We spent the first week based in Split, staying in an apartment outside the old town area and driving each day to explore beaches, Split town, castles, nearby rock climbing areas and the Marian national park area. The high season is just starting to ramp up – the weather is hot and sunny but we haven’t had to fight with the excessive crowds that will arrive in the coming months. Perhaps the most famous sight in Split is the Diocletian’s palace – an amazing complex filled with narrow cobblestone streets and plaza and amazingly preserved Roman vaulted basement.

Basement of Diocletian's palace, Split

The Split area is a good mix of cultural and outdoor activities. The nearby Klis fortress is impressive – you can see it perched on top of sheer cliffs from right across the valley. It is in surprisingly good condition given its history and now boasts having been used as a location in the Game of Thrones television series. It also has the bonus of being 20mins walk to some pretty excellent limestone climbing (although the path is pretty scrubby – we came across 2 snakes as we ran back to the car in the midst of a lightning storm. The locals assure us the snakes aren’t poisonous but my Australian upbringing has meant I am cautious of any snake I come across…).

The nearby town of Omis is also geared as a bit of an outdoor destination with climbing, rafting and mountainbiking all in easy reach. We spent a fun afternoon whitewater rafting and swimming (including jumping from a 12m cliff into the river). Unfortunately we didn’t have enough time to do much else there but it’s on my list of places to come back to if I get the chance.

Hvar town, Croatia

From Split we took a ferry to Hvar island. This a touristy island that seems to be shaping itself as Croatia’s version of Ibiza with clubs and beach side bars etc and more tourists than locals. It is a very pretty place though, and was a great place to watch the opening game of World Cup 2014. All the bars and restaurants had big screen TVs playing the game and when Croatia scored the opening goal against Brazil everyone went nuts! The party kicked on to 4:30am…

We have a few days left here before I head to Romania. Hopefully the weather clears up and we can do some climbing and sightseeing…

Running Karma JS tests as part of a Maven CI build with Webjars

I spent several hours at work recently trying to solve this problem. The solution has a few moving parts to it, so I thought I’d jot down some notes to make it easier on myself and others in the future.

The problem

At my workplace we have an established Maven/Java workflow with tooling in place for executing CI builds and deploying built artefacts to our DEV/TEST/PROD environments etc. Some time ago we adopted Webjars as a way to manage static web resources via the Maven dependency management mechanism.

As we have become more front-end heavy and as the amount of business logic in our front-end code has increased, it has become increasingly important to integrate javascript unit and e2e tests into our build processes.

After evaluating some options we settled on the Karma test runner. This is a powerful test runner that supports cross-browser testing, multiple reporting formats and the ability to ‘watch’ project files and automatically re-run tests when a change is detected (very cool!). The easiest way to get Karma running is on NodeJS, which we didn’t have set up in our environment.

How do we integrate Karma-driven tests on a project that uses Webjar dependencies so that the tests can be run locally AND as part of a Maven CI build using our existing tooling?

If you want to skip ahead, a fully working project is available on github. Take a look at the README to get started.

Some background

First, some background on the various tools and libraries used for anyone not familiar with them.

Mavenhttp://maven.apache.org/
Maven is a dependency management and project build management system. It has become a de-facto standard for Java projects. It supports a wide variety of plugins that can be used together to perform arbitrarily complex build processes.

Webjars – http://webjars.org
Webjars is a convention for packaging client-side web libraries as JAR dependencies so they can be managed via Java-oriented tools such as Maven. They have the nice property that they can be included and managed as a project dependency in the same way that any regular JAR library can.

Karma – http://karma-runner.github.io/
Karma is a test runner library for executing JS tests. The tests can be run across multiple browsers and on multiple devices.

The solution

Overview

If you don’t want to get into the details, the breakdown of the solution is as follows:

  1. Setup webjar dependencies
  2. Host webjars using the Jetty Maven Plugin when developing locally
  3. Setup Karma to run locally using the hosted Webjar dependencies
  4. Use the Maven Dependency plugin to unpack Webjar dependencies during a CI build
  5. Create a CI-specific Karma configuration that uses the unpacked dependencies rather than the hosted ones during a CI build
  6. Use the Frontend-Maven-Plugin to install NodeJS and Karma local to the project during a CI build and execute the Karma tests
  7. (Optional) Add JUnit style reporting so the Karma test results can be reported on by CI tooling such as Jenkins etc.

Setup your project to use Webjars

This part is easy. Webjar dependencies can be added to your POM just as any other dependency.

<dependencies>
    ...
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>angularjs</artifactId>
        <version>1.2.16</version>
    </dependency>
    ...
</dependencies>

The Webjars documentation has instructions for getting Webjars running on a number of platforms. For ease of setup we’ll use a Servlet 3.0 container (see next section).

Setup Jetty configuration

The easiest way to make the webjar dependencies available is via a Servlet 3.0 container such as Jetty. I used the Jetty Maven Plugin which allows you to launch a fully configured Jetty container using Maven.

<build>
        <plugins>
            ...
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.0.M0</version>
                <configuration>
                    <webApp>
                        <contextPath>/maven-karma-webjars-example</contextPath>
                    </webApp>
                </configuration>
            </plugin>
            ...
        </plugins>
</build>

You can now launch Jetty using:

>> mvn jetty:run

And the webjar dependencies (along with any of your project resources) are now available on e.g. http://localhost:8080/maven-karma-webjars-example/webjars/angularjs/1.2.16/angular.min.js

Setup your Karma tests

Ideally you will be able to setup Karma to run locally on your development machine. Follow the installation instructions to get setup with NodeJS and Karma. If you can’t install Karma locally due to policy restrictions etc. you can get away without it – you will just need to execute tests via the Maven build which adds a bit of overhead.

The Karma setup instructions will get you most of the way there. Following Maven project conventions I put the karma.conf.js in src/test/webapp/js, which means you will need to set the project basePath appropriately. You will also want to reference the webjar dependencies at the container-hosted URL (e.g. http://localhost:8080/…).

module.exports = function(config) {
  config.set({
 
    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '../../../../',
 
    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],
 
    // list of files / patterns to load in the browser
    files : [
	'http://localhost:8080/maven-karma-webjars-example/webjars/angularjs/1.2.16/angular.js',
	'http://localhost:8080/maven-karma-webjars-example/webjars/angularjs/1.2.16/angular-mocks.js',
	'src/main/webapp/**/*.js', 
	'src/test/webapp/**/*.js' 
	],
 
 
    // list of files to exclude
    exclude: [
      '**/karma.*.js'
    ],
 
    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
 
    },
 
    // test results reporter to use
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],
 
    // web server port
    port: 9876,
 
    // enable / disable colors in the output (reporters and logs)
    colors: true,
 
    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,
 
    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,
 
    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],
 
    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  });
};

Now, assuming you have installed the karma-cli, you can run the Karma tests using:

>> karma start src/test/webapp/js/karma.conf.js

and navigating to http://localhost:9876

Setup Karma tests to run in a CI build

The Karma tests now run locally and will helpfully watch for changes to project resources and re-run the tests (how good is that!). Unfortunately, they still require a container to host the webjars which is not really appropriate for a CI build. Your environment might support this setup on your build server, but a better solution is to remove the dependency on the container altogether during a CI build.

First, create a Karma config specific for your CI job, e.g. karma.ci.conf.js. In this config you will want to:

  1. Reference the primary Karma config file; and
  2. Override the config object to switch to single-run mode and stop watching files
//Load the base configuration
var baseConfig = require('./karma.conf.js');
 
module.exports = function(config) {
	// Load base config
	baseConfig(config);
 
	// Update the location of webjar dependencies
	updateWebjarPaths(config);
 
	// Override base config
	config.set({
 
		// Switch to a headless PhantomJS browser for tests
		browsers : [ 'PhantomJS' ],
 
		// Only run once in CI mode
		singleRun : true,
 
		// Do no watch for file changes
		autoWatch : false
	});
};

Now to unpack the webjar dependencies to the file system so that Karma can see them without using a container. Luckily, there is a Maven plugin available that can do just that.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.8</version>
  <executions>
    <execution>
      <id>unpack</id>
      <goals>
        <goal>unpack-dependencies</goal>
      </goals>
      <configuration>
        <includes>**/*.js</includes>
      </configuration>
    </execution>
  </executions>
</plugin>

The last thing left is to tell Karma how to resolve the unpacked dependencies. We could simply set the files property again with the new file locations, but this will result in duplication and we hate duplication. A better option is to take advantage of the fact that Karma config files are simply JavaScript and write a function to do the resolution for us:

...
module.exports = function(config) {
	// Load base config
	baseConfig(config);
 
	// Update the location of webjar dependencies
	updateWebjarPaths(config);
 
	// Override base config
	config.set({
           ...
        });
};
 
//Override path to webjar dependencies
function updateWebjarPaths(config) {
	for (var i = 0; i < config.files.length; i++){
		config.files[i] = config.files[i].replace(
		  'http://localhost:8080/maven-karma-webjars-example/webjars', 
		  'target/dependency/META-INF/resources/webjars');
	}
}

Karma is now ready to run in a CI build. We just need to make Maven execute them at the correct time.

Invoke Karma from Maven

Karma runs on NodeJS. A simple way to get the tests running from Maven would be to execute the Karma CLI from the Maven build. However, this would require installing Node on your build server which can be difficult in some environments.

That’s where the Frontend Maven Plugin comes in. This neat plugin will install NodeJS local to the project, run NPM to install required dependencies, and then execute Karma.

<plugin>
	<groupId>com.github.eirslett</groupId>
	<artifactId>frontend-maven-plugin</artifactId>
	<version>0.0.14</version>
	<executions>
 
		<!-- 1. Install node and npm locally -->
		<execution>
			<id>install node and npm</id>
			<goals>
				<goal>install-node-and-npm</goal>
			</goals>
			<configuration>
				<nodeVersion>v0.10.18</nodeVersion>
				<npmVersion>1.3.8</npmVersion>
			</configuration>
		</execution>
 
		<!-- 2. Install karma and karma plugins -->
		<execution>
			<id>npm install</id>
			<goals>
				<goal>npm</goal>
			</goals>
		</execution>
 
		<!-- 3. Run karma tests -->
		<execution>
			<id>javascript tests</id>
			<goals>
				<goal>karma</goal>
			</goals>
			<configuration>
				<karmaConfPath>src/test/webapp/js/karma.ci.conf.js</karmaConfPath>
			</configuration>
		</execution>
	</executions>
</plugin>

Now give your config a whirl.

>> mvn clean install

If everything is working your tests should be run during the test phase of your build.

(Optional) Add a JUnit reporter

A little added extra that I find particularly useful is to configure a JUnit reporter for Karma that outputs test results in the JUnit XML format. This can be read along with your regular Java unit test results by your CI server to give aggregated test results that include your JS tests.

See https://github.com/karma-runner/karma-junit-reporter for more details on how to set it up.

Summary

At the end of the (somewhat lengthy) process above we now have:

  • Karma tests that can be run locally with Webjar dependencies
  • A Karma configuration suitable for running on a CI server; and
  • A Maven configuration that can setup Node+NPM+Karma as part of the build and execute the Karma tests

A working example project that illustrates everything above is available on github. Feel free to clone it and experiment with different configurations that make sense for your environment.

There are still some rough edges with this configuration that I am ironing out as development continues. These include:

  1. You need to remember to run the Jetty server before you try to execute your local Karma tests for the first time. If you don’t you get a less-than-helpful error.
  2. There are some issues with using Node/NPM and the Frontend Maven Plugin behind a corporate proxy server that has caused some problems for us. I haven’t gone into details here, but some workarounds have been needed to make it work nicely.

If you have thoughts or comments please post below. I’d really like to hear if/how other people have solved this (possibly arcane) problem.