Sunday, December 29, 2013

Eclipse – Jenkins

Eclipse – Jenkins


Of course my assumption is that you are practicing continuous integration. If not you should begin with it right away. For more information see http://en.wikipedia.org/wiki/Continuous_integration.
One of the problems with Jenkins is that you need to always open the browser to check what the status of the build is. One of the rules for CI is never commit on a broken build (some even say on a running build), so you need to know the status of the build in a simple an easy way.
Another issue, is once the build is broken you need to click multiple times until you can get the information that you need to fix the build.
Well all this changes with the plugin for eclipse. You can download the plugin from http://marketplace.eclipse.org/content/hudsonjenkins-mylyn-builds-connector#.UsAyivQW1VA, or just search the market place for Jenkins.
This plugin will display the builds that you choose within your eclipse:


The interval for the status checking should be changed since the default is 15 minutes.
A double click on the build will display the tests run, where you can choose to see the console output



On the junit view, you can click on any test, and it will open the code for that test. You can filter the view to see only failed tests or all of them.
A right click on the build will bring you the option to view old build or even to run a new build.
Eclipse even support instant notifications that pop up when a build finished.
Once you install this plugin you will never need to open the Jenkins in your web browser again

Wednesday, December 18, 2013

XML Subsets

XML Subsets

Most applications today use XML for some form of data saving. In testing we also need to validate XML files, find entries in the XML via XPath and search for differences in the XML.
A lot of these abilities can be found in the lib of XMLUnit (http://xmlunit.sourceforge.net/)
This lib knows how to compare XML files, and other actions like:
·         The differences between two pieces of XML
·         The outcome of transforming a piece of XML using XSLT
·         The evaluation of an XPath expression on a piece of XML
·         The validity of a piece of XML
·         Individual nodes in a piece of XML that are exposed by DOM Traversal
One feature that I needed that it did not support is to detect if one XML is a subset of another. For example
I would like to check the following XML is a subset of the next one.
<a>
    <b>
        test b
    </b>
</a>
<a>
    <b>
        test a
    </b>
    <b>
        test b
    </b>
</a>
As you can guess a simple compare will fail since it will compare the first node of b in both XML’s and since the elements are not same it fails. What we need to do is to recursively search all nodes that have the same name and check if they are the same and not to stop on the first. This problem of course is not just on nodes but on attributes as well. If you need this functionally then you can grab the code below:

public class XmlSubsetHelper {
       static private boolean equalNotNullPointers(Object a, Object b) {
              if ((a == null && b != null) || (a != null && b == null)) {
                     return false;
              }
              return true;
       }

       static public boolean isSubset(NamedNodeMap namedNodeMapA,
                     NamedNodeMap namedNodeMapB) {
              if (!equalNotNullPointers(namedNodeMapA, namedNodeMapB)) {
                     return false;
              }
              if ((namedNodeMapA == null && namedNodeMapB == null)) {
                     return true;
              }
              for (int i = 0; i < namedNodeMapA.getLength(); i++) {
                     Node itemA = namedNodeMapA.item(i);
                     Node itemB = namedNodeMapB.getNamedItem(itemA.getNodeName());
                     if (itemB == null) {
                           return false;
                     }
                     if (!itemA.getNodeValue().equals(itemB.getNodeValue())) {
                           return false;
                     }
              }
              return true;

       }

       static public boolean isSubset(NodeList childNodesA, NodeList childNodesB) {
              if (!equalNotNullPointers(childNodesA, childNodesB)) {
                     return false;
              }
              if ((childNodesA == null && childNodesB == null)) {
                     return true;
              }
              for (int a = 0; a < childNodesA.getLength(); a++) {
                     boolean foundMatch = false;
                     Node itemA = childNodesA.item(a);
                     for (int b = 0; b < childNodesB.getLength(); b++) {
                           Node itemB = childNodesB.item(b);
                           if (isSubset(itemA, itemB)) {
                                  foundMatch = true;
                                  break;
                           }
                     }
                     if (!foundMatch) {
                           return false;
                     }
              }
              return true;
       }

       static public boolean isSubset(Node nodeA, Node nodeB) {
              if (!equalNotNullPointers(nodeA, nodeB)) {
                     return false;
              }
              if ((nodeA == null && nodeB == null)) {
                     return true;
              }
              if (!nodeA.getNodeName().equals(nodeB.getNodeName())) {
                     return false;
              }
              if (!isSubset(nodeA.getChildNodes(), nodeB.getChildNodes())) {
                     return false;
              }
              if (!isSubset(nodeA.getAttributes(), nodeB.getAttributes())) {
                     return false;
              }

              return true;
       }

       static public boolean isSubset(Document documentA, Document documentB) {
              if (!documentA.getDocumentElement().getNodeName()
                           .equals(documentB.getDocumentElement().getNodeName())) {
                     return false;
              }
              if (!isSubset(documentA.getDocumentElement(),
                           documentB.getDocumentElement())) {
                     return false;
              }
              return true;
       }

       static public Document parseXML(String xmlSource) {
              try {
                     DocumentBuilderFactory factory = DocumentBuilderFactory
                                  .newInstance();
                     DocumentBuilder builder = factory.newDocumentBuilder();
                     return builder.parse(new InputSource(new StringReader(xmlSource)));
              } catch (Exception e) {
                     throw new RuntimeException(e);
              }
       }

       static public boolean isSubset(String xmlA, String xmlB) {
              try {
                     return isSubset(parseXML(xmlA), parseXML(xmlB));
              } catch (Exception e) {
                     throw new RuntimeException(e);
              }

       }

}

Tuesday, December 3, 2013

Hebrew on the Pebble

Hebrew on the Pebble

There are many new smart watches out in the market. My personal one is the pebble. In my opinion a watch is an extension of the phone, and not a replacement,   and the pebble does just that.
The main disadvantage of the pebble is the SDK environment. There is no simple way to create a pebble application in windows. The workaround for this is a cloud environment that is very nice, you can find it at: https://cloudpebble.net/ide/. In the cloud IDE you upload your resources and write your code. From the cloud you can also compile the application and download it for installation from your phone.
This article will not go into the details of the pebble development. In a broad overview, the pebble GUI is made out of multiple layers that you can create. Each layer can have its own callback so that you can update each layer on a timer that suits you, and only update that layer. There are many API’s for writing text or graphics on each layer so that you can display almost any idea you have.

Language

The main feature that is lacking in my option is the support for multiple languages. Pebble supports only English, and does not support other languages. I am not sure for the reason behind this, it might be since the main market is in the US or the limited memory that the pebble has, or both.
For a review in Hebrew about the watch see: http://www.geektime.co.il/pebble-smartwatch-review/.
The pebble supports two types of applications. Once is a watch face and the other is a watch app. The watch face displays the time in different types of formats and visualizations (a list of watches can be found at http://www.mypebblefaces.com). The watch app is a richer application that usually also interacts with your phone.
If you want to create your own watch face but do not know or want to program, there is a great site that lets you customize your own watch app: http://www.watchface-generator.de/.

Fonts

This blog will deal only with the watch face, and in a future post we will write about watch apps.
What the pebble does support is the usage of True Type Fonts (TTF - http://en.wikipedia.org/wiki/TrueType). The pebble itself comes with some basic fonts and sizes built into the rom (https://developer.getpebble.com/blog/2013/07/24/Using-Pebble-System-Fonts/). You also have the option to add your own custom fonts at the cost of rom location in your app (http://developer.getpebble.com/sdkref/group___fonts.html).

Solution

Once I found this, the rest is as they say history. All I had to do is to use a Hebrew Font, say David, and decide on the font size that I want. I could then display any graphics that I wanted to, and when adding text I needed to use the TTF that I added to my watch. The only disadvantage is that since the pebble does not support RTL you need to write works backwards for it to display correctly.
The pebble has computing capabilities as well, so with a build in math lib, you can easily create a conversion from Gregorian dates to Jewish dates.  Do in addition to a Hebrew clock, you also get the current Hebrew date, and day of the week.

A copy of the watch face I created can be found at:



For the more adventurist people that want to see the code for the pebble have a look at:

More Hebrew watches

Another nice watch that displays in Hebrew words the time can be found at:




A watch that knows how to display the moon phase can be found at: