Search in sources :

Example 6 with ComponentService

use of org.eclipse.sw360.datahandler.thrift.components.ComponentService in project sw360portal by sw360.

the class FossologyFileHandlerTest method testSendToFossologyWithNoSourcesIsSuccess.

@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);
}
Also used : Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 7 with ComponentService

use of org.eclipse.sw360.datahandler.thrift.components.ComponentService in project sw360portal by sw360.

the class FossologyFileHandlerTest method spyGetFilledSourceAttachment.

private void spyGetFilledSourceAttachment(FilledAttachment filledAttachment) throws TException {
    final Attachment attachment = filledAttachment.getAttachment();
    doReturn(ImmutableSet.of(attachment)).when(fossologyFileHandler).getSourceAttachment(releaseId, user, componentService);
    doReturn(filledAttachment).when(fossologyFileHandler).fillAttachment(attachment);
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)

Example 8 with ComponentService

use of org.eclipse.sw360.datahandler.thrift.components.ComponentService in project sw360portal by sw360.

the class FossologyFileHandlerTest method testNotUnlockingIfATeamIsWorkingOnIt.

@Test
public void testNotUnlockingIfATeamIsWorkingOnIt() throws Exception {
    Release release = mock(Release.class);
    doReturn(null).when(fossologyFileHandler).updateRelease(release, user, componentService);
    doReturn(release).when(componentService).getReleaseById(releaseId, user);
    when(release.getClearingTeamToFossologyStatus()).thenReturn(ImmutableMap.of("a", FossologyStatus.OPEN, "b", FossologyStatus.REJECTED));
    fossologyFileHandler.getReleaseAndUnlockIt(releaseId, user, componentService);
    verify(fossologyFileHandler, never()).updateRelease(release, user, componentService);
    verify(componentService).getReleaseById(releaseId, user);
    verify(release).getClearingTeamToFossologyStatus();
    verifyNoMoreInteractions(release);
}
Also used : Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 9 with ComponentService

use of org.eclipse.sw360.datahandler.thrift.components.ComponentService 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);
}
Also used : InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 10 with ComponentService

use of org.eclipse.sw360.datahandler.thrift.components.ComponentService in project sw360portal by sw360.

the class FossologyFileHandlerTest method setUp.

@Before
public void setUp() throws TException {
    ThriftClients thriftClients = TestUtils.failingMock(ThriftClients.class);
    doReturn(componentService).when(thriftClients).makeComponentClient();
    user = TestUtils.getAdminUser(getClass());
    fossologyFileHandler = spy(new FossologyFileHandler(attachmentConnector, fossologyUploader, thriftClients));
}
Also used : ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients) Before(org.junit.Before)

Aggregations

Release (org.eclipse.sw360.datahandler.thrift.components.Release)10 Test (org.junit.Test)10 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)7 InputStream (java.io.InputStream)2 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)2 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)2 ThriftClients (org.eclipse.sw360.datahandler.thrift.ThriftClients)1 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)1 Before (org.junit.Before)1