Saturday, June 18, 2016

Unit testing in Play

Play testing may be done on different levels: unit tests, functional tests, server test etc. - as it is mentioned in Play testing manual. The focus in this post is on writing of unit tests.

Thursday, June 16, 2016

Mocking of generic types with PowerMock and Mockito

See the earlier post Mocking with PowerMock and Mockito how to use the PowerMock for mocking of static classes. Mocking of generic types demands some additional handling.

Let's consider an example of a class with static methods and generic types in API.

Mocking of enum singleton class with PowerMock and Mockito

The earlier post Mocking with PowerMock and Mockito explains how to use the PowerMock for mocking of static classes. Another method of mocking with the PowerMock is the Whitebox class. It provides various utilities for accessing internals of a class. A singleton class which is implemented with enum singleton pattern, may be easily mocked with the Whitebox.setInternalState.

In the example below a singleton DAOFactory contains several DAO services as enum values. Each DAO service supports DB access to a particular DB entity.

Sunday, June 12, 2016

How to attach CSV file to Play application response

Play makes it easy to manipulate a HTTPResponse. You can find in the manual, how to add headers, set cookies etc. in a response. This post shows how to attach a CSV file to a HTTPResponse.

The implementation differs according to the use case:
  • Some string source is converted to csv file while sending to the client.
  • An existing csv file is sent to the client.

Wednesday, June 8, 2016

Using eclipse as Play IDE

Working with Play may be done with a simple text editor and activator UI. Yet it is hard to imagine that this happens in practice. Play has several plugins for different IDE-s. The eclipse plugin allows to transform a Play project into an eclipse project with the command sbt eclipse.

Eclipse plugin may be set per project or globally per sbt user. It depends on team work, which approach should be used. If the whole team is using eclipse IDE, plugin may be set on a project level.

Monday, June 6, 2016

Using log4j2 with Play application

Play default logging engine is Logback. It may be combined with the another logging framework or replaced at all starting from Play 2.5.
This post complements the Play manual, which explains how to customize the Logback configuration for Scala, but does not refers Java.

Saturday, June 4, 2016

Customizing Play application configuration

By default a Play application configuration is defined with a file conf/application.conf. The default configuration file may be replaced or additional configuration files may be provided.

About the author

My Photo
I trust only simple code and believe that code should be handsome. This is not a matter of technology, but professional approach, consolidated after years of software development. I enjoy to cause things working and feel very happy, when I manage to solve a problem.
Back to Top