use of org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment in project sw360portal by sw360.
the class FossologyFileHandlerTest method testSendToFossologySendsAnAttachment.
@Test
public void testSendToFossologySendsAnAttachment() 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(release.getClearingState()).thenReturn(ClearingState.NEW_CLEARING);
when(attachmentConnector.getAttachmentStream(attachmentContent, user, release)).thenReturn(inputStream);
when(fossologyUploader.uploadToFossology(inputStream, attachmentContent, clearingTeam)).thenReturn(1);
doNothing().when(fossologyFileHandler).setFossologyStatus(eq(release), anyString(), eq(FossologyStatus.SENT), eq("" + 1), eq(id));
doReturn(true).when(fossologyFileHandler).checkSourceAttachment(release, filledAttachment);
assertThat(fossologyFileHandler.sendToFossology(releaseId, user, clearingTeam), is(RequestStatus.SUCCESS));
verify(inputStream).close();
// the release should be updated
verify(componentService).updateReleaseFossology(release, user);
verify(fossologyFileHandler).setFossologyStatus(eq(release), anyString(), eq(FossologyStatus.SENT), eq("" + 1), eq(id));
// unimportant verifies
verify(componentService, times(1)).getReleaseById(releaseId, user);
verify(attachmentConnector).getAttachmentStream(attachmentContent, user, release);
verify(fossologyUploader).uploadToFossology(inputStream, attachmentContent, clearingTeam);
}
use of org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment in project sw360portal by sw360.
the class FossologyFileHandler method sendToFossology.
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");
// TODO return a summary and better fitting status
return RequestStatus.FAILURE;
}
final Attachment attachment = getFirst(sourceAttachments);
final FilledAttachment filledAttachment = fillAttachment(attachment);
if (!release.isSetFossologyId()) {
/* send the attachment as a new upload */
AttachmentContent attachmentContent = filledAttachment.getAttachmentContent();
return sendToFossologyNewUpload(release, user, clearingTeam, attachmentContent, componentClient);
} else {
if (!checkSourceAttachment(release, filledAttachment)) {
// TODO summary
return RequestStatus.FAILURE;
} else {
/* duplicate the old upload making it visible for clearingTeam */
return sendToFossologyExistingUpload(release, user, clearingTeam, componentClient);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment in project sw360portal by sw360.
the class FossologyFileHandler method fillAttachment.
protected FilledAttachment fillAttachment(Attachment attachment) throws SW360Exception {
String attachmentContentId = attachment.getAttachmentContentId();
try {
AttachmentContent attachmentContent = attachmentConnector.getAttachmentContent(attachmentContentId);
assertNotNull(attachmentContent);
return new FilledAttachment().setAttachment(attachment).setAttachmentContent(attachmentContent);
} catch (SW360Exception e) {
log.error("cannot retrieve attachment " + attachmentContentId, e);
throw e;
}
}
use of org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment in project sw360portal by sw360.
the class FossologyFileHandlerTest method testSendToFossologyDuplicates.
@Test
public void testSendToFossologyDuplicates() throws Exception {
final FilledAttachment filledAttachment = getMockFilledAttachment("17");
final Release release = mock(Release.class);
when(componentService.getReleaseById(releaseId, user)).thenReturn(release);
when(release.getFossologyId()).thenReturn("41");
when(release.isSetFossologyId()).thenReturn(true);
when(release.getClearingState()).thenReturn(ClearingState.SENT_TO_FOSSOLOGY);
spyGetFilledSourceAttachment(filledAttachment);
when(fossologyUploader.duplicateInFossology(41, clearingTeam)).thenReturn(true);
doNothing().when(fossologyFileHandler).setFossologyStatus(eq(release), anyString(), any(FossologyStatus.class));
doReturn(true).when(fossologyFileHandler).checkSourceAttachment(release, filledAttachment);
assertThat(fossologyFileHandler.sendToFossology(releaseId, user, clearingTeam), is(RequestStatus.SUCCESS));
verify(fossologyUploader).duplicateInFossology(41, clearingTeam);
verify(fossologyUploader).getStatusInFossology(eq(41), eq(clearingTeam));
verify(fossologyFileHandler).setFossologyStatus(eq(release), eq(clearingTeam), eq(FossologyStatus.SENT));
verify(componentService).updateReleaseFossology(release, user);
verify(componentService, atLeastOnce()).getReleaseById(releaseId, user);
verifyNoMoreInteractions(attachmentConnector);
}
use of org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment in project sw360portal by sw360.
the class FossologyFileHandlerTest method getMockFilledAttachment.
private static FilledAttachment getMockFilledAttachment(String attachmentContentId) {
final FilledAttachment filledAttachment = mock(FilledAttachment.class);
final Attachment attachment = mock(Attachment.class);
when(filledAttachment.getAttachment()).thenReturn(attachment);
final AttachmentContent attachmentContent = mock(AttachmentContent.class);
when(filledAttachment.getAttachmentContent()).thenReturn(attachmentContent);
when(attachment.getAttachmentContentId()).thenReturn(attachmentContentId);
when(attachmentContent.getId()).thenReturn(attachmentContentId);
return filledAttachment;
}
Aggregations