*
* @throws Exception
*/
public void testNodeBorders() throws Exception {
Document gmfgraph = getGmfgraph();
IterableElementList nl = xpath(gmfgraph, "/Canvas/figures/descriptors/actualFigure[@type = 'gmfgraph:Rectangle' or @type = 'gmfgraph:Ellipse' or @type = 'gmfgraph:RoundedRectangle']");
assertNotSame("We should have at least one figure node", nl.getLength(), 0);
boolean changed = false;
for (Element child : nl) {
// there should be a border here
IterableElementList e = xpath(child, "border[@type='gmfgraph:MarginBorder']");
String figure = child.getAttribute("name");
// how thick is the border of this figure?
int lineWidth = 1;
if (child.hasAttribute("lineWidth"))
lineWidth = Integer.valueOf(child.getAttribute("lineWidth"));
if (e.getLength() == 0) {
// add one
System.out.println("Adding border inset for figure " + figure);
Element border = gmfgraph.createElement("border");
border.setAttribute("xsi:type", "gmfgraph:MarginBorder");
child.appendChild(border);
Element inset = gmfgraph.createElement("insets");
inset.setAttribute("top", Integer.toString(2 + lineWidth));
inset.setAttribute("left", Integer.toString(2 + lineWidth));
inset.setAttribute("bottom", Integer.toString(2 + lineWidth));
inset.setAttribute("right", Integer.toString(2 + lineWidth));
border.appendChild(inset);
changed = true;
} else if (e.getLength() == 1) {
// there should be one inset in here
Element inset = hasXpathFirst(e.item(0), "insets");
assertNotNull("No inset found for figure " + figure, inset);
// should be equal to the expected
assertEquals(figure + " inset.top", Integer.toString(2 + lineWidth), inset.getAttribute("top"));
assertEquals(figure + " inset.left", Integer.toString(2 + lineWidth), inset.getAttribute("left"));