List of usage examples for org.apache.commons.io IOUtils toInputStream
public static InputStream toInputStream(String input)
From source file:com.github.restdriver.serverdriver.http.DefaultResponseTest.java
@Test public void contentEncodingOnResponseIsReadUsingThatEncoding() throws Exception { Header mockContentEncodingHeader = mock(Header.class); when(mockContentEncodingHeader.getValue()).thenReturn("ISO-8859-1"); HttpEntity mockEntity = mock(HttpEntity.class); when(mockEntity.getContentEncoding()).thenReturn(mockContentEncodingHeader); when(mockEntity.getContent()).thenReturn(IOUtils.toInputStream("????")); HttpResponse mockResponse = createMockResponse(mockEntity); Response response = new DefaultResponse(mockResponse, 12345); assertThat(response.getContent(), is(not("????"))); }
From source file:com.streamsets.pipeline.stage.executor.s3.TestAmazonS3Executor.java
@Test public void testCopyObjectDeleteOriginal() throws Exception { String newName = UUID.randomUUID().toString(); AmazonS3ExecutorConfig config = getConfig(); config.taskConfig.taskType = TaskType.COPY_OBJECT; config.taskConfig.dropAfterCopy = true; config.taskConfig.copyTargetLocation = newName; AmazonS3Executor executor = new AmazonS3Executor(config); TargetRunner runner = new TargetRunner.Builder(AmazonS3DExecutor.class, executor).build(); runner.runInit();//from ww w . j a va 2 s . c o m try { s3client.putObject(new PutObjectRequest(BUCKET_NAME, objectName, IOUtils.toInputStream("dropAfterCopy"), new ObjectMetadata())); runner.runWrite(ImmutableList.of(getTestRecord())); S3Object object = s3client.getObject(BUCKET_NAME, newName); S3ObjectInputStream objectContent = object.getObjectContent(); List<String> stringList = IOUtils.readLines(objectContent); Assert.assertEquals(1, stringList.size()); Assert.assertEquals("dropAfterCopy", stringList.get(0)); Assert.assertFalse(s3client.doesObjectExist(BUCKET_NAME, objectName)); Assert.assertEquals(1, runner.getEventRecords().size()); assertEvent(runner.getEventRecords().get(0), newName); } finally { runner.runDestroy(); } }
From source file:com.norconex.committer.elasticsearch.ElasticsearchCommitterTest.java
@Test public void testKeepIdSourceField() throws Exception { String content = "hello world!"; InputStream is = IOUtils.toInputStream(content); // Force to use a reference field instead of the default // reference ID. String sourceReferenceField = "customId"; committer.setSourceReferenceField(sourceReferenceField); Properties metadata = new Properties(); String customIdValue = "ABC"; metadata.setString(sourceReferenceField, customIdValue); // Add new doc to ES with a difference id than the one we // assigned in source reference field. Set to keep that // field./*from w ww .j ava 2 s. c o m*/ committer.setKeepSourceReferenceField(true); committer.add("1", is, metadata); committer.commit(); IOUtils.closeQuietly(is); // Check that it's in ES using the custom ID GetResponse response = client.prepareGet(indexName, typeName, customIdValue).execute().actionGet(); assertTrue(response.isExists()); // Check custom id field is NOT removed assertTrue(response.getSource().containsKey(sourceReferenceField)); }
From source file:com.elasticbox.jenkins.k8s.services.TestSlaveProvisioningFailing.java
@Test(expected = ServiceException.class) public void testSlaveProvisioningWithoutLabelWithPodFailing() throws Exception { final KubernetesCloud mockKubernetesCloud = Mockito.mock(KubernetesCloud.class); when(mockKubernetesCloud.getInstanceCap()).thenReturn(10); when(mockKubernetesCloud.getName()).thenReturn("FakeCloudName"); when(mockKubernetesCloud.getNamespace()).thenReturn("FakeNamespace"); final String podYamlDefault = getPodYamlDefault(); final PodSlaveConfig fakePodSlaveConfig = getFakePodSlaveConfig(podYamlDefault); List<PodSlaveConfig> podSlaveConfigurations = new ArrayList<>(); podSlaveConfigurations.add(fakePodSlaveConfig); final Pod pod = new DefaultKubernetesClient().pods().inNamespace(mockKubernetesCloud.getNamespace()) .load(IOUtils.toInputStream(fakePodSlaveConfig.getPodYaml())).get(); pod.setStatus(new PodStatus(null, null, null, null, "Failed", null, null, null)); final PodRepository podRepository = injector.getInstance(PodRepository.class); when(podRepository.getPod(anyString(), anyString(), anyString())).thenReturn(pod); when(podRepository.pod(anyString(), anyString(), anyString())).thenReturn(pod); doNothing().when(podRepository).create(anyString(), anyString(), any(Pod.class)); final List<PodSlaveConfigurationParams> podSlaveConfigurationParams = new ArrayList<>(); for (PodSlaveConfig config : podSlaveConfigurations) { podSlaveConfigurationParams.add(config.getPodSlaveConfigurationParams()); }/* w w w . ja v a 2s .c om*/ final SlaveProvisioningService slaveProvisioningService = injector .getInstance(SlaveProvisioningService.class); slaveProvisioningService.slaveProvision(mockKubernetesCloud, podSlaveConfigurationParams, null); }
From source file:cj.restspecs.core.RestSpec.java
static Representation createRepresentation(final JsonNode node, final Loader loader, final String contentType) { if (node.path("representation").isMissingNode() && node.path("representation-ref").isMissingNode()) { return null; }/*from w w w.j ava 2 s . c om*/ return new Representation() { public String contentType() { return contentType; } public InputStream data() { JsonNode representation = node.path("representation"); if (!representation.isMissingNode()) { return IOUtils.toInputStream(representation.getValueAsText()); } JsonNode repRef = node.path("representation-ref"); if (!repRef.isMissingNode()) { String resourcePath = repRef.getValueAsText(); return loader.load(resourcePath); } throw new IllegalStateException( "rest spec does not have representation or representation-ref response node"); } public String asText() { try { String textRepresentation = IOUtils.toString(data()); textRepresentation = textRepresentation.replaceAll("\n\\$", ""); //remove newline from last line of response spec return textRepresentation; } catch (IOException ioe) { /*can't do that*/ } return null; } }; }
From source file:com.collective.celos.ci.testing.fixtures.compare.RecursiveFsObjectComparerTest.java
private FixDir getFixDirWithTwoFilesWrongTypes() { InputStream inputStream1 = IOUtils.toInputStream("stream"); FixFile file1 = new FixFile(inputStream1); FixDir file2 = new FixDir(Maps.<String, FixFsObject>newHashMap()); Map<String, FixFsObject> content1 = Maps.newHashMap(); content1.put("file1", file1); content1.put("file2", file2); return new FixDir(content1); }
From source file:ddf.catalog.registry.transformer.RegistryTransformerTest.java
@Test(expected = CatalogTransformerException.class) public void testMetacardToXmlBadTag() throws Exception { String in = IOUtils.toString(getClass().getResourceAsStream("/csw-rim-node.xml")); Metacard m = rit.transform(IOUtils.toInputStream(in)); m.setAttribute(new AttributeImpl(Metacard.TAGS, "JustSomeMadeUpStuf")); String out = IOUtils.toString(rit.transform(m, null).getInputStream()); assertThat(in, is(out));/*w w w . j a va 2s . c o m*/ }
From source file:ddf.content.endpoint.rest.ContentEndpointCreateTest.java
/** * No filename or Content-Type specified by client, so ContentEndpoint sets the Content-Type * to text/plain (per CXF JAXRS default in Attachment.getContentType()) andgenerates default filename * of file.txt ("file" is default filename and ".txt" extension due to Content-Type of text/plain). * * @throws Exception/*from ww w . ja v a 2 s . c om*/ */ @Test public void testParseAttachmentNoFilenameOrContentTypeSpecified() throws Exception { InputStream is = IOUtils.toInputStream(TEST_JSON); MetadataMap<String, String> headers = new MetadataMap<String, String>(); headers.add(ContentEndpoint.CONTENT_DISPOSITION, "form-data; name=file"); Attachment attachment = new Attachment(is, headers); ContentFramework framework = mock(ContentFramework.class); ContentEndpoint endpoint = new ContentEndpoint(framework, getMockMimeTypeMapper()); CreateInfo createInfo = endpoint.parseAttachment(attachment); Assert.assertNotNull(createInfo); // Content-Type of text/plain is the default returned from CXF JAXRS Assert.assertEquals("text/plain", createInfo.getContentType()); Assert.assertEquals(ContentEndpoint.DEFAULT_FILE_NAME + ".txt", createInfo.getFilename()); }