use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class CLIParserTest method testIsApplicableToFailsOnMalformedXML.
@Test
public void testIsApplicableToFailsOnMalformedXML() 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("this is not an xml file")));
assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class FossologyFileHandlerTest method testAFailedSendToFossology.
@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();
// unimportant verifies
verify(componentService, atLeastOnce()).getReleaseById(releaseId, user);
verify(attachmentConnector).getAttachmentStream(attachmentContent, user, release);
verify(fossologyUploader).uploadToFossology(inputStream, attachmentContent, clearingTeam);
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent 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.AttachmentContent 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.AttachmentContent 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;
}
}
Aggregations