Search in sources :

Example 16 with ReaderInputStream

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"));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) User(org.eclipse.sw360.datahandler.thrift.users.User) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) StringReader(java.io.StringReader) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) TestHelper.assertLicenseInfoParsingResult(org.eclipse.sw360.licenseinfo.TestHelper.assertLicenseInfoParsingResult) Test(org.junit.Test)

Example 17 with ReaderInputStream

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()));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) User(org.eclipse.sw360.datahandler.thrift.users.User) StringReader(java.io.StringReader) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Test(org.junit.Test)

Example 18 with ReaderInputStream

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"));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) User(org.eclipse.sw360.datahandler.thrift.users.User) StringReader(java.io.StringReader) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) TestHelper.assertLicenseInfoParsingResult(org.eclipse.sw360.licenseinfo.TestHelper.assertLicenseInfoParsingResult) Test(org.junit.Test)

Example 19 with ReaderInputStream

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);
}
Also used : lombok.val(lombok.val) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) StringReader(java.io.StringReader) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 20 with ReaderInputStream

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);
}
Also used : ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) ContentType(javax.mail.internet.ContentType) ParseException(javax.mail.internet.ParseException)

Aggregations

ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)25 StringReader (java.io.StringReader)16 Test (org.junit.Test)15 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)8 User (org.eclipse.sw360.datahandler.thrift.users.User)8 InputStream (java.io.InputStream)7 FileInputStream (java.io.FileInputStream)4 InputStreamReader (java.io.InputStreamReader)4 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 HttpEntity (org.apache.http.HttpEntity)3 StatusLine (org.apache.http.StatusLine)3 HttpGet (org.apache.http.client.methods.HttpGet)3 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)3 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)3 TestHelper.assertLicenseInfoParsingResult (org.eclipse.sw360.licenseinfo.TestHelper.assertLicenseInfoParsingResult)3 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)2 WebApplicationConfiguration (com.evolveum.midpoint.web.security.WebApplicationConfiguration)2