    @Test
    public void testRewrite() throws Exception {


        Node rootNode = context.resourceResolver().getResource(ROOTS_PATH + "/matches/jcr:content").adaptTo(Node.class);

        StructureTreeRewriter rewriter = new StructureTreeRewriter(rules);
        Node rewrittenNode = rewriter.rewrite(rootNode);

        assertFalse(rewrittenNode.hasProperty("cq:designPath"));
        assertEquals(EDITABLE_TEMPLATE, rewrittenNode.getProperty("cq:template").getString());
        assertEquals(SLING_RESOURCE_TYPE, rewrittenNode.getProperty("sling:resourceType").getString());
        Node rootContainer = rewrittenNode.getNode("root");
        assertNotNull(rootContainer);

        NodeIterator rootContent = rootContainer.getNodes();
        assertTrue(rootContent.hasNext());
        assertEquals("header", rootContent.nextNode().getName());
        assertTrue(rootContent.hasNext());
        assertEquals("title", rootContent.nextNode().getName());

        assertTrue(rootContent.hasNext());
        Node replacedParsys = rootContent.nextNode();
        assertEquals("par", replacedParsys.getName());
        assertEquals(RewriteUtils.RESPONSIVE_GRID_RES_TYPE,
                replacedParsys.getProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY).getString());

        NodeIterator oldParsysContent = replacedParsys.getNodes();
        Node convertedColumn = oldParsysContent.nextNode();
        assertTrue(convertedColumn.getName().contains("responsivegrid"));
        assertEquals(RewriteUtils.RESPONSIVE_GRID_RES_TYPE,
                convertedColumn.getProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY).getString());
        NodeIterator columnContent = convertedColumn.getNodes();
        assertEquals("cq:responsive", columnContent.nextNode().getName());
        Node responsive = convertedColumn.getNode("cq:responsive");
        assertTrue(responsive.hasNode("default"));
        Node width = responsive.getNode("default");
        assertTrue(width.hasProperty("width"));
        assertEquals("6", width.getProperty("width").getString());
        assertTrue(width.hasProperty("offset"));
        assertEquals("0", width.getProperty("offset").getString());
        assertTrue(columnContent.hasNext());
        assertEquals("image", columnContent.nextNode().getName());
        assertTrue(columnContent.hasNext());
        assertEquals("title_1", columnContent.nextNode().getName());
        assertTrue(columnContent.hasNext());
        assertEquals("text_1", columnContent.nextNode().getName());

        assertFalse(columnContent.hasNext());

        // Found the next new responsive grid
        // Verify it's structure
        assertTrue(oldParsysContent.hasNext());
        convertedColumn = oldParsysContent.nextNode();
        assertTrue(convertedColumn.getName().contains("responsivegrid"));
        columnContent = convertedColumn.getNodes();
        assertTrue(columnContent.hasNext());
        assertEquals("cq:responsive", columnContent.nextNode().getName());
        responsive = convertedColumn.getNode("cq:responsive");
        assertTrue(responsive.hasNode("default"));
        width = responsive.getNode("default");
        assertTrue(width.hasProperty("width"));
        assertEquals("6", width.getProperty("width").getString());
        assertTrue(width.hasProperty("offset"));
        assertEquals("0", width.getProperty("offset").getString());

        assertTrue(columnContent.hasNext());
        assertEquals("image_0", columnContent.nextNode().getName());
        assertTrue(columnContent.hasNext());
        assertEquals("title_2", columnContent.nextNode().getName());
        assertTrue(columnContent.hasNext());
        assertEquals("text_0", columnContent.nextNode().getName());

        assertFalse(columnContent.hasNext());
        assertFalse(rootContent.hasNext());

    }