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.sonatype.nexus.plugins.lvo.strategy.AbstractRemoteDiscoveryStrategyTest.java
@Test public void testDirectRedirect() throws Exception { server = Server.withPort(0).serve("/test.properties") .withBehaviours(redirect("/redirect/test.properties", 301)).serve("/redirect/test.properties") .withBehaviours(content(content)).start(); AbstractRemoteDiscoveryStrategy underTest = create(); AbstractRemoteDiscoveryStrategy.RequestResult result = underTest .handleRequest(server.getUrl().toString() + "/test.properties"); assertThat(result.getInputStream(), notNullValue()); assertThat("content did not match", IOUtils.contentEquals(result.getInputStream(), new ByteArrayInputStream(content.getBytes())), is(true));/* w w w. j a v a2 s . c om*/ }
From source file:org.sonatype.nexus.plugins.lvo.strategy.AbstractRemoteDiscoveryStrategyTest.java
@Test public void testProxyRedirect() throws Exception { server = Proxy.withPort(0).serve("/test.properties") .withBehaviours(redirect("/redirect/test.properties", 301)).serve("/redirect/test.properties") .withBehaviours(content(content)).start(); RemoteProxySettings remoteCfg = remoteStorageContext.getRemoteProxySettings(); remoteCfg.setHostname("localhost"); remoteCfg.setPort(server.getPort()); AbstractRemoteDiscoveryStrategy underTest = create(); result = underTest.handleRequest("http://invalid.url/test.properties"); assertThat(result.getInputStream(), notNullValue()); assertThat("content did not match", IOUtils.contentEquals(result.getInputStream(), new ByteArrayInputStream(content.getBytes())), is(true));//from w w w.j a v a2s . c om }
From source file:org.sonatype.nexus.proxy.item.DefaultStorageFileItemTest.java
@Test public void testNonVirtualFileSimple() throws Exception { doReturn("dummy").when(repository).getId(); doAnswer(new Answer<RepositoryItemUid>() { public RepositoryItemUid answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); return getRepositoryItemUidFactory().createUid(repository, (String) args[0]); }/* www . j a v a 2s . com*/ }).when(repository).createUid("/a.txt"); DefaultStorageFileItem file = new DefaultStorageFileItem(repository, new ResourceStoreRequest("/a.txt"), true, true, new StringContentLocator("/a.txt")); checkAbstractStorageItem(repository, file, false, "a.txt", "/a.txt", "/"); // content InputStream is = file.getInputStream(); assertEquals(true, IOUtils.contentEquals(is, new ByteArrayInputStream(file.getRepositoryItemUid().getPath().getBytes()))); }
From source file:org.sonatype.nexus.proxy.item.DefaultStorageFileItemTest.java
@Test public void testNonVirtualFileWithContentSimple() throws Exception { doReturn("dummy").when(repository).getId(); doAnswer(new Answer<RepositoryItemUid>() { public RepositoryItemUid answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); return getRepositoryItemUidFactory().createUid(repository, (String) args[0]); }// ww w . ja v a 2 s . c o m }).when(repository).createUid("/a.txt"); DefaultStorageFileItem file = new DefaultStorageFileItem(repository, new ResourceStoreRequest("/a.txt"), true, true, new StringContentLocator("THIS IS CONTENT")); checkAbstractStorageItem(repository, file, false, "a.txt", "/a.txt", "/"); // content InputStream fis = file.getInputStream(); assertEquals(true, IOUtils.contentEquals(fis, new ByteArrayInputStream("THIS IS CONTENT".getBytes()))); }
From source file:org.sonatype.nexus.proxy.item.DefaultStorageFileItemTest.java
@Test public void testNonVirtualFileDeep() throws Exception { doReturn("dummy").when(repository).getId(); doAnswer(new Answer<RepositoryItemUid>() { public RepositoryItemUid answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); return getRepositoryItemUidFactory().createUid(repository, (String) args[0]); }/*from ww w . j av a2s. co m*/ }).when(repository).createUid("/some/dir/hierarchy/a.txt"); DefaultStorageFileItem file = new DefaultStorageFileItem(repository, new ResourceStoreRequest("/some/dir/hierarchy/a.txt"), true, true, new StringContentLocator("/some/dir/hierarchy/a.txt")); checkAbstractStorageItem(repository, file, false, "a.txt", "/some/dir/hierarchy/a.txt", "/some/dir/hierarchy"); // content InputStream is = file.getInputStream(); assertEquals(true, IOUtils.contentEquals(is, new ByteArrayInputStream(file.getRepositoryItemUid().getPath().getBytes()))); }
From source file:org.sonatype.nexus.proxy.item.DefaultStorageFileItemTest.java
@Test public void testNonVirtualFileWithContentDeep() throws Exception { doReturn("dummy").when(repository).getId(); doAnswer(new Answer<RepositoryItemUid>() { public RepositoryItemUid answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); return getRepositoryItemUidFactory().createUid(repository, (String) args[0]); }/*from w w w .jav a 2 s . co m*/ }).when(repository).createUid("/some/dir/hierarchy/a.txt"); DefaultStorageFileItem file = new DefaultStorageFileItem(repository, new ResourceStoreRequest("/some/dir/hierarchy/a.txt"), true, true, new StringContentLocator("THIS IS CONTENT")); checkAbstractStorageItem(repository, file, false, "a.txt", "/some/dir/hierarchy/a.txt", "/some/dir/hierarchy"); // content InputStream fis = file.getInputStream(); assertEquals(true, IOUtils.contentEquals(fis, new ByteArrayInputStream("THIS IS CONTENT".getBytes()))); }
From source file:org.sonatype.nexus.test.NexusTestSupport.java
/** * Both s1 and s2 will be closed.//from w ww . ja v a 2 s.c om */ protected boolean contentEquals(InputStream s1, InputStream s2) throws IOException { try (InputStream in1 = s1; InputStream in2 = s2) { return IOUtils.contentEquals(in1, in2); } }
From source file:org.sonatype.security.model.source.AbstractSecurityConfigurationSourceTest.java
public void testConfigStream() throws Exception { configurationSource = getConfigurationSource(); // not using load here since File config would load it and store it // thus changing it (but no content change!) copyDefaultSecurityConfigToPlace();/* ww w . j a v a 2 s .c o m*/ try (InputStream configStream = configurationSource.getConfigurationAsStream(); InputStream origStream = getOriginatingConfigurationInputStream()) { assertTrue(IOUtils.contentEquals(configStream, origStream)); } }
From source file:org.unitedinternet.cosmo.util.BufferedContentTest.java
/** * Tests buffered content.//from w ww. j a v a 2 s . c o m * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testBufferedContent() throws Exception { Random random = new Random(); // 100K test byte[] bytes = new byte[1024 * 100]; random.nextBytes(bytes); BufferedContent content = new BufferedContent(new ByteArrayInputStream(bytes)); Assert.assertTrue(content.getLength() == (1024 * 100)); // verify streams are the same Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(bytes), content.getInputStream())); // verify we can re-consume the same stream Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(bytes), content.getInputStream())); // should fit into memory Assert.assertTrue(content.getInputStream() instanceof ByteArrayInputStream); // should be buffered into file content = new BufferedContent(new ByteArrayInputStream(bytes), 1024 * 50); Assert.assertTrue(content.getLength() == (1024 * 100)); Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(bytes), content.getInputStream())); Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(bytes), content.getInputStream())); // should be in a file Assert.assertTrue(content.getInputStream() instanceof FileInputStream); }
From source file:org.unitedinternet.cosmo.util.BufferedServletOutputStreamTest.java
/** * Tests buffered servlet output stream. * /*from w w w . ja v a2 s. c o m*/ * @throws Exception * - if something is wrong this exception is thrown. */ @Test public void testBufferedServletOutputStream() throws Exception { byte[] testData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; BufferedServletOutputStream buf = new BufferedServletOutputStream(); // no data yet Assert.assertTrue(buf.isEmpty()); // write 8 bytes buf.write(testData); // should be data Assert.assertFalse(buf.isEmpty()); Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(testData), buf.getBufferInputStream())); buf.close(); }