BranchesDelegator extends BaseDelegator implements IBranchesDelegator { @Override public List<IBranchSpecSummary> getBranchSpecs(final GetBranchSpecsOptions opts) throws P4JavaException { List<Map<String, Object>> resultMaps = execMapCmdList(BRANCHES, processParameters(opts, server), null); return ResultListBuilder.buildNonNullObjectListFromCommandResultMaps( resultMaps, new Function<Map, IBranchSpecSummary>() { @Override public IBranchSpecSummary apply(Map map) { return new BranchSpecSummary(map, true); } }); } BranchesDelegator(IOptionsServer server); @Override List<IBranchSpecSummary> getBranchSpecs(final GetBranchSpecsOptions opts); @Override List<IBranchSpecSummary> getBranchSpecs(
            final String userName,
            final String nameFilter,
            final int maxReturns);  }
@Test public void testNullServerResponse() throws P4JavaException { when(server.execMapCmdList(eq(BRANCHES.toString()), any(String[].class), eq((Map<String,Object>)null))) .thenReturn(null); List<IBranchSpecSummary> branchSpecs = branchesDelegator .getBranchSpecs(mock(GetBranchSpecsOptions.class)); assertEquals(0, branchSpecs.size()); }
@Test public void testNormalServerResponse() throws P4JavaException { when(server.execMapCmdList(eq(BRANCHES.toString()), any(String[].class), eq((Map<String,Object>)null))) .thenReturn(resultMaps); when(resultMap.get(MapKeys.ACCESS_KEY)).thenReturn("0"); when(resultMap.get(MapKeys.UPDATE_KEY)).thenReturn("0"); List<IBranchSpecSummary> branchSpecs = branchesDelegator .getBranchSpecs(new GetBranchSpecsOptions()); assertEquals(1, branchSpecs.size()); }
@Test public void testFilteredResultList() throws P4JavaException { final String knownName="testKnownName"; final String knownDescription="testKnownSummaryDescription"; when(server.getServerVersion()).thenReturn(20161); when(server.execMapCmdList(eq(BRANCHES.toString()), any(String[].class), eq((Map<String,Object>)null))) .thenReturn(resultMaps); when(resultMap.get(MapKeys.BRANCH_LC_KEY)).thenReturn(knownName); when(resultMap.get(MapKeys.DESCRIPTION_KEY)).thenReturn(knownDescription); when(resultMap.get(MapKeys.ACCESS_KEY)).thenReturn("0"); when(resultMap.get(MapKeys.UPDATE_KEY)).thenReturn("0"); List<IBranchSpecSummary> branchSpecs = branchesDelegator.getBranchSpecs( "seans", "myFilter", 10); assertEquals(1, branchSpecs.size()); assertEquals(knownName, branchSpecs.get(0).getName()); assertEquals(knownDescription, branchSpecs.get(0).getDescription()); }
@Test(expected=RequestException.class) public void testUserNameFilterSupportMinVersion() throws P4JavaException { when(server.getServerVersion()).thenReturn(20051); branchesDelegator.getBranchSpecs("sean", "Date_Modified>453470485", 10); }
@Test(expected=RequestException.class) public void testMaxResultsFilterSupportMinVersion() throws P4JavaException { when(server.getServerVersion()).thenReturn(20051); branchesDelegator.getBranchSpecs(EMPTY, "Date_Modified>453470485", 10); }
@Test(expected=RequestException.class) public void testQueryFilterSupportMinVersion() throws P4JavaException { when(server.getServerVersion()).thenReturn(20071); branchesDelegator.getBranchSpecs(EMPTY, "Date_Modified>453470485", -1); }
@Test public void testNullServerResponse() throws P4JavaException { when(server.execMapCmdList(eq(BRANCHES.toString()), any(String[].class), eq(null))) .thenReturn(null); List<IBranchSpecSummary> branchSpecs = branchesDelegator .getBranchSpecs(mock(GetBranchSpecsOptions.class)); assertThat(branchSpecs.size(), is(0)); }
@Test public void testNormalServerResponse() throws P4JavaException { when(server.execMapCmdList(eq(BRANCHES.toString()), any(String[].class), eq(null))) .thenReturn(resultMaps); when(resultMap.get(MapKeys.ACCESS_KEY)).thenReturn("0"); when(resultMap.get(MapKeys.UPDATE_KEY)).thenReturn("0"); List<IBranchSpecSummary> branchSpecs = branchesDelegator .getBranchSpecs(new GetBranchSpecsOptions()); assertThat(branchSpecs.size(), is(1)); }
@Test public void testFilteredResultList() throws P4JavaException { final String knownName="testKnownName"; final String knownDescription="testKnownSummaryDescription"; when(server.getServerVersion()).thenReturn(20161); when(server.execMapCmdList(eq(BRANCHES.toString()), any(String[].class), eq(null))) .thenReturn(resultMaps); when(resultMap.get(MapKeys.BRANCH_LC_KEY)).thenReturn(knownName); when(resultMap.get(MapKeys.DESCRIPTION_KEY)).thenReturn(knownDescription); when(resultMap.get(MapKeys.ACCESS_KEY)).thenReturn("0"); when(resultMap.get(MapKeys.UPDATE_KEY)).thenReturn("0"); List<IBranchSpecSummary> branchSpecs = branchesDelegator.getBranchSpecs( "seans", "myFilter", 10); assertEquals(1, branchSpecs.size()); assertEquals(knownName, branchSpecs.get(0).getName()); assertEquals(knownDescription, branchSpecs.get(0).getDescription()); }
@Test public void testUserNameFilterSupportMinVersion() throws P4JavaException { when(server.getServerVersion()).thenReturn(20051); expectThrows(RequestException.class, () -> branchesDelegator.getBranchSpecs("sean", "Date_Modified>453470485", 10)); }
@Test public void testMaxResultsFilterSupportMinVersion() throws P4JavaException { when(server.getServerVersion()).thenReturn(20051); expectThrows(RequestException.class, () -> branchesDelegator.getBranchSpecs(EMPTY, "Date_Modified>453470485", 10)); }
@Test public void testQueryFilterSupportMinVersion() throws P4JavaException { when(server.getServerVersion()).thenReturn(20071); expectThrows(RequestException.class, () -> branchesDelegator.getBranchSpecs(EMPTY, "Date_Modified>453470485", -1)); }