Search in sources :

Example 1 with CapturerOutputStream

use of org.eclipse.sw360.fossology.ssh.FossologyUploader.CapturerOutputStream in project sw360portal by sw360.

the class FossologyUploaderFunctionalTest method testRealUpload.

@Ignore
@Test
public void testRealUpload() {
    doFirstConnectionAndTrust();
    String test = "this is the content\n";
    InputStream inputStream = new ByteArrayInputStream(test.getBytes());
    final CapturerOutputStream outputStream = new CapturerOutputStream();
    final String command = String.format(FossologyUploader.FOSSOLOGY_COMMAND_UPLOAD, "id", GROUP, "project");
    final int exitCode = fossologySshConnector.runInFossologyViaSsh(command, inputStream, outputStream);
    final long uploadId = FossologyUploader.parseResultUploadId(outputStream.getContent());
    System.out.println("uploaded as " + uploadId);
    assertThat("Send to fossology failed: " + outputStream.getContent(), exitCode, is(0));
    assertThat("bad uploadId received: " + outputStream.getContent(), uploadId, is(greaterThan(0L)));
    int i = 0;
    while (++i < 60) {
        ByteArrayOutputStream osget = new ByteArrayOutputStream();
        final String commandGet = String.format(FossologyUploader.FOSSOLOGY_COMMAND_GET_STATUS, uploadId, GROUP);
        final int exitCodeGet = fossologySshConnector.runInFossologyViaSsh(commandGet, osget);
        if (exitCodeGet != 0) {
            fail("check status script is broken");
            break;
        }
        final String outputget = new String(osget.toByteArray());
        final FossologyStatus status = fossologyUploader.parseResultStatus(outputget);
        System.out.println("status is " + status + ", try changing it from FOSSology");
        if (status.equals(FossologyStatus.CLOSED)) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            fail("interrupted");
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CapturerOutputStream(org.eclipse.sw360.fossology.ssh.FossologyUploader.CapturerOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) FossologyHostFingerPrint(org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with CapturerOutputStream

use of org.eclipse.sw360.fossology.ssh.FossologyUploader.CapturerOutputStream in project sw360portal by sw360.

the class FossologyUploaderFunctionalTest method testNotLosingBytes.

@Test
public void testNotLosingBytes() {
    RealSshConnectionUtils.assumeCanOpenSshSessions();
    final long count = 5000000L;
    CapturerOutputStream capturer = new CapturerOutputStream();
    InputStream inputStream = new RepeaterInputStream("\n", count);
    doFirstConnectionAndTrust();
    assertThat(fossologySshConnector.runInFossologyViaSsh("wc -l", inputStream, capturer), is(0));
    assertThat(capturer.getContent(), startsWith("" + count));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CapturerOutputStream(org.eclipse.sw360.fossology.ssh.FossologyUploader.CapturerOutputStream) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 CapturerOutputStream (org.eclipse.sw360.fossology.ssh.FossologyUploader.CapturerOutputStream)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)1 FossologyHostFingerPrint (org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint)1 Ignore (org.junit.Ignore)1