FossologyUploader { public boolean copyToFossology(String filename, InputStream content, boolean execBit) throws SW360Exception { final String quotedFileName = sanitizeQuotes(filename); String copyCmd = String.format(COPY_STDIN_CMD, quotedFileName); if (execBit) { copyCmd += " && " + String.format(CHMOD_EXEC_CMD, quotedFileName); } return fossologySshConnector.runInFossologyViaSsh(copyCmd, content) == 0; } @Autowired  FossologyUploader(FossologySshConnector fossologySshConnector); int uploadToFossology(InputStream inputStream, AttachmentContent attachment, String clearingTeam); boolean duplicateInFossology(int uploadId, String clearingTeam); FossologyStatus getStatusInFossology(int uploadId, String clearingTeam); boolean copyToFossology(String filename, InputStream content, boolean execBit);  }
@Test public void testCopyToFossology() throws Exception { when(sshConnector.runInFossologyViaSsh(anyString(), any(InputStream.class))).thenReturn(0); final InputStream content = mock(InputStream.class); boolean success = fossologyUploader.copyToFossology("filename", content, false); assertThat(success, is(true)); verify(sshConnector).runInFossologyViaSsh(eq("cat > 'filename'"), eq(content)); }
@Test public void testCopyToFossologyExecutable() throws Exception { when(sshConnector.runInFossologyViaSsh(anyString(), any(InputStream.class))).thenReturn(0); final InputStream content = mock(InputStream.class); boolean success = fossologyUploader.copyToFossology("filename", content, true); assertThat(success, is(true)); verify(sshConnector).runInFossologyViaSsh(eq("cat > 'filename' && chmod u+x 'filename'"), eq(content)); }
@Test public void testCopyToFossologyReportsFailure() throws Exception { when(sshConnector.runInFossologyViaSsh(anyString(), any(InputStream.class))).thenReturn(1); final InputStream content = mock(InputStream.class); boolean success = fossologyUploader.copyToFossology("filename", content, false); assertThat(success, is(false)); verify(sshConnector).runInFossologyViaSsh(eq("cat > 'filename'"), eq(content)); }