ExportDelegator extends BaseDelegator implements IExportDelegator { @Override public List<Map<String, Object>> getExportRecords( final boolean useJournal, final long maxRecs, final int sourceNum, final long offset, final boolean format, final String journalPrefix, final String filter) throws ConnectionException, RequestException, AccessException { try { ExportRecordsOptions exportRecordsOptions = new ExportRecordsOptions() .setFormat(format) .setFilter(filter) .setJournalPrefix(journalPrefix) .setMaxRecs(maxRecs) .setOffset(offset) .setSourceNum(sourceNum) .setUseJournal(useJournal); return getExportRecords(exportRecordsOptions); } catch (final ConnectionException | AccessException | RequestException exc) { throw exc; } catch (P4JavaException exc) { throw new RequestException(exc.getMessage(), exc); } } ExportDelegator(IOptionsServer server); @Override List<Map<String, Object>> getExportRecords(
            final boolean useJournal,
            final long maxRecs,
            final int sourceNum,
            final long offset,
            final boolean format,
            final String journalPrefix,
            final String filter); @Override List<Map<String, Object>> getExportRecords(final ExportRecordsOptions opts); @Override void getStreamingExportRecords(
            final ExportRecordsOptions opts,
            @Nonnull final IStreamingCallback callback,
            final int key);  }
@SuppressWarnings("unchecked") @Test(expected=ConnectionException.class) public void testGetExportRecordsByUseJournalMaxRecsSourceNumOffsetFormatJournalPrefixAndFilterExpectedThrownConnectionExceptionThatWasThrownFromInnerMethodCall() throws Exception { final int maxRecs = 10; final int sourceNum = 2; final int offset = 3; doThrow(ConnectionException.class).when(server).execMapCmdList(eq(EXPORT.toString()), any(String[].class), any(Map.class)); exportDelegator.getExportRecords(true, maxRecs, sourceNum, offset, true, "prefix", "add"); }
@SuppressWarnings("unchecked") @Test(expected=AccessException.class) public void testGetExportRecordsByUseJournalMaxRecsSourceNumOffsetFormatJournalPrefixAndFilterExpectedThrownRAccessExceptionThatWasThrownFromInnerMethodCall() throws Exception { final int maxRecs = 10; final int sourceNum = 2; final int offset = 3; doThrow(AccessException.class).when(server).execMapCmdList(eq(EXPORT.toString()), any(String[].class), any(Map.class)); exportDelegator.getExportRecords(true, maxRecs, sourceNum, offset, true, "prefix", "add"); }
@SuppressWarnings("unchecked") @Test(expected=RequestException.class) public void testGetExportRecordsByUseJournalMaxRecsSourceNumOffsetFormatJournalPrefixAndFilterExpectedThrownRequestExceptionThatWasThrownFromInnerMethodCall() throws Exception { final int maxRecs = 10; final int sourceNum = 2; final int offset = 3; doThrow(RequestException.class).when(server).execMapCmdList(eq(EXPORT.toString()), any(String[].class), any(Map.class)); exportDelegator.getExportRecords(true, maxRecs, sourceNum, offset, true, "prefix", "add"); }
@SuppressWarnings("unchecked") @Test(expected=RequestException.class) public void testGetExportRecordsByUseJournalMaxRecsSourceNumOffsetFormatJournalPrefixAndFilterExpectedThrownRequestExceptionWhenInnerMethodCallThrownP4JavaException() throws Exception { final int maxRecs = 10; final int sourceNum = 2; final int offset = 3; doThrow(P4JavaException.class).when(server).execMapCmdList(eq(EXPORT.toString()), any(String[].class), any(Map.class)); exportDelegator.getExportRecords(true, maxRecs, sourceNum, offset, true, "prefix", "add"); }
@Test public void testGetExportRecordsByExportRecordsOptions() throws Exception { when(mockOpts.processFieldRules()).thenReturn(resultMap); givenWorkingResultMaps(); List<Map<String, Object>> exportRecords = exportDelegator.getExportRecords(mockOpts); assertThat(exportRecords.size(), is(2)); Map<String, Object> secondResultMap = exportRecords.get(1); assertEquals("test", secondResultMap.get("any other")); assertFalse(secondResultMap.containsKey(FUNCTION)); }
@Test public void testGetExportRecordsByUseJournalMaxRecsSourceNumOffsetFormatJournalPrefixAndFilterExpectedReturnNonEmptyList() throws Exception { givenWorkingResultMaps(); final int maxRecs = 10; final int sourceNum = 2; final int offset = 3; List<Map<String, Object>> exportRecords = exportDelegator.getExportRecords(true, maxRecs, sourceNum, offset, true, "prefix", "add"); assertThat(exportRecords, is(resultMaps)); }
@Test public void testGetExportRecordsByExportRecordsOptions() throws Exception { when(mockOpts.processFieldRules()).thenReturn(resultMap); givenWorkingResultMaps(); List<Map<String, Object>> exportRecords = exportDelegator.getExportRecords(mockOpts); assertThat(exportRecords.size(), is(2)); Map<String, Object> secondResultMap = exportRecords.get(1); assertThat(secondResultMap.get("any other"), is("test")); assertThat(secondResultMap.containsKey(FUNCTION), is(false)); }