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.mule.modules.hdfs.automation.testcases.AppendTestCases.java
@Category({ RegressionTests.class }) @Test/*from w w w . j a v a 2 s .c o m*/ public void testAppend() { Vector<InputStream> inputStreams = new Vector<InputStream>(); inputStreams.add((InputStream) getTestRunMessageValue("payloadRef")); InputStream inputStreamToAppend = getBeanFromContext("randomInputStream"); inputStreams.add(inputStreamToAppend); upsertOnTestRunMessage("payloadRef", inputStreamToAppend); SequenceInputStream inputStreamsSequence = new SequenceInputStream( (Enumeration<InputStream>) inputStreams.elements()); try { runFlowAndGetPayload("append"); IOUtils.contentEquals(inputStreamsSequence, (InputStream) runFlowAndGetPayload("read")); } catch (Exception e) { fail(ConnectorTestUtils.getStackTrace(e)); } }
From source file:org.mule.transport.http.servlet.MuleServletTestCase.java
@Test public void testHttpServletRequest() throws Exception { String queryParam = "array=1&array=2¶m1=param1&noValueParam"; DefaultMuleEvent event = getTestHttpEvent(queryParam); MuleHttpServletRequest request = new MuleHttpServletRequest(event); // is payload correct ServletInputStream stream = request.getInputStream(); assertNotNull(stream);/*from w w w . j ava2 s . c o m*/ IOUtils.contentEquals(new ByteArrayInputStream("test".getBytes()), stream); // headers assertEquals("value", request.getHeader("X-MyHeader")); assertEquals("UTF-8", request.getCharacterEncoding()); assertEquals(-1, request.getContentLength()); assertEquals("text/plain", request.getContentType()); assertEquals("/foo", request.getContextPath()); assertEquals("GET", request.getMethod()); assertEquals("/bar", request.getPathInfo()); assertEquals(queryParam, request.getQueryString()); assertEquals("/foo/bar", request.getRequestURI()); assertEquals("/foo", request.getServletPath()); assertEquals("127.0.0.1", request.getServerName()); }
From source file:org.nuxeo.build.ant.ZipDiffTask.java
@Override public void execute() throws BuildException { ZipFile zipfile1 = null;/* ww w. j a va 2 s.c om*/ ZipFile zipfile2 = null; try { zipfile1 = new ZipFile(file1); zipfile2 = new ZipFile(file2); Set<String> set1 = new LinkedHashSet<>(); for (Enumeration<? extends ZipEntry> zipEntries = zipfile1.entries(); zipEntries.hasMoreElements();) { set1.add((zipEntries.nextElement()).getName()); } Set<String> set2 = new LinkedHashSet<>(); for (Enumeration<? extends ZipEntry> zipEntries = zipfile2.entries(); zipEntries.hasMoreElements();) { set2.add((zipEntries.nextElement()).getName()); } try { if (includesfile != null) { includesfile.createNewFile(); fileWriter = new FileWriter(includesfile); } // includes (files from file1 not present or differ in file2) for (Iterator<String> i = set1.iterator(); i.hasNext();) { String filename = i.next(); if (!set2.contains(filename)) { log("Only in " + file1.getName() + ": " + filename, Project.MSG_INFO); include(filename, fileWriter); continue; } set2.remove(filename); if (!ignoreContent && !filename.matches(ignoreContentPattern)) { try { if (!IOUtils.contentEquals(zipfile1.getInputStream(zipfile1.getEntry(filename)), zipfile2.getInputStream(zipfile2.getEntry(filename)))) { log("Content differs: " + filename, Project.MSG_INFO); include(filename, fileWriter); } } catch (IOException e) { log(e, Project.MSG_WARN); } } } } catch (IOException e) { throw new BuildException(e); } finally { IOUtils.closeQuietly(fileWriter); } // excludes (files from file2 not present in file1) try { if (excludesfile != null) { excludesfile.createNewFile(); fileWriter = new FileWriter(excludesfile); } for (Iterator<String> i = set2.iterator(); i.hasNext();) { String filename = i.next(); log("Only in " + file2.getName() + ": " + filename, Project.MSG_INFO); exclude(filename, fileWriter); } } catch (IOException e) { throw new BuildException(e); } finally { IOUtils.closeQuietly(fileWriter); } } catch (IOException e) { throw new BuildException("Error opening " + file1 + " or " + file2, e); } finally { if (zipfile1 != null) { try { zipfile1.close(); } catch (IOException e) { throw new BuildException(e); } } if (zipfile2 != null) { try { zipfile2.close(); } catch (IOException e) { throw new BuildException(e); } } } }
From source file:org.nuxeo.connect.update.task.update.UpdateManager.java
/** * Look if an update is required, taking into account the given UpdateOptions, the currently installed JAR and the * other available JARs./*from w w w.j a v a2s . c o m*/ * * @since 5.7 * @param key * @param opt * @param currentJar * @return null if no update required, else the right UpdateOptions * @throws PackageException */ protected UpdateOptions shouldUpdate(String key, UpdateOptions opt, Match<File> currentJar) throws PackageException { log.debug("Look for updating " + opt.file.getName()); if (opt.upgradeOnly && currentJar == null) { log.debug("=> don't update (upgradeOnly)"); return null; } if (opt.allowDowngrade) { log.debug("=> update (allowDowngrade)"); return opt; } // !opt.allowDowngrade && (!opt.upgradeOnly || currentJar != null) ... UpdateOptions optToUpdate = null; Version packageVersion = registry.get(key).getVersion(opt.version); Version greatestVersion = registry.get(key).getGreatestVersion(); if (packageVersion.equals(greatestVersion)) { optToUpdate = opt; } else { // we'll use the greatest available JAR instead optToUpdate = UpdateOptions.newInstance(opt.pkgId, new File(backupRoot, greatestVersion.path), opt.targetDir); } FileVersion greatestFileVersion = greatestVersion.getFileVersion(); if (currentJar == null) { log.debug("=> update (new) " + greatestFileVersion); return optToUpdate; } // !opt.allowDowngrade && currentJar != null ... FileVersion currentVersion = new FileVersion(currentJar.version); log.debug("=> comparing " + greatestFileVersion + " with " + currentVersion); if (greatestFileVersion.greaterThan(currentVersion)) { log.debug("=> update (greater)"); return optToUpdate; } else if (greatestFileVersion.equals(currentVersion)) { if (greatestFileVersion.isSnapshot()) { FileInputStream is1 = null; FileInputStream is2 = null; try { is1 = new FileInputStream(new File(backupRoot, greatestVersion.path)); is2 = new FileInputStream(currentJar.object); if (IOUtils.contentEquals(is1, is2)) { log.debug("=> don't update (already installed)"); return null; } else { log.debug("=> update (newer SNAPSHOT)"); return optToUpdate; } } catch (IOException e) { throw new PackageException(e); } finally { IOUtils.closeQuietly(is1); IOUtils.closeQuietly(is2); } } else { log.debug("=> don't update (already installed)"); return null; } } else { log.debug("Don't update (lower)"); return null; } }
From source file:org.nuxeo.ecm.core.api.impl.blob.AbstractBlob.java
protected boolean equalsStream(Blob other) { InputStream is = null;/*w w w. ja v a 2 s .com*/ InputStream ois = null; try { persist(); other.persist(); is = getStream(); ois = other.getStream(); return IOUtils.contentEquals(is, ois); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(ois); } }
From source file:org.onehippo.repository.mock.MockBinaryTest.java
@Test public void getStream() throws IOException { IOUtils.contentEquals(new ByteArrayInputStream(data), binary.getStream()); }
From source file:org.onehippo.repository.mock.MockNodeTest.java
@Test public void testVariousTypesOfProperties() throws RepositoryException, IOException { MockNode root = MockNode.root();//from ww w . j ava2 s . co m MockNode node = root.addNode("node1", "nt:unstructured"); Calendar now = Calendar.getInstance(); byte[] binaryData = new byte[1]; node.setProperty("string1", "stringvalue1"); node.setProperty("boolean1", true); node.setProperty("long1", Long.MAX_VALUE); node.setProperty("date1", now); node.setProperty("double1", Double.MAX_VALUE); node.setProperty("bigdecimal1", BigDecimal.TEN); node.setProperty("binary", new MockBinary(new ByteArrayInputStream(binaryData))); assertTrue(node.getProperty("boolean1").getBoolean()); assertEquals(Long.MAX_VALUE, node.getProperty("long1").getLong()); assertEquals(ISO8601.format(now), ISO8601.format(node.getProperty("date1").getDate())); assertEquals(Double.toString(Double.MAX_VALUE), Double.toString(node.getProperty("double1").getDouble())); assertEquals(BigDecimal.TEN, node.getProperty("bigdecimal1").getDecimal()); assertEquals("stringvalue1", node.getProperty("string1").getString()); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(binaryData), node.getProperty("binary").getBinary().getStream())); node.setProperty("stringarray1", new String[] { "stringvalue1", "stringvalue2" }); node.setProperty("booleanarray1", new MockValue[] { new MockValue(PropertyType.BOOLEAN, "true"), new MockValue(PropertyType.BOOLEAN, "false") }); node.setProperty("longarray1", new MockValue[] { new MockValue(PropertyType.LONG, "123"), new MockValue(PropertyType.LONG, "456") }); node.setProperty("datearray1", new MockValue[] { new MockValue(PropertyType.DATE, "2013-10-30T00:00:00.000Z"), new MockValue(PropertyType.DATE, "2013-10-31T00:00:00.000Z") }); node.setProperty("doublearray1", new MockValue[] { new MockValue(PropertyType.DOUBLE, "1.23"), new MockValue(PropertyType.DOUBLE, "4.56") }); node.setProperty("bigdecimalarray1", new MockValue[] { new MockValue(PropertyType.DECIMAL, "1.23E3"), new MockValue(PropertyType.DECIMAL, "4.56E3") }); Value[] values = node.getProperty("stringarray1").getValues(); assertEquals(2, values.length); assertEquals("stringvalue1", values[0].getString()); assertEquals("stringvalue2", values[1].getString()); values = node.getProperty("booleanarray1").getValues(); assertEquals(2, values.length); assertEquals(true, values[0].getBoolean()); assertEquals(false, values[1].getBoolean()); values = node.getProperty("longarray1").getValues(); assertEquals(2, values.length); assertEquals(123, values[0].getLong()); assertEquals(456, values[1].getLong()); values = node.getProperty("datearray1").getValues(); assertEquals(2, values.length); assertEquals("2013-10-30T00:00:00.000Z", ISO8601.format(values[0].getDate())); assertEquals("2013-10-31T00:00:00.000Z", ISO8601.format(values[1].getDate())); values = node.getProperty("doublearray1").getValues(); assertEquals(2, values.length); assertEquals(Double.toString(1.23d), Double.toString(values[0].getDouble())); assertEquals(Double.toString(4.56), Double.toString(values[1].getDouble())); values = node.getProperty("bigdecimalarray1").getValues(); assertEquals(2, values.length); assertEquals(new BigDecimal("1.23E3"), values[0].getDecimal()); assertEquals(new BigDecimal("4.56E3"), values[1].getDecimal()); }
From source file:org.onehippo.repository.mock.MockSessionTest.java
@Test public void valueFactoryCanCreateBinaries() throws RepositoryException, IOException { Session session = new MockSession(MockNode.root()); ValueFactory factory = session.getValueFactory(); byte[] data = new byte[10]; data[3] = 42;// w ww .ja v a 2s .co m Binary binary = factory.createBinary(new ByteArrayInputStream(data)); assertEquals(data.length, binary.getSize()); IOUtils.contentEquals(new ByteArrayInputStream(data), binary.getStream()); }
From source file:org.onehippo.repository.mock.MockSessionTest.java
@Test public void valueFactoryCanCreateBinaryValues() throws RepositoryException, IOException { MockSession session = new MockSession(MockNode.root()); MockValueFactory factory = session.getValueFactory(); byte[] data = new byte[10]; data[3] = 42;/*w ww. j a v a2 s . co m*/ MockValue value = factory.createValue(new ByteArrayInputStream(data)); assertEquals(PropertyType.BINARY, value.getType()); final Binary binary = value.getBinary(); assertEquals(data.length, binary.getSize()); IOUtils.contentEquals(new ByteArrayInputStream(data), binary.getStream()); }
From source file:org.onesec.raven.ivr.vmail.impl.VMailBoxNodeTest.java
@Test public void getNewMessages() throws Exception { assertTrue(vbox.getNewMessages().isEmpty()); Date messDate = new Date(); vbox.addMessage(new NewVMailMessageImpl("123", "333", messDate, new FileDataSource(testFile))); assertEquals(1, vbox.getNewMessages().size()); List<SavableStoredVMailMessage> messages = vbox.getNewMessages(); SavableStoredVMailMessage mess = messages.get(0); assertEquals(messDate, mess.getMessageDate()); assertEquals("333", mess.getSenderPhoneNumber()); assertTrue(IOUtils.contentEquals(new FileInputStream(testFile), mess.getAudioSource().getInputStream())); Thread.sleep(10);// ww w .j a va 2s . c o m vbox.addMessage(new NewVMailMessageImpl("123", "222", new Date(), new FileDataSource(testFile))); Thread.sleep(10); vbox.addMessage(new NewVMailMessageImpl("123", "111", new Date(), new FileDataSource(testFile))); messages = vbox.getNewMessages(); assertEquals(3, messages.size()); assertEquals("333", messages.get(0).getSenderPhoneNumber()); assertEquals("222", messages.get(1).getSenderPhoneNumber()); assertEquals("111", messages.get(2).getSenderPhoneNumber()); }