@Test public void getAppRootTest() { Utils utils = new Utils(); assertNotNull(utils); assertTrue(Utils.getAppRoot().contains("/java2word")); }
@Test(expected = RuntimeException.class) public void readFileTestException() { String res = Utils.readFile(Utils.getAppRoot() + "/src/test/resources/not_a_file"); assertEquals(1, TestUtils.regexCount(res, "FileNotFoundException")); }
@Test public void testReplaceSpecialCharactersAll(){ String original = "Índio, "; assertEquals("Índio, ", Utils.replaceSpecialCharacters(original)); original = "Á, É, Í, Ó, Ú"; assertEquals("Á, É, Í, Ó, Ú", Utils.replaceSpecialCharacters(original)); original = "á, é, í, ó, ú"; assertEquals("á, é, í, ó, ú", Utils.replaceSpecialCharacters(original)); }
@Test //(expected = IllegalArgumentException.class) public void testFromSmallFilenameInputStream() throws Exception{ try { InputStream is = new BufferedInputStream( new FileInputStream(Utils.getAppRoot() + "/src/test/resources/dtpick.gif")); Image img = Image.from_STREAM("12", is); throw new Exception("It shouldn't get here"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("Can't create image - invalid filename")); } }
@Ignore @Test public void test93() { IDocument myDoc = new Document2004(); // String xmlTemplate = Utils.readFile("/home/leonardo/Desktop/paulo_93.doc"); //String xmlTemplate = Utils.readFile("/home/leonardo/Desktop/template_branco.xml"); String xmlTemplate = Utils.readFile("/home/leonardo/Desktop/template.doc"); TableV2 tbl = new TableV2(); tbl.addRow(TableRow.with("Simple String cell", "Another String simple cell")); xmlTemplate = replacePh(xmlTemplate, "<w:t><phTabela></w:t>", tbl.getContent()); System.out.println(xmlTemplate.trim()); //System.out.println(tbl.getContent()); //TestUtils.createLocalDoc(xmlTemplate.replace("</w:body>", tbl.getContent() + "</w:body>")); TestUtils.createLocalDoc(xmlTemplate.trim()); }
@Test(expected = java.lang.RuntimeException.class) public void testInvalidImage(){ Image img = Image.from_FULL_LOCAL_PATHL(Utils.getAppRoot() + "/src/test/resources/whatever"); }
String xmlTemplate = Utils.readFile("src/test/resources/ReleaseNotesTemplate.doc");
@Test(expected = RuntimeException.class ) public void testLocalImageWeb(){ Image img = Image.from_WEB_URL(Utils.getAppRoot() + "/src/test/resources/dtpick.gif"); }
@Test public void readFileTest() { String res = Utils.readFile(Utils.getAppRoot() + "/src/test/resources/resources.properties"); assertEquals(1, TestUtils.regexCount(res, "this is a regex test")); }
@Test(expected = RuntimeException.class ) public void testLocalImageClasspath(){ Image img = Image.from_CLASSPATH(Utils.getAppRoot() + "/src/test/resources/dtpick.gif"); }
@Test(expected = RuntimeException.class ) public void testLocalImageClasspathFluent(){ Image img = Image.from_WEB_URL(Utils.getAppRoot() + "/src/test/resources/dtpick.gif").create(); }
@Test public void sanityTestLocal() throws IOException{ ImageUtils imageUtils = new ImageUtils(); assertNotNull(imageUtils); BufferedImage bufferedImage = ImageIO.read(new File(Utils.getAppRoot() + "/src/test/resources/dtpick.gif")); String hexa = ImageUtils.getImageHexaBase64(bufferedImage, "gif"); assertEquals(1, TestUtils.regexCount(hexa, "R0lGODlhEAAQAPMAAKVNSkpNpUpNSqWmpdbT1v")); }
@Test public void testDefaultSize() throws IOException { Image img = Image.from_FULL_LOCAL_PATHL(Utils.getAppRoot() + "/src/test/resources/base2logo.png"); assertEquals(1, TestUtils.regexCount(img.getContent(), "style=\"width:116pt;height:104pt\"")); }
@Test public void testFromInputStream() throws FileNotFoundException{ InputStream is = new BufferedInputStream( new FileInputStream(Utils.getAppRoot() + "/src/test/resources/dtpick.gif")); Image img = Image.from_STREAM("leo.png", is); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*w:pict>")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shapetype")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shape[ >]")); //white space or > assertEquals(2, TestUtils.regexCount(img.getContent(), "wordml")); assertEquals(1, TestUtils.regexCount(img.getContent(), "width:16pt;height:16pt")); assertEquals(1, TestUtils.regexCount(img.getContent(), "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAAD")); }
@Test public void testWidth() throws IOException { Image img = Image.from_FULL_LOCAL_PATHL(Utils.getAppRoot() + "/src/test/resources/base2logo.png"); img.setWidth("120"); assertEquals(0, TestUtils.regexCount(img.getContent(), "style=\"width:116pt;height:104pt\"")); assertEquals(1, TestUtils.regexCount(img.getContent(), "style=\"width:120pt;height:104pt\"")); }
@Test public void testHeight() throws IOException { Image img = Image.from_FULL_LOCAL_PATHL(Utils.getAppRoot() + "/src/test/resources/base2logo.png"); img.setHeight("110"); assertEquals(0, TestUtils.regexCount(img.getContent(), "style=\"width:116pt;height:104pt\"")); assertEquals(1, TestUtils.regexCount(img.getContent(), "style=\"width:116pt;height:110pt\"")); }
@Test public void testWidthAndHeight() throws IOException { Image img = Image.from_FULL_LOCAL_PATHL(Utils.getAppRoot() + "/src/test/resources/base2logo.png"); img.setWidth("121"); img.setHeight("111"); assertEquals(0, TestUtils.regexCount(img.getContent(), "style=\"width:116pt;height:104pt\"")); assertEquals(1, TestUtils.regexCount(img.getContent(), "style=\"width:121pt;height:111pt\"")); }
@Test public void testLocalImageFluent(){ Image img = Image.from_FULL_LOCAL_PATHL(Utils.getAppRoot() + "/src/test/resources/dtpick.gif"); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*w:pict>")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shapetype")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shape[ >]")); //white space or > assertEquals(2, TestUtils.regexCount(img.getContent(), "wordml")); assertEquals(1, TestUtils.regexCount(img.getContent(), "R0lGODlhEAAQAPMAAKVNSkpNpUpNS"));//just the beginning of... }
@Test public void sanityTest() throws IOException{ Image img = Image.from_FULL_LOCAL_PATHL(Utils.getAppRoot() + "/src/test/resources/dtpick.gif"); //Image img = new Image(Utils.getAppRoot() + "/src/test/resources/base2logo.png"); // Image("/Users/leonardo_correa/Desktop/icons_corrup/quote.gif"); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*w:pict>")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shapetype")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shape[ >]")); //white space or > assertEquals(2, TestUtils.regexCount(img.getContent(), "wordml")); //for dtPicker.gif assertEquals(1, TestUtils.regexCount(img.getContent(), "R0lGODlhEAAQAPMAAKVNSkpNpUpNSqWmpdbT1v///////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAAAACH5BAEAAAYALAAAAAAQABAAQwRI0MhJqxmlkLwLyF8hYBpnluJArGzbjkEsB0NtD6PLAjyw\njqeOMANEDVGjm1IJm8WWONLxWDyGQjkdoecjVIOnrzEsKJvPaEEEADs=")); }
@Test public void testLocalImage(){ Image img = Image.from_FULL_LOCAL_PATHL(Utils.getAppRoot() + "/src/test/resources/dtpick.gif"); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*w:pict>")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shapetype")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shape[ >]")); //white space or > assertEquals(2, TestUtils.regexCount(img.getContent(), "wordml")); assertEquals(1, TestUtils.regexCount(img.getContent(), "R0lGODlhEAAQAPMAAKVNSkpNpUpNS"));//just the beginning of... }