use of org.apache.commons.io.input.ReaderInputStream in project sw360portal by sw360.
the class CLIParserTest method testGetCLI.
@Test
public void testGetCLI() throws Exception {
Attachment cliAttachment = new Attachment("A1", "a.xml");
when(connector.getAttachmentStream(anyObject(), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(CLI_TESTFILE)));
LicenseInfoParsingResult res = parser.getLicenseInfos(cliAttachment, new User(), new Project()).stream().findFirst().orElseThrow(() -> new RuntimeException("Parser returned empty LisenceInfoParsingResult list"));
assertLicenseInfoParsingResult(res);
assertThat(res.getStatus(), is(LicenseInfoRequestStatus.SUCCESS));
assertThat(res.getLicenseInfo(), notNullValue());
assertThat(res.getLicenseInfo().getFilenames(), contains("a.xml"));
assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().size(), is(1));
assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().stream().map(LicenseNameWithText::getLicenseText).collect(Collectors.toSet()), containsInAnyOrder("jQuery projects are released under the terms of the MIT license."));
assertThat(res.getLicenseInfo().getCopyrights().size(), is(2));
assertThat(res.getLicenseInfo().getCopyrights(), containsInAnyOrder("Copyrights", "(c) jQuery Foundation, Inc. | jquery.org"));
}
use of org.apache.commons.io.input.ReaderInputStream in project sw360portal by sw360.
the class CLIParserTest method testIsApplicableToFailsOnIncorrectRootElement.
@Test
public void testIsApplicableToFailsOnIncorrectRootElement() throws Exception {
AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader("<wrong-root/>")));
assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
use of org.apache.commons.io.input.ReaderInputStream in project sw360portal by sw360.
the class CLIParserTest method testGetCLIFailsOnMalformedXML.
@Test
public void testGetCLIFailsOnMalformedXML() throws Exception {
Attachment cliAttachment = new Attachment("A1", "a.xml");
when(connector.getAttachmentStream(anyObject(), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(CLI_TESTFILE.replaceAll("</Content>", "</Broken>"))));
LicenseInfoParsingResult res = parser.getLicenseInfos(cliAttachment, new User(), new Project()).stream().findFirst().orElseThrow(() -> new RuntimeException("Parser returned empty LisenceInfoParsingResult list"));
assertLicenseInfoParsingResult(res, LicenseInfoRequestStatus.FAILURE);
assertThat(res.getStatus(), is(LicenseInfoRequestStatus.FAILURE));
assertThat(res.getLicenseInfo(), notNullValue());
assertThat(res.getLicenseInfo().getFilenames(), contains("a.xml"));
}
use of org.apache.commons.io.input.ReaderInputStream in project cas by apereo.
the class ResourceUtils method buildInputStreamResourceFrom.
/**
* Build input stream resource from string value.
*
* @param value the value
* @param description the description
* @return the input stream resource
*/
public static InputStreamResource buildInputStreamResourceFrom(final String value, final String description) {
val reader = new StringReader(value);
val is = new ReaderInputStream(reader, StandardCharsets.UTF_8);
return new InputStreamResource(is, description);
}
use of org.apache.commons.io.input.ReaderInputStream in project wso2-axis2-transports by wso2.
the class TextMessageBuilderAdapter method processDocument.
public OMElement processDocument(Reader reader, String contentType, MessageContext messageContext) throws AxisFault {
String charset;
try {
ContentType ct = new ContentType(contentType);
charset = ct.getParameter("charset");
} catch (ParseException ex) {
charset = null;
}
if (charset == null) {
charset = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
messageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charset);
return processDocument(new ReaderInputStream(reader, charset), contentType, messageContext);
}
Aggregations