List of usage examples for org.apache.commons.io IOUtils contentEquals
public static boolean contentEquals(Reader input1, Reader input2) throws IOException
From source file:org.apache.tiles.autotag.freemarker.FMModelRepositoryGeneratorTest.java
/** * Test method for {@link FMModelRepositoryGenerator#generate(File, String, TemplateSuite, java.util.Map)}. * @throws Exception If something goes wrong. *///from ww w .j a v a2 s. c om @Test public void testGenerate() throws Exception { Properties props = new Properties(); InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties"); props.load(propsStream); propsStream.close(); VelocityEngine velocityEngine = new VelocityEngine(props); FMModelRepositoryGenerator generator = new FMModelRepositoryGenerator(velocityEngine); File tempDir = new File(System.getProperty("java.io.tmpdir"), "autotag"); OutputLocator locator = new DirectoryOutputLocator(tempDir); tempDir.deleteOnExit(); TemplateSuite suite = new TemplateSuite("tldtest", "Test for TLD docs."); List<TemplateParameter> params = new ArrayList<TemplateParameter>(); TemplateParameter param = new TemplateParameter("one", "one", "java.lang.String", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "int", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "long", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); param = new TemplateParameter("modelBody", "modelBody", ModelBody.class.getName(), null, false, false); param.setDocumentation("The body."); params.add(param); TemplateMethod executeMethod = new TemplateMethod("execute", params); TemplateClass clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffTemplate", "doStuff", "DoStuff", executeMethod); clazz.setDocumentation("Documentation of the DoStuff class"); suite.addTemplateClass(clazz); params = new ArrayList<TemplateParameter>(); param = new TemplateParameter("one", "one", "java.lang.Double", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "float", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "java.util.Date", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); executeMethod = new TemplateMethod("execute", params); clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffNoBodyTemplate", "doStuffNoBody", "DoStuffNoBody", executeMethod); clazz.setDocumentation("Documentation of the DoStuffNoBody class"); suite.addTemplateClass(clazz); generator.generate(locator, "org.apache.tiles.autotag.freemarker.test", suite, null); InputStream expected = getClass() .getResourceAsStream("/org/apache/tiles/autotag/freemarker/test/TldtestFMModelRepository.javat"); File effectiveFile = new File(tempDir, "/org/apache/tiles/autotag/freemarker/test/TldtestFMModelRepository.java"); assertTrue(effectiveFile.exists()); InputStream effective = new FileInputStream(effectiveFile); assertTrue(IOUtils.contentEquals(effective, expected)); effective.close(); expected.close(); FileUtils.deleteDirectory(tempDir); }
From source file:org.apache.tiles.autotag.jsp.TagClassGeneratorTest.java
/** * Test method for {@link TagClassGenerator#generate(File, String, TemplateSuite, TemplateClass, Map)}. * @throws Exception If something goes wrong. *//*www. ja va 2 s .c o m*/ @Test public void testGenerate() throws Exception { Properties props = new Properties(); InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties"); props.load(propsStream); propsStream.close(); VelocityEngine velocityEngine = new VelocityEngine(props); TagClassGenerator generator = new TagClassGenerator(velocityEngine); File tempDir = new File(System.getProperty("java.io.tmpdir"), "autotag"); OutputLocator locator = new DirectoryOutputLocator(tempDir); tempDir.deleteOnExit(); TemplateSuite suite = new TemplateSuite("tldtest", "Test for TLD docs."); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("taglibURI", "http://www.initrode.net/tags/test"); List<TemplateParameter> params = new ArrayList<TemplateParameter>(); TemplateParameter param = new TemplateParameter("one", "one", "java.lang.String", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "int", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "boolean", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); param = new TemplateParameter("modelBody", "modelBody", ModelBody.class.getName(), null, false, false); param.setDocumentation("The body."); params.add(param); TemplateMethod executeMethod = new TemplateMethod("execute", params); TemplateClass clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffTemplate", "doStuff", "DoStuff", executeMethod); clazz.setDocumentation("Documentation of the DoStuff class."); generator.generate(locator, "org.apache.tiles.autotag.jsp.test", suite, clazz, parameters, "org.apache.tiles.autotag.jsp.test.Runtime", REQUEST_CLASS); InputStream expected = getClass().getResourceAsStream("/org/apache/tiles/autotag/jsp/test/DoStuffTag.java"); File effectiveFile = new File(tempDir, "/org/apache/tiles/autotag/jsp/test/DoStuffTag.java"); assertTrue(effectiveFile.exists()); InputStream effective = new FileInputStream(effectiveFile); assertTrue(IOUtils.contentEquals(effective, expected)); effective.close(); expected.close(); suite.addTemplateClass(clazz); params = new ArrayList<TemplateParameter>(); param = new TemplateParameter("one", "one", "java.lang.Double", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "float", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "java.util.Date", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); executeMethod = new TemplateMethod("execute", params); clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffNoBodyTemplate", "doStuffNoBody", "DoStuffNoBody", executeMethod); clazz.setDocumentation("Documentation of the DoStuffNoBody class."); suite.addTemplateClass(clazz); generator.generate(locator, "org.apache.tiles.autotag.jsp.test", suite, clazz, parameters, "org.apache.tiles.autotag.jsp.test.Runtime", REQUEST_CLASS); expected = getClass().getResourceAsStream("/org/apache/tiles/autotag/jsp/test/DoStuffNoBodyTag.java"); effectiveFile = new File(tempDir, "/org/apache/tiles/autotag/jsp/test/DoStuffNoBodyTag.java"); assertTrue(effectiveFile.exists()); effective = new FileInputStream(effectiveFile); assertTrue(IOUtils.contentEquals(effective, expected)); effective.close(); expected.close(); FileUtils.deleteDirectory(tempDir); }
From source file:org.apache.tiles.autotag.jsp.TLDGeneratorTest.java
/** * Test method for {@link TLDGenerator#generate(File, String, TemplateSuite, Map)}. * @throws Exception If something goes wrong. *///from w ww.j a v a2s . c om @Test public void testGenerate() throws Exception { Properties props = new Properties(); InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties"); props.load(propsStream); propsStream.close(); VelocityEngine velocityEngine = new VelocityEngine(props); TLDGenerator generator = new TLDGenerator(velocityEngine); File tempDir = new File(System.getProperty("java.io.tmpdir"), "autotag"); OutputLocator locator = new DirectoryOutputLocator(tempDir); tempDir.deleteOnExit(); TemplateSuite suite = new TemplateSuite("tldtest", "Test for TLD docs."); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("taglibURI", "http://www.initrode.net/tags/test"); List<TemplateParameter> params = new ArrayList<TemplateParameter>(); TemplateParameter param = new TemplateParameter("one", "one", "java.lang.String", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "int", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "long", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); param = new TemplateParameter("modelBody", "modelBody", ModelBody.class.getName(), null, false, false); param.setDocumentation("The body."); params.add(param); TemplateMethod executeMethod = new TemplateMethod("execute", params); TemplateClass clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffTemplate", "doStuff", "DoStuff", executeMethod); clazz.setDocumentation("Documentation of the DoStuff class"); suite.addTemplateClass(clazz); params = new ArrayList<TemplateParameter>(); param = new TemplateParameter("one", "one", "java.lang.Double", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "float", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "java.util.Date", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); executeMethod = new TemplateMethod("execute", params); clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffNoBodyTemplate", "doStuffNoBody", "DoStuffNoBody", executeMethod); clazz.setDocumentation("Documentation of the DoStuffNoBody class"); suite.addTemplateClass(clazz); generator.generate(locator, "org.apache.tiles.autotag.jsp.test", suite, parameters); InputStream expected = getClass().getResourceAsStream("/tldtest-jsp.tld"); File effectiveFile = new File(tempDir, "META-INF/tld/tldtest-jsp.tld"); assertTrue(effectiveFile.exists()); InputStream effective = new FileInputStream(effectiveFile); assertTrue(IOUtils.contentEquals(effective, expected)); effective.close(); expected.close(); FileUtils.deleteDirectory(tempDir); }
From source file:org.apache.tiles.autotag.velocity.VelocityDirectiveGeneratorTest.java
/** * Test method for//from w w w . j a va 2s . co m * {@link VelocityDirectiveGenerator#generate(File, String, TemplateSuite, TemplateClass, java.util.Map)}. * @throws Exception If something goes wrong. */ @Test public void testGenerate() throws Exception { Properties props = new Properties(); InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties"); props.load(propsStream); propsStream.close(); VelocityEngine velocityEngine = new VelocityEngine(props); VelocityDirectiveGenerator generator = new VelocityDirectiveGenerator(velocityEngine); File tempDir = new File(System.getProperty("java.io.tmpdir"), "autotag"); OutputLocator locator = new DirectoryOutputLocator(tempDir); tempDir.deleteOnExit(); TemplateSuite suite = new TemplateSuite("tldtest", "Test for TLD docs."); List<TemplateParameter> params = new ArrayList<TemplateParameter>(); TemplateParameter param = new TemplateParameter("one", "one", "java.lang.String", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "int", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "boolean", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); param = new TemplateParameter("modelBody", "modelBody", ModelBody.class.getName(), null, false, false); param.setDocumentation("The body."); params.add(param); TemplateMethod executeMethod = new TemplateMethod("execute", params); TemplateClass clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffTemplate", "doStuff", "DoStuff", executeMethod); clazz.setDocumentation("Documentation of the DoStuff class."); generator.generate(locator, "org.apache.tiles.autotag.velocity.test", suite, clazz, null, "org.apache.tiles.autotag.velocity.test.Runtime", REQUEST_CLASS); InputStream expected = getClass() .getResourceAsStream("/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat"); File effectiveFile = new File(tempDir, "/org/apache/tiles/autotag/velocity/test/DoStuffDirective.java"); assertTrue(effectiveFile.exists()); InputStream effective = new FileInputStream(effectiveFile); assertTrue(IOUtils.contentEquals(effective, expected)); effective.close(); expected.close(); suite.addTemplateClass(clazz); params = new ArrayList<TemplateParameter>(); param = new TemplateParameter("one", "one", "java.lang.Double", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "float", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "java.util.Date", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); executeMethod = new TemplateMethod("execute", params); clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffNoBodyTemplate", "doStuffNoBody", "DoStuffNoBody", executeMethod); clazz.setDocumentation("Documentation of the DoStuffNoBody class."); suite.addTemplateClass(clazz); generator.generate(locator, "org.apache.tiles.autotag.velocity.test", suite, clazz, null, "org.apache.tiles.autotag.velocity.test.Runtime", REQUEST_CLASS); expected = getClass() .getResourceAsStream("/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat"); effectiveFile = new File(tempDir, "/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.java"); assertTrue(effectiveFile.exists()); effective = new FileInputStream(effectiveFile); assertTrue(IOUtils.contentEquals(effective, expected)); effective.close(); expected.close(); FileUtils.deleteDirectory(tempDir); }
From source file:org.apache.tiles.autotag.velocity.VelocityPropertiesGeneratorTest.java
/** * Test method for/*from w w w. j av a 2 s .c o m*/ * {@link org.apache.tiles.autotag.velocity.VelocityPropertiesGenerator * #generate(File, String, TemplateSuite, java.util.Map)}. * @throws Exception If something goes wrong. */ @Test public void testGenerate() throws Exception { Properties props = new Properties(); InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties"); props.load(propsStream); propsStream.close(); VelocityEngine velocityEngine = new VelocityEngine(props); VelocityPropertiesGenerator generator = new VelocityPropertiesGenerator(velocityEngine); File tempDir = new File(System.getProperty("java.io.tmpdir"), "autotag"); OutputLocator locator = new DirectoryOutputLocator(tempDir); tempDir.deleteOnExit(); TemplateSuite suite = new TemplateSuite("tldtest", "Test for TLD docs."); List<TemplateParameter> params = new ArrayList<TemplateParameter>(); TemplateParameter param = new TemplateParameter("one", "one", "java.lang.String", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "int", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "long", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); param = new TemplateParameter("modelBody", "modelBody", ModelBody.class.getName(), null, false, false); param.setDocumentation("The body."); params.add(param); TemplateMethod executeMethod = new TemplateMethod("execute", params); TemplateClass clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffTemplate", "doStuff", "DoStuff", executeMethod); clazz.setDocumentation("Documentation of the DoStuff class"); suite.addTemplateClass(clazz); params = new ArrayList<TemplateParameter>(); param = new TemplateParameter("one", "one", "java.lang.Double", null, true, false); param.setDocumentation("Parameter one."); params.add(param); param = new TemplateParameter("two", "two", "float", null, false, false); param.setDocumentation("Parameter two."); params.add(param); param = new TemplateParameter("three", "three", "java.util.Date", null, false, false); param.setDocumentation("Parameter three."); params.add(param); param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true); param.setDocumentation("The request."); params.add(param); executeMethod = new TemplateMethod("execute", params); clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffNoBodyTemplate", "doStuffNoBody", "DoStuffNoBody", executeMethod); clazz.setDocumentation("Documentation of the DoStuffNoBody class"); suite.addTemplateClass(clazz); generator.generate(locator, "org.apache.tiles.autotag.velocity.test", suite, null); InputStream expected = getClass().getResourceAsStream("/velocity.properties.test"); File effectiveFile = new File(tempDir, "META-INF/velocity.properties"); assertTrue(effectiveFile.exists()); InputStream effective = new FileInputStream(effectiveFile); assertTrue(IOUtils.contentEquals(effective, expected)); effective.close(); expected.close(); FileUtils.deleteDirectory(tempDir); }
From source file:org.artificer.test.maven.ArtificerMavenTest.java
/** * Verifies that the correct file content was downloaded. * @param expected//from w w w.j a v a 2 s . c om * @param actual * @throws IOException */ private void assertContents(String expected, File actual) throws IOException { InputStream expectedStream = null; InputStream actualStream = null; try { expectedStream = getClass().getResourceAsStream(expected); actualStream = FileUtils.openInputStream(actual); Assert.assertTrue("File contents failed to match: " + actual.getName(), IOUtils.contentEquals(expectedStream, actualStream)); } finally { IOUtils.closeQuietly(actualStream); IOUtils.closeQuietly(expectedStream); } }
From source file:org.biokoframework.utils.matcher.EqualToStream.java
@Override protected boolean matchesSafely(InputStream actualStream) { try {//from w w w. jav a 2 s . c o m boolean equals = IOUtils.contentEquals(_expectedStream, actualStream); _expectedStream.close(); actualStream.close(); return equals; } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:org.craftercms.commons.zip.ZipUtilsTest.java
private void assertFileContents(File expected, File actual) throws IOException { InputStream expectedInputStream = new FileInputStream(expected); InputStream actualInputStream = new FileInputStream(actual); assertTrue(IOUtils.contentEquals(expectedInputStream, actualInputStream)); }
From source file:org.cryptomator.frontend.webdav.WebDavServerTest.java
@Test public void testGet() throws HttpException, IOException { final HttpClient client = new HttpClient(); // write test content: final byte[] testContent = "hello world".getBytes(); try (WritableFile w = fs.file("foo.txt").openWritable()) { w.write(ByteBuffer.wrap(testContent)); }//from ww w.j a v a 2 s . co m // check get response body: final HttpMethod getMethod = new GetMethod(servletRoot + "/foo.txt"); final int statusCode = client.executeMethod(getMethod); Assert.assertEquals(200, statusCode); Assert.assertThat(getMethod.getResponseHeaders(), hasItemInArray(new Header("Accept-Ranges", "bytes"))); Assert.assertTrue( IOUtils.contentEquals(new ByteArrayInputStream(testContent), getMethod.getResponseBodyAsStream())); getMethod.releaseConnection(); }
From source file:org.dataconservancy.packaging.tool.impl.BOREMPackageGeneratorTest.java
private void compareDataFile(TarArchiveInputStream ais, File pathToFile) throws IOException { InputStream fileIS = new FileInputStream(pathToFile); assertTrue(IOUtils.contentEquals(ais, fileIS)); }