Developing a Codec: Test driven development

The heard of this program is the codec which can create a graph in neo4j from a mxGraph input file.

An example for a mxGraph:

<mxGraphModel dx="811" dy="514" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="806" pageHeight="566" background="#ffffff">
    <mxCell id="0"/>
    <mxCell id="1" style="locked=1;" parent="0"/>
    <mxCell id="2" value="Hand 1" parent="0"/>
    <object label="Token" color="ros" dialect="no" lang="ital" pos="NPR" them_mak="ult" tool="spr" id="4">
    <mxCell style="tokenType=token;rounded=1;whiteSpace=wrap;fillColor=#FFFFFF;opacity=50;html=1;" parent="2" vertex="1">
        <mxGeometry x="180" y="10" width="120" height="60" as="geometry"/>

The GraphML format

The coded can also transform the arbitrary mxGraph format to the open GraphML standard, which looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <key id="label" for="node""label" attr.type="string"/>
  <key id="color" for="node""color" attr.type="string"/>
  <key id="dialect" for="node""dialect" attr.type="string"/>
  <key id="lang" for="node""lang" attr.type="string"/>
  <key id="pos" for="node""pos" attr.type="string"/>
  <key id="them_mak" for="node""them_mak" attr.type="string"/>
  <key id="tool" for="node""tool" attr.type="string"/>
  <key id="id" for="node""id" attr.type="string"/>
  <key id="parent" for="node""parent" attr.type="string"/>
  <key id="vertex" for="node""vertex" attr.type="string"/>
  <key id="hand" for="node""hand" attr.type="string"/>
  <key id="x" for="node""x" attr.type="string"/>
  <key id="y" for="node""y" attr.type="string"/>
  <key id="width" for="node""width" attr.type="string"/>
  <key id="height" for="node""height" attr.type="string"/>
  <key id="as" for="node""as" attr.type="string"/>
  <key id="tokenType" for="node""tokenType" attr.type="string"/>
  <key id="rounded" for="node""rounded" attr.type="string"/>
  <key id="whiteSpace" for="node""whiteSpace" attr.type="string"/>
  <key id="fillColor" for="node""fillColor" attr.type="string"/>
  <key id="opacity" for="node""opacity" attr.type="string"/>
  <key id="html" for="node""html" attr.type="string"/>
  <graph id="G" edgedefault="directed">
    <node id="4">
    <data key="label">Token</data>
    <data key="color">ros</data>
    <data key="dialect">no</data>
    <data key="lang">ital</data>
    <data key="pos">NPR</data>
    <data key="them_mak">ult</data>
    <data key="tool">spr</data>
    <data key="id">4</data>
    <data key="parent">2</data>
    <data key="vertex">1</data>
    <data key="hand">Hand 1</data>
    <data key="x">180</data>
    <data key="y">10</data>
    <data key="width">120</data>
    <data key="height">60</data>
    <data key="as">geometry</data>
    <data key="tokenType">token</data>
    <data key="rounded">1</data>
    <data key="whiteSpace">wrap</data>
    <data key="fillColor">#FFFFFF</data>
    <data key="opacity">50</data>
    <data key="html">1</data>

How can we verify that the codec works as wanted?

Verification is always difficult. Because the codec is a input-output program without sideeffects testing can be seen as an appropriate way.

In order to make sure that the tests make sense and the coverage is high Test Driven Development (TDD) was employed.

What is the biggest XML file it can transform

The codec is not optimized to work on big files but a few thousand elements with even more attributes are possible. Increasing the performance of the codec can be achieved easily.

Batch-add (+checksum)

By clicking on the “Batch-add”-Button all fragments are checked whether they have changed or not. Only if they have changed they are updated in the database. A SHA1 hash from the file original mxGraph XML file is stored every time one of these files is transferred to the database.