List of usage examples for org.apache.commons.io.input NullInputStream NullInputStream
public NullInputStream(long size)
From source file:org.codehaus.httpcache4j.cache.PersistentCacheStorageTest.java
private HTTPResponse createRealResponse() { return new HTTPResponse(new InputStreamPayload(new NullInputStream(10), MIMEType.APPLICATION_OCTET_STREAM), Status.OK, new Headers()); }
From source file:org.codehaus.httpcache4j.resolver.HTTPClientResponseResolverTest.java
@Test public void testNotSoSimpleGET() throws IOException { HTTPClientResponseResolver resolver = new TestableResolver(); HttpResponse mockedResponse = mock(HttpResponse.class); when(mockedResponse.getAllHeaders()).thenReturn(new org.apache.http.Header[] { new BasicHeader("Date", HeaderUtils.toHttpDate("Date", new DateTime()).getValue()) }); when(mockedResponse.getStatusLine()).thenReturn(new BasicStatusLine(new HttpVersion(1, 1), 200, "OK")); when(mockedResponse.getEntity()).thenReturn(new InputStreamEntity(new NullInputStream(1), 1)); when(client.execute(Mockito.<HttpUriRequest>anyObject())).thenReturn(mockedResponse); HTTPResponse response = resolver.resolve(new HTTPRequest(URI.create("http://www.vg.no"))); assertNotNull("Response was null", response); assertEquals("Wrong header size", 1, response.getHeaders().size()); assertTrue("Response did not have payload", response.hasPayload()); }
From source file:org.codehaus.httpcache4j.storage.jdbc.H2CacheStorageTestCase.java
@Test public void testPUTWithRealPayload() throws Exception { HTTPResponse response = new HTTPResponse( new InputStreamPayload(new NullInputStream(10), MIMEType.APPLICATION_OCTET_STREAM), Status.OK, new Headers()); assertEquals(0, storage.size());//ww w. ja v a 2s . co m HTTPResponse res = storage.insert(REQUEST, response); res.consume(); assertEquals(1, storage.size()); }
From source file:org.codice.ddf.configuration.migration.ImportMigrationManagerImplTest.java
private ZipEntry getDirZipEntry(ZipFile zip, String migratableId, Path path) throws IOException { final ZipEntry ze = Mockito.mock(ZipEntry.class); Mockito.when(ze.getName()).thenReturn(Paths.get(migratableId).resolve(path).toString() + '/'); Mockito.when(ze.isDirectory()).thenReturn(true); // use answer to ensure we create a new stream each time if called multiple times Mockito.doAnswer(AdditionalAnswers.answer(zea -> new NullInputStream(0L))).when(zip).getInputStream(ze); return ze;/*from www .ja va 2 s.c o m*/ }
From source file:org.fcrepo.apix.integration.StreamingIT.java
/** * Creates a container and a binary resource of 2MiB + 1 bytes long. Retrieves checksum of the resource. * * @throws FcrepoOperationFailedException if unexpected things go wrong * @throws IOException if unexpected things go wrong * @throws URISyntaxException if unexpected things go wrong */// w w w .ja va 2 s . c o m @Before public void initBinaryResources() throws FcrepoOperationFailedException, IOException, URISyntaxException { binaryContainer = URI.create(String.format("%s%s", fcrepoBaseURI, testClassName() + "/binaries/")); // Create container if it doesn't already exist if (!resourceExists(binaryContainer)) { try (FcrepoResponse r = client.put(binaryContainer) .body(new FileInputStream(new File(testResources, "objects/binary_container.ttl")), "text/turtle") .perform()) { assertEquals("Failed to create binary container '" + binaryContainer + "'", 201, r.getStatusCode()); } } // Create the binary resource if it doesn't already exist final URI expectedBinaryResource = appendToPath(binaryContainer, "large-binary"); if (!resourceExists(expectedBinaryResource)) { LOG.warn("Expected resource did not exist {}", expectedBinaryResource); try { binaryResource = postFromStream(new NullInputStream((2 * 1024 * 1024) + 1), binaryContainer, "application/octet-stream", "large-binary"); } catch (Exception e) { fail(String.format("Failed to create binary LDPR: %s", e.getMessage())); } } else { binaryResource = expectedBinaryResource; } // Retrieve the checksum calculated by Fedora binaryResourceSha = ModelFactory.createDefaultModel() .read(client.get(appendToPath(binaryResource, "/fcr:metadata")).accept("application/rdf+xml") .perform().getBody(), null) .listObjectsOfProperty( ResourceFactory.createProperty("http://www.loc.gov/premis/rdf/v1#", "hasMessageDigest")) .mapWith((digestValue) -> digestValue.toString().substring("urn:sha1:".length())).next(); assertNotNull("Missing http://www.loc.gov/premis/rdf/v1#hasMessageDigest on " + appendToPath(binaryResource, "/fcr:metadata").toString(), binaryResourceSha); }
From source file:org.geowebcache.s3.S3BlobStoreSuitabilityTest.java
@Override public BlobStore create(String[] dir) throws Exception { S3BlobStoreInfo info = tempFolder.getConfig(); for (String path : dir) { String fullPath = info.getPrefix() + "/" + path; try (InputStream is = new NullInputStream(0)) { tempFolder.getClient().putObject(info.getBucket(), fullPath, is, new ObjectMetadata()); }//from w ww . j a v a2s . c om } return new S3BlobStore(info, tld, locks); }
From source file:org.jenkinsci.plugins.authorizeproject.strategy.SpecificUsersAuthorizationStrategyTest.java
@Test public void testCliSuccess() throws Exception { prepareSecurity();/*ww w . ja va2 s . c o m*/ FreeStyleProject srcProject = j.createFreeStyleProject(); srcProject .addProperty(new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("test1", false))); srcProject.save(); WebClient wc = j.createWebClient(); wc.login("test1", "test1"); // GET config.xml of srcProject (userid is set to test1) String configXml = null; { CLI cli = new CLI(j.getURL()); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); int ret = cli.execute(Arrays.asList("get-job", srcProject.getFullName(), "--username", "test1", "--password", "test1"), new NullInputStream(0), stdout, stderr); assertEquals(stderr.toString(), 0, ret); configXml = stdout.toString(); } // POST config.xml of srcProject (userid is set to test1) to a new project. // This should success. FreeStyleProject destProject = j.createFreeStyleProject(); destProject.save(); String projectName = destProject.getFullName(); { CLI cli = new CLI(j.getURL()); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); int ret = cli.execute(Arrays.asList("update-job", destProject.getFullName(), "--username", "test1", "--password", "test1"), new ByteArrayInputStream(configXml.getBytes()), stdout, stderr); assertEquals(stderr.toString(), 0, ret); } { FreeStyleProject p = j.jenkins.getItemByFullName(projectName, FreeStyleProject.class); assertNotNull(p); AuthorizeProjectProperty prop = p.getProperty(AuthorizeProjectProperty.class); assertNotNull(prop); assertEquals(SpecificUsersAuthorizationStrategy.class, prop.getStrategy().getClass()); SpecificUsersAuthorizationStrategy strategy = (SpecificUsersAuthorizationStrategy) prop.getStrategy(); assertEquals("test1", strategy.getUserid()); } j.jenkins.reload(); { FreeStyleProject p = j.jenkins.getItemByFullName(projectName, FreeStyleProject.class); assertNotNull(p); AuthorizeProjectProperty prop = p.getProperty(AuthorizeProjectProperty.class); assertNotNull(prop); assertEquals(SpecificUsersAuthorizationStrategy.class, prop.getStrategy().getClass()); SpecificUsersAuthorizationStrategy strategy = (SpecificUsersAuthorizationStrategy) prop.getStrategy(); assertEquals("test1", strategy.getUserid()); } }
From source file:org.jenkinsci.plugins.authorizeproject.strategy.SpecificUsersAuthorizationStrategyTest.java
@Test public void testCliFailure() throws Exception { prepareSecurity();/* ww w . j av a2 s.c o m*/ FreeStyleProject srcProject = j.createFreeStyleProject(); srcProject .addProperty(new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("admin", false))); srcProject.save(); WebClient wc = j.createWebClient(); wc.login("test1", "test1"); // GET config.xml of srcProject (userid is set to admin) String configXml = null; { CLI cli = new CLI(j.getURL()); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); int ret = cli.execute(Arrays.asList("get-job", srcProject.getFullName(), "--username", "test1", "--password", "test1"), new NullInputStream(0), stdout, stderr); assertEquals(stderr.toString(), 0, ret); configXml = stdout.toString(); } // POST config.xml of srcProject (userid is set to admin) to a new project. // This should fail. FreeStyleProject destProject = j.createFreeStyleProject(); destProject.save(); String projectName = destProject.getFullName(); { CLI cli = new CLI(j.getURL()); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); int ret = cli.execute(Arrays.asList("update-job", destProject.getFullName(), "--username", "test1", "--password", "test1"), new ByteArrayInputStream(configXml.getBytes()), stdout, stderr); assertNotEquals(0, ret); } { FreeStyleProject p = j.jenkins.getItemByFullName(projectName, FreeStyleProject.class); assertNotNull(p); AuthorizeProjectProperty prop = p.getProperty(AuthorizeProjectProperty.class); assertTrue(prop == null || prop.getStrategy() == null); } j.jenkins.reload(); { FreeStyleProject p = j.jenkins.getItemByFullName(projectName, FreeStyleProject.class); assertNotNull(p); AuthorizeProjectProperty prop = p.getProperty(AuthorizeProjectProperty.class); assertTrue(prop == null || prop.getStrategy() == null); } }
From source file:org.kalypso.ogc.sensor.diagview.grafik.GrafikLauncher.java
/** * Starts the grafik with a java.lang.File tpl-File. *//*from ww w . ja v a 2 s . c om*/ private static IStatus startGrafikTPL(final File tplFile, final RememberForSync[] syncs, final IProgressMonitor monitor) throws SensorException { try { final File grafikExe = getGrafikProgramPath(); final String[] commands = new String[] { // grafikExe.getAbsolutePath(), "/V", tplFile.getAbsolutePath() }; //$NON-NLS-1$ final ICancelable cancelable = new ProgressCancelable(monitor); final ProcessHelper helper = new ProcessHelper(commands, null, grafikExe.getParentFile(), cancelable, 0, NullOutputStream.NULL_OUTPUT_STREAM, NullOutputStream.NULL_OUTPUT_STREAM, new NullInputStream(0)); helper.setKillOnCancel(false); helper.start(); if (monitor.isCanceled()) return new Status(IStatus.CANCEL, KalypsoGisPlugin.PLUGIN_ID, Messages.getString("GrafikLauncher.3")); //$NON-NLS-1$ return syncBack(syncs); } catch (final Exception e) { throw new SensorException(e); } }
From source file:org.kitodo.filemanagement.locking.LockManagementTest.java
/** * A user can return a lock on a file if it has closed all streams through that * lock. If not, he gets an IllegalStateException. *//*from ww w.j a va 2 s .c o m*/ @Test(expected = IllegalStateException.class) public void testLockCanOnlyBeReturnedIfAllStreamsAreClosedForOpenInputStream() throws IOException { underTest.clear(); LockResult alicesAccess = underTest.tryLock(createRequest(ALICE, AN_URI, LockingMode.UPGRADEABLE_READ), null); assertTrue(MESSAGE_ALICE_ALLOWED, alicesAccess instanceof GrantedAccess); try (InputStream openInputStream = underTest.reportGrant(AN_URI, new NullInputStream(0), alicesAccess)) { alicesAccess.close(); } }