private boolean prepareNextPage(LdapContext ldapContext) throws Exception { Control[] responseControls = ldapContext.getResponseControls(); byte[] cookie = null; if (responseControls != null) { for (Control responseControl : responseControls) { if (responseControl instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) responseControl; cookie = prrc.getCookie(); } } } if (cookie == null) { return false; } else { ldapContext.setRequestControls(new Control[]{new PagedResultsControl(pageSize, cookie, Control.CRITICAL)}); return true; } }
private byte[] readResultResponsePageCookie( final Control[] controls ) { if ( controls != null ) { for ( Control control : controls ) { if ( control instanceof PagedResultsResponseControl ) { final PagedResultsResponseControl prrc = ( PagedResultsResponseControl ) control; final byte[] cookie = prrc.getCookie(); if ( cookie != null ) { return cookie; } } } } return null; }
private byte[] getCookie(final LdapContext ctx) throws NamingException, IOException { byte[] cookie = null; // Examine the paged results control response final Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof PagedResultsResponseControl) { final PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i]; cookie = prrc.getCookie(); } } } // Re-activate paged results ctx.setRequestControls(new Control[] { new PagedResultsControl(PAGE_SIZE, cookie, Control.CRITICAL) }); return cookie; }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.PagedResultsResponseControl(String, boolean, byte[])'</p> * <p>Here we are testing if this method constructs a paged-results response control.</p> * <p>The expected result is that the byte array must be copy not clone so any chance in original affect the response.</p> */ public void testPagedResultsResponseControl011() { try { byte[] b={48,5,2,1,0,4,0}; byte[] c={48,5,2,1,0,4,0}; PagedResultsResponseControl x=new PagedResultsResponseControl("",false,b); byte[] aux = x.getEncodedValue().clone(); for (int i = 0; i < b.length; i++) { b[i]=1; } for (int i = 0; i < b.length; i++) { assertSame(c[i],aux[i]); assertSame(b[i],x.getEncodedValue()[i]); } } catch (IOException e) { fail("The arguments are ok."); } }
public void assertDeserialized(Serializable initial, Serializable deserialized) { PagedResultsResponseControl initThr = (PagedResultsResponseControl) initial; PagedResultsResponseControl dserThr = (PagedResultsResponseControl) deserialized; // verify ResultSize int initResultSize = initThr.getResultSize(); int dserResultSize = dserThr.getResultSize(); assertTrue(initResultSize == dserResultSize); // verify Cookie byte[] initCookie = initThr.getCookie(); byte[] dserCookie = dserThr.getCookie(); assertTrue(Arrays.equals(initCookie, dserCookie)); }
@Test public void testPostProcess() throws Exception { int resultSize = 50; byte pageSize = 8; byte[] value = new byte[1]; value[0] = pageSize; byte[] cookie = encodeValue(resultSize, value); PagedResultsResponseControl control = new PagedResultsResponseControl( "dummy", true, cookie); when(ldapContextMock.getResponseControls()).thenReturn(new Control[] { control }); tested.postProcess(ldapContextMock); PagedResultsCookie returnedCookie = tested.getCookie(); assertThat(returnedCookie.getCookie()[0]).isEqualTo((byte)8); assertThat(tested.getPageSize()).isEqualTo(20); assertThat(tested.getResultSize()).isEqualTo(50); }
private byte[] getPagedResponseCookie(Control[] controls) { if (controls != null) { for (Control control : controls) { if (control instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) control; return prrc.getCookie(); } } } return null; }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.PagedResultsResponseControl(String, boolean, byte[])'</p> * <p>Here we are testing if this method constructs a paged-results response control.</p> * <p>The expected result is a IOexception.</p> */ public void testPagedResultsResponseControl003() { try { byte[] b={}; PagedResultsResponseControl x=new PagedResultsResponseControl(null,false,b); fail("The byte array must not be empty."); } catch (IOException e) { } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.PagedResultsResponseControl(String, boolean, byte[])'</p> * <p>Here we are testing if this method constructs a paged-results response control.</p> * <p>The expected result is a IOexception.</p> */ public void testPagedResultsResponseControl004() { try { byte[] b={}; PagedResultsResponseControl x=new PagedResultsResponseControl(null,true,b); fail("The byte array must not be empty."); } catch (IOException e) { } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.PagedResultsResponseControl(String, boolean, byte[])'</p> * <p>Here we are testing if this method constructs a paged-results response control.</p> * <p>The expected result is a IOexception.</p> */ public void testPagedResultsResponseControl005() { try { byte[] b={1,2,3,4,0}; PagedResultsResponseControl x=new PagedResultsResponseControl(null,false,b); fail("The byte array is not ok."); } catch (IOException e) { } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.PagedResultsResponseControl(String, boolean, byte[])'</p> * <p>Here we are testing if this method constructs a paged-results response control.</p> * <p>The expected result is a IOexception.</p> */ public void testPagedResultsResponseControl006() { try { byte[] b={1,2,3,4,0}; PagedResultsResponseControl x=new PagedResultsResponseControl(null,true,b); fail("The byte array is not ok."); } catch (IOException e) { } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.PagedResultsResponseControl(String, boolean, byte[])'</p> * <p>Here we are testing if this method constructs a paged-results response control.</p> * <p>The expected result is an instance of the class.</p> */ public void testPagedResultsResponseControl007() { try { byte[] b={48,5,2,1,0,4,0}; PagedResultsResponseControl x=new PagedResultsResponseControl(null,true,b); } catch (IOException e) { fail("The arguments are ok."); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.PagedResultsResponseControl(String, boolean, byte[])'</p> * <p>Here we are testing if this method constructs a paged-results response control.</p> * <p>The expected result is an instance of the class.</p> */ public void testPagedResultsResponseControl008() { try { byte[] b={48,5,2,1,0,4,0}; PagedResultsResponseControl x=new PagedResultsResponseControl(null,false,b); } catch (IOException e) { fail("The arguments are ok."); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.PagedResultsResponseControl(String, boolean, byte[])'</p> * <p>Here we are testing if this method constructs a paged-results response control.</p> * <p>The expected result is an instance of the class.</p> */ public void testPagedResultsResponseControl010() { try { byte[] b={48,5,2,1,0,4,0}; PagedResultsResponseControl x=new PagedResultsResponseControl("",false,b); } catch (IOException e) { fail("The arguments are ok."); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.getResultSize()'</p> * <p>Here we are testing if this method retrieves (an estimate of) the number of entries in the search result.</p> * <p>The expected result is in this case zero.</p> */ public void testGetResultSize001() { byte[] b={48,5,2,1,0,4,0}; try { PagedResultsResponseControl x=new PagedResultsResponseControl("",false,b); assertEquals(0,x.getResultSize()); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.getResultSize()'</p> * <p>Here we are testing if this method retrieves (an estimate of) the number of entries in the search result.</p> * <p>The expected result is in this case zero.</p> */ public void testGetResultSize002() { byte[] b={48,5,2,1,10,4,0}; try { PagedResultsResponseControl x=new PagedResultsResponseControl("",false,b); assertEquals(10,x.getResultSize()); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.getCookie()'</p> * <p>Here we are testing if this method retrieves the server-generated cookie.</p> * <p>The expected result in this case is null.</p> */ public void testGetCookie001() { byte[] b={48,5,2,1,0,4,0}; try { PagedResultsResponseControl x=new PagedResultsResponseControl("",false,b); assertEquals(null,x.getCookie()); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.getCookie()'</p> * <p>Here we are testing if this method retrieves the server-generated cookie.</p> * <p>The expected result in this case is a not null array.</p> */ public void testGetCookie002() { byte[] b={48,7,2,1,0,4,2,1,1}; byte[] c={1,1}; try { PagedResultsResponseControl x=new PagedResultsResponseControl("",false,b); for (int i = 0; i < x.getCookie().length; i++) { assertEquals(c[i],x.getCookie()[i]); } } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsResponseControl.getCookie()'</p> * <p>Here we are testing if this method retrieves the server-generated cookie.</p> * <p>The expected result in this case is not null.</p> */ public void testGetCookie003() { byte[] b={48,6,2,1,0,4,1,0}; try { PagedResultsResponseControl x=new PagedResultsResponseControl("",false,b); assertNotNull(x.getCookie()); } catch (IOException e) { fail("Failed with:"+e); } }