FileLogDelegator extends BaseDelegator implements IFileLogDelegator { @Override public Map<IFileSpec, List<IFileRevisionData>> getRevisionHistory( final List<IFileSpec> fileSpecs, final int maxRevs, final boolean contentHistory, final boolean includeInherited, final boolean longOutput, final boolean truncatedLongOutput) throws ConnectionException, AccessException { try { GetRevisionHistoryOptions revisionHistoryOptions = new GetRevisionHistoryOptions() .setContentHistory(contentHistory) .setIncludeInherited(includeInherited) .setLongOutput(longOutput) .setTruncatedLongOutput(truncatedLongOutput) .setMaxRevs(maxRevs); return getRevisionHistory(fileSpecs, revisionHistoryOptions); } catch (final ConnectionException | AccessException exc) { throw exc; } catch (P4JavaException exc) { Log.warn("Unexpected exception in IServer.getRevisionHistory: %s", exc.getLocalizedMessage()); return Collections.emptyMap(); } } FileLogDelegator(IOptionsServer server); @Override Map<IFileSpec, List<IFileRevisionData>> getRevisionHistory(
            final List<IFileSpec> fileSpecs,
            final int maxRevs,
            final boolean contentHistory,
            final boolean includeInherited,
            final boolean longOutput,
            final boolean truncatedLongOutput); @Override Map<IFileSpec, List<IFileRevisionData>> getRevisionHistory(
            final List<IFileSpec> fileSpecs,
            final GetRevisionHistoryOptions opts);  }
@Test(expected = ConnectionException.class) public void testGetRevisionHistoryByFileSpecsMaxRevsContentHistoryIncludeInheritedLongOutputAndTruncatedLongOutputExpectedConnectionException() throws Exception { doThrow(ConnectionException.class).when(server).execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq((Map<String, Object>) null)); fileLogDelegator.getRevisionHistory(mockFileSpecs, MOCK_MAX_REVS, false, false, false, false); }
@Test(expected = AccessException.class) public void testGetRevisionHistoryByFileSpecsMaxRevsContentHistoryIncludeInheritedLongOutputAndTruncatedLongOutputExpectedAccessException() throws Exception { doThrow(AccessException.class).when(server).execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq((Map<String, Object>) null)); fileLogDelegator.getRevisionHistory(mockFileSpecs, MOCK_MAX_REVS, false, false, false, false); }
@Test public void testGetRevisionHistoryByFileSpecsMaxRevsContentHistoryIncludeInheritedLongOutputAndTruncatedLongOutputExpectedEmptyMapAsInnerMethodCallThrownP4JavaException() throws Exception { doThrow(P4JavaException.class).when(server).execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq((Map<String, Object>) null)); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator .getRevisionHistory(mockFileSpecs, MOCK_MAX_REVS, false, false, false, false); assertThat(revisionHistory.size(), is(0)); }
@Test public void testGetRevisionHistoryByFileSpecsMaxRevsContentHistoryIncludeInheritedLongOutputAndTruncatedLongOutputExpectedReturnNonEmptyMap() throws Exception { String depotPath1 = " when(resultMap.get(DEPOT_FILE)).thenReturn(depotPath1); when(resultMap.get("rev0")).thenReturn("11"); when(resultMap.get("time0")).thenReturn("20160923"); when(resultMap.get("change0")).thenReturn("123"); when(resultMap.get("file0,0")).thenReturn(EMPTY); when(resultMap.get("rev1")).thenReturn("12"); when(resultMap.get("time1")).thenReturn("20160923"); when(resultMap.get("change1")).thenReturn("123"); when(resultMap.get("file1,0")).thenReturn(EMPTY); @SuppressWarnings("unchecked") Map<String, Object> resultMap2 = mock(Map.class); String depotPath2 = " when(resultMap2.get(DEPOT_FILE)).thenReturn(depotPath2); when(resultMap2.get(CODE0)).thenReturn(MESSAGE_CODE_IN_ERROR_RANGE); when(resultMap2.get(FMT0)).thenReturn("Error other than Auth fail message"); resultMaps.add(resultMap2); doReturn(resultMaps).when(server).execMapCmdList(eq(FILELOG.toString()), eq(new String[] { "-m" + MOCK_MAX_REVS }), eq((Map<String, Object>) null)); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator .getRevisionHistory(mockFileSpecs, MOCK_MAX_REVS, false, false, false, false); assertThat(revisionHistory.size(), is(2)); for (Map.Entry<IFileSpec, List<IFileRevisionData>> entry : revisionHistory.entrySet()) { IFileSpec fileSpec = entry.getKey(); if (depotPath1.equals(fileSpec.getDepotPathString())) { assertThat(fileSpec.getOpStatus(), is(VALID)); assertThat(entry.getValue().size(), is(2)); } if (depotPath2.equals(fileSpec.getDepotPathString())) { assertThat(fileSpec.getOpStatus(), is(ERROR)); assertThat(entry.getValue(), nullValue()); } } }
@Test public void testGetRevisionHistoryByFileSpecsAndGetRevisionHistoryOptionsExpectedReturnEmptyMapAsResultMapsIsNull() throws Exception { when(server.execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq((Map<String, Object>) null))).thenReturn(null); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator .getRevisionHistory(mockFileSpecs, mockOpts); assertThat(revisionHistory.size(), is(0)); }
@Test public void testGetRevisionHistoryByFileSpecsAndGetRevisionHistoryOptionsExpectedReturnNonEmptyListButDontHaveRevisionHistoryAsSomeError() throws Exception { doReturn(resultMaps).when(server).execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq((Map<String, Object>) null)); givenErrorMessageCode(); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator .getRevisionHistory(mockFileSpecs, mockOpts); assertThat(revisionHistory.size(), is(1)); assertNull(revisionHistory.entrySet().iterator().next().getValue()); }
@Test public void testGetRevisionHistoryByFileSpecsAndGetRevisionHistoryOptionsExpectedReturnNonEmptyListAndNonEmptyRevisionDataList() throws Exception { when(server.execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq((Map<String, Object>) null))).thenReturn(resultMaps); when(resultMap.get("rev0")).thenReturn(MOCK_MAX_REVS); when(resultMap.get("time0")).thenReturn("20160923"); when(resultMap.get("change0")).thenReturn("123"); when(resultMap.get("file0,0")).thenReturn(EMPTY); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator .getRevisionHistory(mockFileSpecs, mockOpts); assertThat(revisionHistory.size(), is(1)); Collection<List<IFileRevisionData>> values = revisionHistory.values(); List<IFileRevisionData> fileRevisionDataList = new ArrayList<IFileRevisionData>(); for (List<IFileRevisionData> revs : values) { fileRevisionDataList.addAll(revs); } assertNotNull(fileRevisionDataList.get(0)); }
@Test public void testGetRevisionHistoryByFileSpecsMaxRevsContentHistoryIncludeInheritedLongOutputAndTruncatedLongOutputExpectedEmptyMapAsInnerMethodCallThrownP4JavaException() throws Exception { doThrow(P4JavaException.class) .when(server) .execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq(null)); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator.getRevisionHistory( mockFileSpecs, MOCK_MAX_REVS, false, false, false, false); assertThat(revisionHistory.size(), is(0)); }
@Test public void testGetRevisionHistoryByFileSpecsMaxRevsContentHistoryIncludeInheritedLongOutputAndTruncatedLongOutputExpectedReturnNonEmptyMap() throws Exception { String depotPath1 = " when(resultMap.get(DEPOT_FILE)).thenReturn(depotPath1); when(resultMap.get("rev0")).thenReturn("11"); when(resultMap.get("time0")).thenReturn("20160923"); when(resultMap.get("change0")).thenReturn("123"); when(resultMap.get("file0,0")).thenReturn(EMPTY); when(resultMap.get("rev1")).thenReturn("12"); when(resultMap.get("time1")).thenReturn("20160923"); when(resultMap.get("change1")).thenReturn("123"); when(resultMap.get("file1,0")).thenReturn(EMPTY); Map<String, Object> resultMap2 = mock(Map.class); String depotPath2 = " when(resultMap2.get(DEPOT_FILE)).thenReturn(depotPath2); when(resultMap2.get(CODE0)).thenReturn(MESSAGE_CODE_IN_ERROR_RANGE); when(resultMap2.get(FMT0)).thenReturn("Error other than Auth fail message"); resultMaps.add(resultMap2); doReturn(resultMaps) .when(server) .execMapCmdList(eq(FILELOG.toString()), eq(new String[]{"-m" + MOCK_MAX_REVS}), eq(null)); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator.getRevisionHistory( mockFileSpecs, MOCK_MAX_REVS, false, false, false, false); assertThat(revisionHistory.size(), is(2)); for(Map.Entry<IFileSpec, List<IFileRevisionData>> entry : revisionHistory.entrySet()) { IFileSpec fileSpec = entry.getKey(); if (depotPath1.equals(fileSpec.getDepotPathString())) { assertThat(fileSpec.getOpStatus(), is(VALID)); assertThat(entry.getValue().size(), is(2)); } if (depotPath2.equals(fileSpec.getDepotPathString())) { assertThat(fileSpec.getOpStatus(), is(ERROR)); assertThat(entry.getValue(), nullValue()); } } }
@Test public void testGetRevisionHistoryByFileSpecsAndGetRevisionHistoryOptionsExpectedReturnEmptyMapAsResultMapsIsNull() throws Exception { when(server.execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq(null))).thenReturn(null); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator.getRevisionHistory( mockFileSpecs, mockOpts); assertThat(revisionHistory.size(), is(0)); }
@Test public void testGetRevisionHistoryByFileSpecsAndGetRevisionHistoryOptionsExpectedReturnNonEmptyListButDontHaveRevisionHistoryAsSomeError() throws Exception { doReturn(resultMaps) .when(server) .execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq(null)); givenErrorMessageCode(); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator.getRevisionHistory( mockFileSpecs, mockOpts); assertThat(revisionHistory.size(), is(1)); Collection<List<IFileRevisionData>> values = revisionHistory.values(); List<IFileRevisionData> fileRevisionDataList = new ArrayList(values); Object nullObject = null; assertThat(fileRevisionDataList.get(0), is(nullObject)); }
@Test public void testGetRevisionHistoryByFileSpecsAndGetRevisionHistoryOptionsExpectedReturnNonEmptyListAndNonEmptyRevisionDataList() throws Exception { when(server.execMapCmdList(eq(FILELOG.toString()), any(String[].class), eq(null))).thenReturn(resultMaps); when(resultMap.get("rev0")).thenReturn(MOCK_MAX_REVS); when(resultMap.get("time0")).thenReturn("20160923"); when(resultMap.get("change0")).thenReturn("123"); when(resultMap.get("file0,0")).thenReturn(EMPTY); Map<IFileSpec, List<IFileRevisionData>> revisionHistory = fileLogDelegator.getRevisionHistory( mockFileSpecs, mockOpts); assertThat(revisionHistory.size(), is(1)); Collection<List<IFileRevisionData>> values = revisionHistory.values(); List<IFileRevisionData> fileRevisionDataList = new ArrayList(values); assertNotNull(fileRevisionDataList.get(0)); }