private String getDescriptorContent(File jsonFile) { try (InputStream stream = new FileInputStream(jsonFile)) { return IOUtils.toString(stream); } catch (IOException e) { throw new IllegalArgumentException(format("Could not read extension describer on artifact '%s'", jsonFile.getAbsolutePath()), e); } }
@Override public MessageDispatcher connect() throws ConnectionException { return request -> { try { URL resource = Thread.currentThread().getContextClassLoader().getResource("test-http-response.xml"); String response = String.format(IOUtils.toString(resource.openStream()), getResponseWord()); return new DispatchingResponse(new ByteArrayInputStream(response.getBytes()), singletonMap("Content-Type", "text/xml")); } catch (Exception e) { throw new RuntimeException("Something went wrong when getting fake test response", e); } }; }
MulePluginBasedLoaderFinder(InputStream json) { try { this.mulePlugin = mulePluginSerializer.deserialize(IOUtils.toString(json)); } finally { closeQuietly(json); } }
@OnError public void onError(@InputJsonType(schema = "person-schema.json") InputStream person, SourceCallbackContext cc) { onErrorResult = IOUtils.toString(person); }
@Test public void testReadRootFile() throws IOException { String rootResource = "root-resource.txt"; URL url = getURL(rootResource); InputStream actualInputStream = url.openStream(); assertThat(actualInputStream, notNullValue()); String expectedRootResourceContent = org.apache.commons.io.IOUtils.toString(getClass().getClassLoader() .getResource(new File(MULE_MODULE_ARTIFACT_PLUGIN + separator + rootResource).getPath())); assertThat(IOUtils.toString(actualInputStream), is(expectedRootResourceContent)); }
@Test public void convertsToStringWithEncoding() throws Exception { final Charset encoding = forName("EUC-JP"); final String encodedText = "\u3053"; InputStream in = new ByteArrayInputStream(encodedText.getBytes(encoding)); String converted = IOUtils.toString(in, encoding); assertThat(converted, equalTo(encodedText)); } }
@Test public void testReadElementWithinJar() throws IOException { String file = "lib" + File.separator + "test-jar-with-resources.jar" + SEPARATOR + "test-resource-2.txt"; URL url = getURL(file); InputStream actualInputStream = url.openStream(); assertThat(actualInputStream, notNullValue()); assertThat(IOUtils.toString(actualInputStream), is("Just some text")); }
public List<String> getPets(@Connection PetStoreClient client, @Config PetStoreConnector config, String ownerName, @Optional InputStream ownerSignature) { if (ownerSignature != null) { ownerName += IOUtils.toString(ownerSignature); } return client.getPets(ownerName, config); }
@Test public void testClassloaderWithMulePluginUrls() throws IOException { URL jarURL = getURL("lib" + File.separator + "test-jar-with-resources.jar" + SEPARATOR); URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {jarURL}); // looking for resource that's located in the jarURL (zip within zip scenario) InputStream testResourceWithinZipInputStream = urlClassLoader.getResourceAsStream("test-resource-2.txt"); assertThat(testResourceWithinZipInputStream, notNullValue()); assertThat(IOUtils.toString(testResourceWithinZipInputStream), is("Just some text")); }
private void assertConsumedRepeatableInputStream(CursorStreamProvider payload, TypedValue value) { Object responsePayload = value.getValue(); assertThat(responsePayload, is(not(sameInstance(payload)))); assertThat(responsePayload, is(instanceOf(ByteArrayCursorStreamProvider.class))); assertThat(IOUtils.toString((CursorStreamProvider) responsePayload), equalTo(TEST_PAYLOAD)); }
@Test public void generate() throws Exception { GeneratedResource resource = resourceFactory.generateResource(extensionModel).get(); assertThat(resource.getPath(), equalTo(RESOURCE_NAME)); XMLUnit.setIgnoreWhitespace(true); String expected = IOUtils.toString(currentThread().getContextClassLoader().getResource(RESOURCE_NAME).openStream()); XMLUnit.compareXML(expected, new String(resource.getContent())); } }
@Test public void handleNullEvent() throws MuleException { TypedValue evaluate = muleContext.getExpressionManager().evaluate("%dw 2.0\noutput application/json\n---\n{a: 1}"); ByteArrayBasedCursorStreamProvider value = (ByteArrayBasedCursorStreamProvider) evaluate.getValue(); String expected = "{\n" + " \"a\": 1\n" + "}"; assertThat(IOUtils.toString(value), is(expected)); } }
@Test public void decodeWithoutUnzipping() throws Exception { final String payload = RandomStringUtils.randomAlphabetic(1024); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(payload.getBytes()); GZIPCompressorInputStream gzipCompressorInputStream = new GZIPCompressorInputStream(byteArrayInputStream); String encoded = Base64.encodeBytes(IOUtils.toByteArray(gzipCompressorInputStream), Base64.DONT_BREAK_LINES); GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(Base64.decodeWithoutUnzipping(encoded))); assertThat(IOUtils.toString(gzipInputStream), is(payload)); } }
private Object evaluateHeaders(InputStream headers) { String hs = IOUtils.toString(headers); BindingContext context = BindingContext.builder().addBinding("payload", new TypedValue<>(hs, DataType.XML_STRING)).build(); return expressionExecutor.evaluate("%dw 2.0 \n" + "output application/java \n" + "---\n" + "payload.headers mapObject (value, key) -> {\n" + " '$key' : write((key): value, \"application/xml\")\n" + "}", context).getValue(); }
@Test public void testSetPayloadHardcodedFileProperty() throws Exception { CoreEvent muleEvent = flowRunner("testSetPayloadHardcodedFileProperty").run(); final String expectedContent = IOUtils.toString(currentThread().getContextClassLoader().getResourceAsStream("modules/module-properties-file.txt")) .trim(); assertThat(muleEvent.getMessage().getPayload().getValue(), is( expectedContent)); } }
@Test public void persistDocumentation() throws Exception { InputStream in = getClass().getResourceAsStream(expectedProductPath); assertThat(in, is(notNullValue())); String expectedXml = IOUtils.toString(in); TestProcessor processor = new TestProcessor(extensionClass); doCompile(processor); ExtensionDocumentationResourceGenerator generator = new ExtensionDocumentationResourceGenerator(); GeneratedResource resource = generator.generateResource(processor.getExtensionModel()) .orElseThrow(() -> new RuntimeException("No Documentation Generated")); compareXML(expectedXml, new String(resource.getContent())); }
@Test public void getJavaObjectFromStringJsonProperty() throws MuleException { AttributeEvaluator attributeEvaluator = getAttributeEvaluator("#[payload.host]", OBJECT); CoreEvent event = newEvent(HOST_PORT_JSON, APPLICATION_JSON); Object resolveValue = attributeEvaluator.resolveValue(event); assertThat(IOUtils.toString((InputStream) ((CursorProvider) resolveValue).openCursor()), is("\"0.0.0.0\"")); }
@Test public void typedValueForInputStream() throws Exception { CoreEvent event = flowRunner("typedValueForInputStream").run(); TypedValue jsonObject = (TypedValue) event.getMessage().getPayload().getValue(); assertThat(IOUtils.toString((InputStream) jsonObject.getValue()), is(JSON_OBJECT)); assertThat(jsonObject.getDataType(), is(like(jsonObject.getDataType().getType(), APPLICATION_JSON, UTF8))); }
@Test public void xmlOutput() throws Exception { Object payload = flowRunner("output").keepStreamsOpen().run().getMessage().getPayload().getValue(); assertThat(IOUtils.toString(((CursorStreamProvider) payload).openCursor()), is(XML_VALUE)); }
@Test public void jsonOutput() throws Exception { Object payload = flowRunner("jsonOutput").keepStreamsOpen().run().getMessage().getPayload().getValue(); assertEqualJsons(IOUtils.toString(((CursorStreamProvider) payload).openCursor()), JSON_VALUE); }