DimensionItemPageHandler { void addPaginationToNodeIfEnabled( final RootNode rootNode, final WebOptions webOptions, final String dimensionUid, final int totalOfItems ) { final boolean isPaginationEnabled = webOptions.hasPaging( false ); if ( isPaginationEnabled ) { final String apiRelativeUrl = format( RESOURCE_PATH + "/%s/items", dimensionUid ); final Pager pager = new Pager( webOptions.getPage(), totalOfItems, webOptions.getPageSize() ); linkService.generatePagerLinks( pager, apiRelativeUrl ); rootNode.addChild( createPager( pager ) ); } } DimensionItemPageHandler( final LinkService linkService );   }
@Test public void testAddPaginationToNodeWithSuccess() { final RootNode anyRootNode = new RootNode( "any" ); final WebOptions anyWebOptions = mockWebOptions( 10, 1 ); final String anyUid = "LFsZ8v5v7rq"; final int anyTotals = 12; dimensionItemPageHandler.addPaginationToNodeIfEnabled( anyRootNode, anyWebOptions, anyUid, anyTotals ); assertThat( anyRootNode, is( notNullValue() ) ); assertThat( anyRootNode.getName(), is( equalTo( "any" ) ) ); assertThat( anyRootNode.getChildren(), hasSize( 1 ) ); assertThat( anyRootNode.getChildren().get( 0 ).isComplex(), is( true ) ); verify( linkService, times( 1 ) ).generatePagerLinks( any( Pager.class ), anyString() ); }
@Test public void testAddPaginationToNodeWhenPagingIsFalse() { final RootNode anyRootNode = new RootNode( "any" ); final WebOptions webOptionsNoPaging = mockWebOptionsWithPagingFlagFalse(); final String anyUid = "LFsZ8v5v7rq"; final int anyTotals = 12; dimensionItemPageHandler.addPaginationToNodeIfEnabled( anyRootNode, webOptionsNoPaging, anyUid, anyTotals ); assertThat( anyRootNode, is( notNullValue() ) ); assertThat( anyRootNode.getName(), is( equalTo( "any" ) ) ); assertThat( anyRootNode.getChildren(), is( empty() ) ); verify( linkService, never() ).generatePagerLinks( any( Pager.class ), anyString() ); }
@Test public void testAddPaginationToNodeWhenNoPagingIsSet() { final RootNode anyRootNode = new RootNode( "any" ); final WebOptions webOptionsNoPaging = mockWebOptionsWithNoPagingFlagSet(); final String anyUid = "LFsZ8v5v7rq"; final int anyTotals = 12; dimensionItemPageHandler.addPaginationToNodeIfEnabled( anyRootNode, webOptionsNoPaging, anyUid, anyTotals ); assertThat( anyRootNode, is( notNullValue() ) ); assertThat( anyRootNode.getName(), is( equalTo( "any" ) ) ); assertThat( anyRootNode.getChildren(), is( empty() ) ); verify( linkService, never() ).generatePagerLinks( any( Pager.class ), anyString() ); }