Search in sources :

Example 1 with ComponentService

use of org.eclipse.sw360.datahandler.thrift.components.ComponentService 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);
}
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 2 with ComponentService

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

the class FossologyFileHandlerTest method testSendToFossologyDuplicateDoesNotUpdateTheStatusOnErrors.

@Test
public void testSendToFossologyDuplicateDoesNotUpdateTheStatusOnErrors() 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);
    spyGetFilledSourceAttachment(filledAttachment);
    when(fossologyUploader.duplicateInFossology(41, clearingTeam)).thenReturn(false);
    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.FAILURE));
    verify(fossologyUploader).duplicateInFossology(41, clearingTeam);
    verify(fossologyFileHandler, never()).setFossologyStatus(eq(release), eq(clearingTeam), any(FossologyStatus.class));
    verify(fossologyUploader).getStatusInFossology(eq(41), eq(clearingTeam));
    verify(componentService, never()).updateReleaseFossology(release, user);
    verify(componentService).getReleaseById(releaseId, user);
    verifyNoMoreInteractions(attachmentConnector);
}
Also used : FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 3 with ComponentService

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

the class FossologyFileHandlerTest method testGetStatusInFossology.

@Test
public void testGetStatusInFossology() throws Exception {
    final String id1 = "41";
    final FilledAttachment filledAttachment = getMockFilledAttachment(id1);
    final Release release = mock(Release.class);
    final Release updated = mock(Release.class);
    when(componentService.getReleaseById(releaseId, user)).thenReturn(release, updated);
    spyGetFilledSourceAttachment(filledAttachment);
    int fossologyId = 14;
    when(release.isSetFossologyId()).thenReturn(true);
    when(release.getFossologyId()).thenReturn("" + fossologyId);
    String clearingTeam2 = "anotherClearingTeam";
    when(fossologyUploader.getStatusInFossology(eq(fossologyId), eq(clearingTeam))).thenReturn(FossologyStatus.IN_PROGRESS);
    when(fossologyUploader.getStatusInFossology(eq(fossologyId), eq(clearingTeam2))).thenReturn(FossologyStatus.OPEN);
    doNothing().when(fossologyFileHandler).setFossologyStatus(eq(release), eq(clearingTeam), eq(FossologyStatus.IN_PROGRESS), eq("" + fossologyId), eq(id1));
    doReturn(ImmutableList.of(clearingTeam, clearingTeam2)).when(fossologyFileHandler).getAllClearingTeams(release, clearingTeam);
    final Release resultRelease = fossologyFileHandler.getStatusInFossology(releaseId, user, clearingTeam);
    assertThat(resultRelease, is(sameInstance(release)));
    verify(fossologyFileHandler).setFossologyStatus(release, clearingTeam, FossologyStatus.IN_PROGRESS);
    verify(fossologyFileHandler).setFossologyStatus(release, clearingTeam2, FossologyStatus.OPEN);
    verify(fossologyUploader).getStatusInFossology(fossologyId, clearingTeam);
    verify(fossologyUploader).getStatusInFossology(fossologyId, clearingTeam2);
    verify(componentService, atLeastOnce()).getReleaseById(releaseId, user);
    verify(componentService).updateReleaseFossology(release, user);
}
Also used : FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 4 with ComponentService

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

the class FossologyFileHandlerTest method testGetStatusInFossologyDoesNotUpdateInDatabaseOnConnectionFailures.

@Test
public void testGetStatusInFossologyDoesNotUpdateInDatabaseOnConnectionFailures() throws Exception {
    final String id1 = "41";
    final FilledAttachment filledAttachment = getMockFilledAttachment(id1);
    final Release release = mock(Release.class);
    when(componentService.getReleaseById(releaseId, user)).thenReturn(release);
    spyGetFilledSourceAttachment(filledAttachment);
    int fossologyId = 14;
    when(release.isSetFossologyId()).thenReturn(true);
    when(release.getFossologyId()).thenReturn("" + fossologyId);
    String clearingTeam2 = "anotherClearingTeam";
    when(fossologyUploader.getStatusInFossology(eq(fossologyId), eq(clearingTeam))).thenReturn(FossologyStatus.IN_PROGRESS);
    when(fossologyUploader.getStatusInFossology(eq(fossologyId), eq(clearingTeam2))).thenReturn(FossologyStatus.CONNECTION_FAILED);
    doNothing().when(fossologyFileHandler).setFossologyStatus(eq(release), eq(clearingTeam), eq(FossologyStatus.IN_PROGRESS), eq("" + fossologyId), eq(id1));
    doReturn(ImmutableList.of(clearingTeam, clearingTeam2)).when(fossologyFileHandler).getAllClearingTeams(release, clearingTeam);
    final Release resultRelease = fossologyFileHandler.getStatusInFossology(releaseId, user, clearingTeam);
    assertThat(resultRelease, is(sameInstance(release)));
    verify(fossologyFileHandler).setFossologyStatus(release, clearingTeam, FossologyStatus.IN_PROGRESS);
    verify(fossologyFileHandler).setFossologyStatus(release, clearingTeam2, FossologyStatus.CONNECTION_FAILED);
    verify(fossologyUploader).getStatusInFossology(fossologyId, clearingTeam);
    verify(fossologyUploader).getStatusInFossology(fossologyId, clearingTeam2);
    verify(componentService, atLeastOnce()).getReleaseById(releaseId, user);
    verify(componentService, never()).updateReleaseFossology(release, user);
}
Also used : FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 5 with ComponentService

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

the class FossologyFileHandlerTest method testNotUnlockingForNoClearing.

@Test
public void testNotUnlockingForNoClearing() throws Exception {
    Release release = mock(Release.class);
    doReturn(null).when(fossologyFileHandler).updateRelease(release, user, componentService);
    doReturn(release).when(componentService).getReleaseById(releaseId, user);
    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)

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