FossologyFileHandler { public RequestStatus sendToFossology(String releaseId, User user, String clearingTeam) throws TException { Release release; final ComponentService.Iface componentClient = thriftClients.makeComponentClient(); release = getReleaseAndUnlockIt(releaseId, user, componentClient); Set<Attachment> sourceAttachments = getSourceAttachment(releaseId, user, componentClient); if (sourceAttachments.size() != 1) { log.error("release " + releaseId + " does not have a single source attachment"); return RequestStatus.FAILURE; } final Attachment attachment = getFirst(sourceAttachments); final FilledAttachment filledAttachment = fillAttachment(attachment); if (!release.isSetFossologyId()) { AttachmentContent attachmentContent = filledAttachment.getAttachmentContent(); return sendToFossologyNewUpload(release, user, clearingTeam, attachmentContent, componentClient); } else { if (!checkSourceAttachment(release, filledAttachment)) { return RequestStatus.FAILURE; } else { return sendToFossologyExistingUpload(release, user, clearingTeam, componentClient); } } } @Autowired  FossologyFileHandler(AttachmentConnector attachmentConnector, FossologyUploader fossologyUploader, ThriftClients thriftClients); RequestStatus sendToFossology(String releaseId, User user, String clearingTeam); Release getStatusInFossology(String releaseId, User user, String clearingTeam);  }
@Test public void testSendToFossologyWithNotExistentReleaseIsError() throws Exception { try { assertThat(fossologyFileHandler.sendToFossology(releaseId, user, clearingTeam), is(RequestStatus.FAILURE)); } catch (SW360Exception e) { assertThat(e, instanceOf(SW360Exception.class)); } verify(componentService).getReleaseById(releaseId, user); }
@Test public void testSendToFossologyWithNoSourcesIsSuccess() throws Exception { final Release release = mock(Release.class); when(componentService.getReleaseById(releaseId, user)).thenReturn(release); assertThat(fossologyFileHandler.sendToFossology(releaseId, user, clearingTeam), is(RequestStatus.FAILURE)); verify(componentService).getReleaseById(releaseId, user); verify(componentService).getSourceAttachments(releaseId); }
@Test public void testAFailedSendToFossology() throws Exception { final String id = "41"; final FilledAttachment filledAttachment = getMockFilledAttachment(id); final AttachmentContent attachmentContent = filledAttachment.getAttachmentContent(); final Release release = mock(Release.class); when(componentService.getReleaseById(releaseId, user)).thenReturn(release); spyGetFilledSourceAttachment(filledAttachment); final InputStream inputStream = mock(InputStream.class); when(release.isSetFossologyId()).thenReturn(false); when(attachmentConnector.getAttachmentStream(attachmentContent, user, release)).thenReturn(inputStream); when(fossologyUploader.uploadToFossology(inputStream, attachmentContent, clearingTeam)).thenReturn(-1); assertThat(fossologyFileHandler.sendToFossology(releaseId, user, clearingTeam), is(RequestStatus.FAILURE)); verify(inputStream).close(); verify(componentService, atLeastOnce()).getReleaseById(releaseId, user); verify(attachmentConnector).getAttachmentStream(attachmentContent, user, release); verify(fossologyUploader).uploadToFossology(inputStream, attachmentContent, clearingTeam); }