DataSourceProcessor extends ODataSingleProcessor implements ODataProcessor { String percentEncodeNextLink(final String link) { if (link == null) { return null; } return link.replaceAll("\\$skiptoken=.+?(?:&|$)", "") .replaceAll("\\$skipApplied=.+?(?:&|$)", "") .replaceFirst("(?:\\?|&)$", ""); } DataSourceProcessor(final DataSource dataSource, final ValueAccess valueAccess);  DataSourceProcessor(final DataSource dataSource, final ValueAccess valueAccess, final FunctionSource functionSource); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType); @Override ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriInfo, final String contentType); @Override ODataResponse countEntityLinks(final GetEntitySetLinksCountUriInfo uriInfo, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriInfo, final InputStream content,
      final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriInfo, final InputStream content,
      final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse readEntityLink(final GetEntityLinkUriInfo uriInfo, final String contentType); @Override ODataResponse existsEntityLink(final GetEntityLinkCountUriInfo uriInfo, final String contentType); @Override ODataResponse deleteEntityLink(final DeleteUriInfo uriInfo, final String contentType); @Override ODataResponse createEntityLink(final PostUriInfo uriInfo, final InputStream content,
      final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriInfo, final InputStream content,
      final String requestContentType, final String contentType); @Override ODataResponse readEntityComplexProperty(final GetComplexPropertyUriInfo uriInfo, final String contentType); @Override ODataResponse readEntitySimpleProperty(final GetSimplePropertyUriInfo uriInfo, final String contentType); @Override ODataResponse readEntitySimplePropertyValue(final GetSimplePropertyUriInfo uriInfo, final String contentType); @Override ODataResponse deleteEntitySimplePropertyValue(final DeleteUriInfo uriInfo, final String contentType); @Override ODataResponse updateEntityComplexProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
      final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse updateEntitySimpleProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
      final String requestContentType, final String contentType); @Override ODataResponse updateEntitySimplePropertyValue(final PutMergePatchUriInfo uriInfo, final InputStream content,
      final String requestContentType, final String contentType); @Override ODataResponse readEntityMedia(final GetMediaResourceUriInfo uriInfo, final String contentType); @Override ODataResponse deleteEntityMedia(final DeleteUriInfo uriInfo, final String contentType); @Override ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
      final String requestContentType, final String contentType); @Override ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriInfo, final String contentType); @Override ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriInfo, final String contentType); @Override ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content); @Override BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests);  }
@Test public void testSkipAndSkiptoken() { String url1 = "Rooms?$orderby=Seats%20desc&$skiptoken=12&$skipApplied=000000&$topApplied=200"; String result = dataSourceProcessor.percentEncodeNextLink(url1); Assert.assertEquals("Rooms?$orderby=Seats%20desc&$topApplied=200", result); String url2 = "Rooms?$orderby=Seats%20desc&$skiptoken=213&$skipApplied=99"; String result2 = dataSourceProcessor.percentEncodeNextLink(url2); Assert.assertEquals("Rooms?$orderby=Seats%20desc", result2); String url3 = "Rooms?$skiptoken=213&$skipApplied=0000"; String result3 = dataSourceProcessor.percentEncodeNextLink(url3); Assert.assertEquals("Rooms", result3); }
@Test public void testSkipOnly() { String url = "Rooms?$orderby=Seats%20desc&$skipApplied=000000&$topApplied=200"; String result = dataSourceProcessor.percentEncodeNextLink(url); Assert.assertEquals("Rooms?$orderby=Seats%20desc&$topApplied=200", result); String url2 = "Rooms?$orderby=Seats%20desc&$skipApplied=213"; String result2 = dataSourceProcessor.percentEncodeNextLink(url2); Assert.assertEquals("Rooms?$orderby=Seats%20desc", result2); String url3 = "Rooms?$skipApplied=0999"; String result3 = dataSourceProcessor.percentEncodeNextLink(url3); Assert.assertEquals("Rooms", result3); }
@Test public void testSkiptokenOnly() { String url = "Rooms?$orderby=Seats%20desc&$skiptoken=213&$topApplied=200"; String result = dataSourceProcessor.percentEncodeNextLink(url); Assert.assertEquals("Rooms?$orderby=Seats%20desc&$topApplied=200", result); String url2 = "Rooms?$orderby=Seats%20desc&$skiptoken=213"; String result2 = dataSourceProcessor.percentEncodeNextLink(url2); Assert.assertEquals("Rooms?$orderby=Seats%20desc", result2); String url3 = "Rooms?$skiptoken=213"; String result3 = dataSourceProcessor.percentEncodeNextLink(url3); Assert.assertEquals("Rooms", result3); }