Search in sources :

Example 6 with FossologyStatus

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

the class ReleaseClearingStateSummaryComputer method computeReleaseClearingStateSummary.

public static ReleaseClearingStateSummary computeReleaseClearingStateSummary(List<Release> releases, String clearingTeam) {
    ReleaseClearingStateSummary summary = new ReleaseClearingStateSummary(0, 0, 0, 0, 0);
    if (releases == null) {
        return summary;
    }
    for (Release release : releases) {
        Map<String, FossologyStatus> fossologyStatuses = nullToEmptyMap(release.getClearingTeamToFossologyStatus());
        ViewedState globalState = getGlobalState(release.getClearingState());
        ViewedState myTeamState = getStateOfFossology(fossologyStatuses.get(clearingTeam));
        ViewedState otherTeamState = getBestStateOfFossologyForOtherTeams(clearingTeam, fossologyStatuses);
        addReleaseWithStates(summary, globalState, myTeamState, otherTeamState);
    }
    return summary;
}
Also used : FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Release(org.eclipse.sw360.datahandler.thrift.components.Release) ReleaseClearingStateSummary(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStateSummary)

Example 7 with FossologyStatus

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

the class FossologyUploaderTest method testParseResult.

@Test
public void testParseResult() {
    final FossologyStatus fossologyStatus = FossologyStatus.CLOSED;
    assertThat(fossologyUploader.parseResultStatus("status=" + fossologyStatus), is(fossologyStatus));
}
Also used : FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Test(org.junit.Test)

Example 8 with FossologyStatus

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

the class FossologyUploaderTest method testGetStatusInFossology.

@Test
public void testGetStatusInFossology() throws Exception {
    int uploadId = 42;
    fossologyUploader = spy(fossologyUploader);
    String clearingTeam = "team d";
    final String output = "output result\nfrom the get status script";
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final OutputStream os = (OutputStream) invocation.getArguments()[1];
            os.write(output.getBytes());
            return 0;
        }
    }).when(sshConnector).runInFossologyViaSsh(anyString(), any(OutputStream.class));
    FossologyStatus parseResult = FossologyStatus.IN_PROGRESS;
    doReturn(parseResult).when(fossologyUploader).parseResultStatus(output);
    FossologyStatus statusInFossology = fossologyUploader.getStatusInFossology(uploadId, clearingTeam);
    assertThat(statusInFossology, is(parseResult));
    verify(fossologyUploader).parseResultStatus(output);
    verify(sshConnector).runInFossologyViaSsh(anyString(), any(OutputStream.class));
    verify(fossologyUploader).getStatusInFossology(uploadId, clearingTeam);
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OutputStream(java.io.OutputStream) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Test(org.junit.Test)

Example 9 with FossologyStatus

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

the class FossologyFileHandlerTest method testUpdateFossologyStatusForTheFirstTimeCreatesTheStatusMap.

@Test
public void testUpdateFossologyStatusForTheFirstTimeCreatesTheStatusMap() {
    Release release = mock(Release.class);
    fossologyFileHandler.setFossologyStatus(release, clearingTeam, FossologyStatus.SCANNING, "13", "14");
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            try {
                @SuppressWarnings("unchecked") Map<String, FossologyStatus> statusMap = (Map<String, FossologyStatus>) invocation.getArguments()[0];
                assertThat(statusMap, hasEntry(clearingTeam, FossologyStatus.SCANNING));
                assertThat(statusMap.keySet(), containsInAnyOrder(clearingTeam));
            } catch (ClassCastException e) {
                fail("status was supposed to be a map :-/" + e.getMessage());
            }
            return null;
        }
    }).when(release).setClearingTeamToFossologyStatus(anyMapOf(String.class, FossologyStatus.class));
    verify(release).setClearingTeamToFossologyStatus(anyMapOf(String.class, FossologyStatus.class));
    verify(release).setFossologyId("13");
    verify(release).setAttachmentInFossology("14");
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 10 with FossologyStatus

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

the class FossologyFileHandlerTest method testUpdateFossologyStatusAddTheNewStatus.

@Test
public void testUpdateFossologyStatusAddTheNewStatus() {
    Release release = mock(Release.class);
    final String clearingTeam2 = "team2";
    final Map<String, FossologyStatus> existingStatuses = newHashMap();
    existingStatuses.put(clearingTeam, FossologyStatus.SENT);
    existingStatuses.put(clearingTeam2, FossologyStatus.CLOSED);
    when(release.getClearingTeamToFossologyStatus()).thenReturn(existingStatuses);
    fossologyFileHandler.setFossologyStatus(release, clearingTeam, FossologyStatus.SCANNING);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            try {
                @SuppressWarnings("unchecked") Map<String, FossologyStatus> statusMap = (Map<String, FossologyStatus>) invocation.getArguments()[0];
                assertThat(statusMap, hasEntry(clearingTeam, FossologyStatus.SCANNING));
                assertThat(statusMap, hasEntry(clearingTeam2, FossologyStatus.CLOSED));
                assertThat(statusMap.keySet(), containsInAnyOrder(clearingTeam, clearingTeam2));
            } catch (ClassCastException e) {
                fail("status was supposed to be a map :-/" + e.getMessage());
            }
            return null;
        }
    }).when(release).setClearingTeamToFossologyStatus(anyMapOf(String.class, FossologyStatus.class));
    verify(release).setClearingTeamToFossologyStatus(anyMapOf(String.class, FossologyStatus.class));
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Aggregations

FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)14 Release (org.eclipse.sw360.datahandler.thrift.components.Release)8 Test (org.junit.Test)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 OutputStream (java.io.OutputStream)2 Map (java.util.Map)2 TEnumToString (org.eclipse.sw360.datahandler.TEnumToString)2 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 TException (org.apache.thrift.TException)1 CommonUtils.nullToEmptyMap (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap)1