stubby4j – Java-based HTTP stub server

I released a Java-based HTTP stub server. We are actually using it on our current project. Give it a go, perhaps it can help you too. In brief, why would you use a stub HTTP server?

  • You want to simulate responses from real server and don’t care (or cannot) to go over the network
  • You want to verify that your code makes HTTP requests with all the required parameters and/or headers
  • You want to verify that your code correctly handles HTTP error codes
  • You want to trigger response from the server based on the request parameters over HTTP or HTTPS
  • You want support for any of the available HTTP methods
  • You want to trigger multiple responses based on multiple requests on the same URI
  • You want to easily configure stub data using configuration file
  • You want to easily configure stub data at runtime, without restarting the server by making a POST to an exposed endpoint
  • You want to easily provide canned answers in your contract/integration tests
  • You don’t want to spend time coding for the above requirements and just want to concentrate on the task at hand
  • Specifiable mock responses to simulate page conditions without real data.
  • Easily swappable data config files to run different data sets and responses.
  • All-in-one stub server to handle mock data with less need to upkeep code for test generation

 

LaTeX – Fonts with Ligatures

Spent some time yesterday playing with LaTeX again, and to be more specific – with fonts in LaTeX. I created a resume template by applying XeLaTeX type setting. The latter allows me easily to load system fonts (both OTF and TTF) in .TEX files.

It is very similiar to CSS – XeLaTeX allows you to load system fonts simply by calling font’s name in your commands. Have a look at the following example: I declared a new command HoeflerFont which uses one of my system fonts by its name: Hoefler Text


\newcommand{\HoeflerFont}[1]{\fontspec[Alternate=1,Ligatures={TeX,Common,NoCommon, Rare}]{Hoefler Text}\selectfont #1}

I used several different fonts for my resume with ligatures enabled. Ligatures are curly little letter tails that make text style look somewhat medieval. From Wikipedia:

In writing and typography, a ligature occurs where two or more graphemes are joined as a single glyph. Ligatures usually replace consecutive characters sharing common components and are part of a more general class of glyphs called “contextual forms”, where the specific shape of a letter depends on context such as surrounding letters or proximity to the end of a line.

In order to enable ligatures, the font needs to support them. In other words, not all fonts have ligatures enabled. The following image is a screenshot of my resume using fonts supporting ligatures.

Measure amount of WTFs per package or project

I created a library that measures amount of WTFs per package or project. This library is a by-product that derived from what I was doing few days ago:

I was dabbling with Java and decided to take a break. I came across a well know image that depicts code review session behind closed doors. The image called “The only valid measurement of code quality: WTF/minute”. I decided to make an extension to the latter concept.

This library brings you the ability to mark code smells in your source code (Classes, methods, fields etc.) with ‘WTF’ annotation. The WTF annotation accepts an arbitary message, if none provided, the default message ‘Dude.. WTF?!’ is used instead. When source compiles, the compiler generates a warning using the message from the detected annotation(s) and information about annotated element. The following is a sample output from compiling a class containing WTF annotations:

Warning: : In CLASS [wtf.per.project.model.DummyPojoImpl] :CLASS level => WTF?! Are you for real?! This naming convention is bad!
Warning: : In CLASS [wtf.per.project.model.DummyPojoImpl] : FIELD ‘SOME_CONSTANT’ => WTF?! What is this non-descriptive name?
Warning: : In CLASS [wtf.per.project.model.DummyPojoImpl] : CONSTRUCTOR ‘DummyPojoImpl(java.lang.String)’ => WTF?! Dude.. WTF?!

The library also provides a custom JUnit test runner class. The runner consumes package name, annotation class and search filter through @Grep annotation (used in conjunction with @RunWith). The runner scans .class files under the given package, its sub-packages and JARs for the given annotation (for example WTF.class) occurrences. If String regex pattern provided in @Grep, classes are filtered out from being scanned based on the filter. The runner uses a test class internally to assert whether the code is still infested with WTFs (or any other annotation class set in @Grep).

The analysis of .class files within given package, its sub-packages and any JAR files found is done using reflection. At first I was using third party library called ‘Reflections’ for this task (which is a very good tool btw!), but I ended up not using it anymore. I did not want to have third party dependencies and implemented my own meta data analysis in order to keep the library size small and lean. In the near future, I will extract the metadata analysis logic into a separate library. It should be quite flexible since there different .class file scanners in place. For example, scanner for constructors only or for method parameters, fields only etc.

So, if runner’s test assertion fails (given annotation like @WTF found present in the code), the test class generates metrics about how many WTFs are there and where. These metrics appended to the assertion failure message. For example, the following is the example of the custom JUnit runner:

@RunWith(WTFsPerProject.class)
@Grep(packageName = "wtf.per.project.model",
classNameFilter = ".*", annotationClass = WTF.class)
public final class WTFsPerProjectRunner { }

I have few POJOs marked with WTF annoation, the following is the produced output after running the above runner:

Another example of the custom JUnit runner:

@RunWith(WTFsPerProject.class)
//Grep only inner classes
@Grep(packageName = "wtf.per.project.model",
classNameFilter = ".*[$].*", annotationClass = WTF.class)
public final class WTFsPerProjectRunner { }

Disclaimer

I created this library for fun. Nothing more. If someone actually decides to use it – great.

If you want you can fork it on Github

Please report if you experience any problems :)

Unfamiliarity Causes Rejection

Recently I listened to a talk given by an ex-ThoughtWorker, Simon Harris. One of the things that Simon talked about was how we, developers (and generally speaking – human beings) sometimes tend to reject what is unfamiliar to us. Within software development context it can be an existing/legacy application or a module that we need to extend, and which is difficult to understand.

Really, how many times we looked at someone else’s work (eg:. a developer that has left the company a long time ago) and thought “Dude, this is so weak … come one”?

Instead of just pointing fingers, maybe we should stop for a moment, try to think and understand, what were the reasons for producing that mediocre piece of code? Look at the current software’s state from a different angle. Sure, sometimes a poorly written software is simply just that – a poorly written software without a particular reason. But at other times, perhaps there were unknown variables in the equation that prevented developers produce something of a higher quality: technical limitations? Some internal politics? Tight deadlines? Environment?

Understanding the historical/current state of an application, can only help us to come up with better results in the long run. I really enjoyed Simon‘s talk, he clearly draws from his extensive experience.

LateX – Transparent Watermark Image

If you want to add a watermark image to your LaTeX document, you can achieve it easily using three packages: graphicx, tikz and eso-pic:

Graphicx package allows to load images into documents. If you want to add transparency to your image, you need also to use tikz package. Tikz is used for producing vector graphics from a geometric/algebraic description, but is also allows to play with opacity levels.

Eso-pic package provides hooks to inserts the images on one or more pages as a background (in other words – a watermark).

[xml]
\\usepackage{graphicx}
\\usepackage{tikz}
\\usepackage{eso-pic}

\\newcommand\\BackgroundPicA{\\put(270,440){{%
\\begin{tikzpicture}\\node[opacity=0.1]{%
\\includegraphics[scale=0.80]{letter-watermark.jpg}};%
\\end{tikzpicture}%
}}}

\\newcommand\\BackgroundPicB{\\put(-80,-40){{\\reflectbox{%
\\begin{tikzpicture}%
\\node[opacity=0.1]{%
\\includegraphics[scale=0.80]{letter-watermark.jpg}};%
\\end{tikzpicture}%
}}}}

\\makeatletter%
\\AddToShipoutPicture{\\BackgroundPicA}%
\\AddToShipoutPicture{\\BackgroundPicB}%
\\makeatother

\\begin{document}
.
.
\\newpage
.
.
\\end{document}
[/xml]

I have attached a final result as PDF, so you can see the output: PDF with semi-opaqued watermark.

LateX – Style Section Title With a Color Filled Box

I was playing with LaTeX in order to create a resume template for my self. I was looking for a way to style title generated by the \section command. My goal was to generate color filled box with some text inside and some padding.

This is what I have came up with:

[java]
\\definecolor{gray}{RGB}{186,186,186}
\\section{\\fcolorbox{black}{gray}{\\color{black}%
{\\parbox{6.5in}{\\vspace{.03in}\\hspace{.03in}\\LaTe X{ is really cool}\\vspace{.03in}}}}}
[/java]

Which produced the following result:

LaTex - Style section title with a colored filled box

I Have Joined the ThoughtWorks Camp

I have some good news: I am going to be a ThoughtWorker. After two or three weeks of interviews, I have recently accepted their offer and going to start with the company in August.

I am really looking forward to it, since many bright, passionate and talented people work for ThoughtWorks. The company is known for its cutting-edge technology development and being one of the global leaders in enterprise Agile development services. In other words, I am really happy :)

I will keep writing updates from time to time about my experience at ThoughtWorks. Stay tuned.