Articles Tagged ‘Java’

Writing BDD-Style Webservice Tests with Karate and Java

Thursday, April 6th, 2017

There is a new testing framework out there called Karate that is build on top of the popular Cucumber framework.

Karate makes it easy to script interactions with out web-services under test and verify the results. In addition it offers us a lot of useful features like parallelization, script/feature re-use, data-tables, JsonPath and XPath support, gherkin syntax, switchable staging-configurations and many others.

In the following tutorial we’ll be writing different scenarios and features for a real-world RESTful web-service to demonstrate some of its features.

(more…)

Load Testing Web Applications with Gatling and Maven

Friday, May 6th, 2016

I have written about other performance testing tools for web applications before. Nevertheless I’d like to demonstrate a library for load testing web applications named Gatling in combination with the build tool Maven.

Gatling offers a nice Scala DSL, high performance using Akka, Netty and asynchronous IO and plug-ins for all modern build tools.

In the following tutorial I’m going to show how to record simulations using an HTTP proxy, rewriting simulations in Scala and running and reporting simulations with Maven.

(more…)

A short Overview of Neo4j Indexing Strategies

Sunday, January 25th, 2015

When it comes to indexing in a Neo4j graph database, different options exist for a developer to create and maintain the index.

In the following short examples I’d like to demonstrate different possibilities for index management.

(more…)

Marrying Java EE and BDD with Cucumber, Arquillian and Cukespace

Wednesday, January 7th, 2015

Having written about the basics of using Cucumber in a Java project in my last blog article, I now would like to demonstrate how to use a similar setup in a Java EE web project with Arquillian and the Cukespace library.

In the following tutorial, we’re going to write a full Java EE web application and add BDD-style tests to the project so that we’re able to test our business layer on the one hand and the user interface on the other hand using Arquillian Drone and Selenium.

(more…)

BDD Testing with Cucumber, Java and JUnit

Sunday, December 28th, 2014

Whether behaviour-driven-development, specification by example or acceptance test driven development is the goal, the Cucumber framework eases our life when we need to  establish a link between the non-technical, textual description for a new feature and the tests that prove that the application fulfils these requirements.

In the following short tutorial I’d like to demonstrate how to add Cucumber to a Java project and how to write feature descriptions and test-cases for each step of these descriptions. (more…)

Creating a XMPP Chat Bot with Apache Camel

Sunday, October 12th, 2014

Apache Camel not only is one of my favourite frameworks ever but it also allows the humble developer to create a full blown chat bot within a few lines of code and using the Camel XMPP component.

In the following tutorial, we’re going to create a simple chat bot and since Atlassian’s HipChat basic plan is now free for unlimited users, we’re using HipChat as our play- and testing ground for the bot.

(more…)

Lucene by Example: Specifying Analyzers on a per-field-basis and writing a custom Analyzer/Tokenizer

Sunday, July 6th, 2014

Lucene is my favourite search engine library and the more often I use it in my projects the more features or functionality I find that were unknown to me.

Two of those features I’d like to share in the following tutorial is one the one hand the possibility to specify different analyzers on a per-field basis and on the other hand the API to create a simple character based tokenizer and analyzer within a few steps.

Finally we’re going to create a small index- and search application to test both features in a real scenario.

(more…)

Writing Java Integration Tests for MongoDB

Wednesday, October 16th, 2013

MongoDB is matured, document-oriented, cross-platform NoSQL database system with drivers available for a bunch of different programming languages.

In the following short examples I’m going to write some integration tests for MongoDB using the MongoDB Java driver and the Flapdoodle library to create an embedded MongoDB instance for testing.

We’re going to write tests for a simple persist-and-query scenarion and for a map-reduce function and in addition I’m going to show how to bind the start and stop of a MongoDB  instance to a Maven goal using the embedmongo-maven-plugin.

(more…)

Creating a Chat Application using Java EE 7, Websockets and GlassFish 4

Tuesday, August 13th, 2013

Java EE 7 is out now and so I was curious to play around with the new specifications and APIs from in this technology stack.

That’s why I didn’t hesitate to add yet another websocket-chat tutorial to the existing ones on the internet in favour of gathering some experience with this technology and a possible integration using a GlassFish 4 server, the new Java API for JSON Processing for data serialization combined with custom websocket encoders/decoders and finally adding some Bootstrap and jQuery on the client side.

(more…)

Embedding Jetty or Tomcat in your Java Application

Tuesday, July 9th, 2013

Recently I needed to control an embedded web container from a Java application and I wanted to see how this could be achieved using an embedded instance of either Tomcat or Jetty here.

In the following short examples I would like to show how to embed both servers in an application in no  time using Gradle or Maven as build tool.

(more…)

Creating and Packaging a Game in Java FX 2.2

Sunday, June 23rd, 2013

It’s been a long way for Java FX from the days of the F3 project the current release 2.2. Today there are many options how to create a Java FX application .. you may be using Java, Scala, Groovy or Visage, you may create your application in a programmatic way using the comfortable integrated builders or you may create your views using XML layouts and easy data-bindings with a few annotations.

If you need to bind your UI component properties to a specific application state, there’s a nice properties- and bindings API that makes your life easier.

In the following tutorial, I’m going to create a simple game application – one version using FXML templates, model- and controller classes and using external stylesheets – the other version as a programmatic version in one java class.

Finally I’m showing how easy it is to create a shippable application either as runnable jar or as Java Web Start/JNLP application by using Gradle and the Java FX Plugin for Gradle.

(more…)

Creating slim Database Projections using JPA2 Constructor Expressions

Sunday, April 14th, 2013

One common question that you may encounter one day when using object-relational-mapping in your application is how to slim down data that you’re retrieving from the persistence layer down to a specific subset for your use-case in an efficient manner and without using complex additional mapping frameworks. In some situations you might declare lazy loaded fields but another approach that I’d like to share with you here are JPA2 constructor expressions.

Constructor expressions allow us to create plain old java objects from the result of an JPA query. The advantage is that we may use different projections for different scenarios and without being managed, the POJOs might help us save some resources here.

In the following tutorial, we’re going to persist 100 book entities with multiple properties to an embedded database and we’re using constructor expressions afterwards to create smaller POJOs using a subset of the information available from each persisted book.

(more…)

Creating a Blueprint / Content-Creator Plugin for Confluence

Sunday, March 17th, 2013

Blueprint is a new API in Confluence 5 that allows developers to create new content elements and to hook into the Confluence “create” dialogue – not to be confused with OSGi blueprints, the CSS blueprint framework or Tinkerpop Blueprints here.

Content may be added using simple XHTML templates, dynamic templates enriched with data from context providers or even customized JavaScript dialogues.

Another feature is, that pages of a specific blueprint type may be aggregated in a collector view that displays all pages created with the specific blueprint

In the following short example we’re going to create a simple blueprint adding some dynamic data to the blueprint template using a context provider.

(more…)

Micro Benchmarking your Tests using JUnit and JUnitBenchmarks

Sunday, March 10th, 2013

I recently stumbled upon a nice framework that allows to convert simple JUnit tests into micro benchmarks named JUnitBenchmarks.

It allows to set basic benchmark options and and to generate charts by adding some simple annotations and a test rule to your tests.

One might argue if it is wise to mix the aspects, testing and benchmarking and I’d agree for sure – nevertheless I think this framework can be handy sometimes so let’s create some benchmarks using JUnit and JUnitBenchmarks..

(more…)

Content Detection, Metadata and Content Extraction with Apache Tika

Sunday, December 2nd, 2012

Encountering the situation that you want to extract meta-data or content from a file – might it be an office document, a spreadsheet or even a mp3 or an image – or you’d like to detect the content type for a given file then Apache Tika might be a helpful tool for you.

Apache Tika supports a variety of document formats and has a nice, extendable parser and detection API with a lot of built-in parsers available.

(more…)

Creating an offline Rich-Client-Application using HTML, CSS and Java with SWT

Monday, November 12th, 2012

There are a lot of frameworks out there to create offline applications and rich clients in Java.

One exotic alternative is to use the HTML, CSS and Javascript for this purpose and render the application in a Java frame using SWT and SWT’s browser component.

(more…)

Creating a Windows Executable from a Jar using Maven

Tuesday, August 7th, 2012

Often in the life of a developer there is the need to create a windows executable for a Java application that is build and packaged in a Jar file.

The following short example shows how to create an executable Jar first and a windows executable containing vendor information, a nice icon and other stuff afterwards by using a combination of the Maven Shade Plugin and the launch4j Plugin for Maven.

(more…)

Integration Testing IMAP, SMTP and POP3 with GreenMail

Tuesday, July 31st, 2012

Having written some e-mail handling, sending or receiving library you’d like to run some integration tests against a real mail server?

Then GreenMail might help you out here .. the framework is not quite new on the market but it is really easy to setup IMAP,SMTP or POP3 services with it and it comes with some helpful libraries making your life a bit easier here.

That’s why I’ve come to the idea to share some examples for setting up different server instances, creating user accounts and – at last – fetching and validating e-mails…

(more…)

Aspects of Functional Programming in Java

Monday, July 16th, 2012

Functional programming is a trending topic these days and a lot of Java programmers are hot for the features that modern functional programming languages might offer.

Waiting for Java 8 and native closure support is a nice thing but for now we’re going to take a look at several Java frameworks that are trying to implement typical structures from those functional languages where possible using the capabilities of the Java language to emulate elements like higher-order-functions, closures, options and others …

(more…)

Creating updatable Java Applications using Getdown and the Getdown Maven Plugin

Sunday, May 27th, 2012

Many programmers have suffered when trying to setup an environment to handle updates for their application without much effort. Some tried Java Web Start for this purpose and many encountered difficulties with this approach.

Now there is getdown that aims to replace Java Web Start by offering a simple architecture to handle updates that is fast, realiable and the only thing you need is a normal http server. Though getdown lets us handle our updates really easy it is possible to make this process even easier with the getdown maven plugin.

In the following example we’re building a simple swing application to be installed, updated and launched using getdown.

(more…)

Snippet: Mixing Scala, Java in a Maven Project

Friday, March 23rd, 2012

Having just returned from the Atlassian Camp 2012 I just toyed around with Java and Scala and wanted to share the following snippet that demonstrates how to mix code from both languages in a Maven project using the maven-scala-plugin.

(more…)

Finding Memory Leaks using Eclipse and the MemoryAnalyzer Plugin

Wednesday, November 2nd, 2011

The MemoryAnalyzer Plugin for Eclipse allows us to quickly analyze heap dumps from a virtual machine and search for memory leaks. In the following tutorial we’re going to create and run a small application that is going to cause an OutOfMemoryException during its runtime.

In addition, we’re forcing the virtual machine to save a heap dump and finally analyzing this data using Eclipse and the MemoryAnalyzer plugin.

(more…)

SCJP/OCPJP Exam Preparation: Pitfalls to avoid

Monday, April 25th, 2011

Last year I passed the exam for the “Oracle Certified Professional Java Programmer”successfully and wanted to share my exam preparation notes about common problems and pitfalls to be aware of.

That’s why I have added some code and examples for my top 25 challenges below.

(more…)

A look at Google’s Protocol Buffers

Tuesday, July 6th, 2010
Protocol Buffers are a serialization format developed by Google- you might ask if another IDL is really needed here – is Google barking at the wrong tree?
But protocol buffers offer some advantages over data serialization via XML or JSON – Google says they (compared to XML)..
  • are 3 to 10 times smaller
  • are 20 to 100 times faster
  • provide generated data access classes for programmatic use
  • provide backward compatibility
So lets play around a little with protocol buffers in Java and build a small application that serializes and deserializes some data using a defined format..

Review: "SCJP Sun Certified Programmer for Java 6 Study Guide"

Wednesday, March 24th, 2010

Short Facts:

  • About 850 pages – heavy weight – use it for self defence! ;)
  • Preparation material for the Sun Exam 310-065 (Sun Certified Java Programmer for Java SE 6)
  • CD-Rom with a nice exam simulator included
  • Authors: Kathy Sierry and Bert Bates
  • ISBN: 978-0071591065

(more…)

How to add a local lib directory to Maven

Thursday, March 18th, 2010
Sometimes there is a dependency not available at a remote repository and one is too lazy to set up a local maven repository – that’s when one adds a directory in the project structure and wants maven to find dependencies there. (more…)
Search
Categories