Package javax.naming.ldap

Examples of javax.naming.ldap.SortControl


      System.out.println("#################SEARCH BY QUERY FILTER##########################");
      SearchControls searchControls = new SearchControls();
      searchControls.setCountLimit(5);
      searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
      Control[] requestControls =
         {new PagedResultsControl(3, Control.CRITICAL), new SortControl(new String[]{"cn"}, Control.NONCRITICAL)};
      ctx.setRequestControls(requestControls);
      results = ctx.search(DEVELOPER_UNIT_DN, "(objectclass=person)", searchControls);
      while (results.hasMoreElements())
      {
         SearchResult sr = (SearchResult)results.nextElement();
View Full Code Here


         if (constraints != null && constraints.isSorted())
         {
            //TODO: make criticallity optional
            //TODO sort by attribute name
            requestControls = new Control[]{
               new SortControl(typeConfiguration.getIdAttributeName(), Control.NONCRITICAL)
            };
         }

         StringBuilder af = new StringBuilder();
View Full Code Here

   * Test for the class javax.naming.ldap.SortControl
   *
   */
  public void testSortControl(){
    try{
      SortControl sc=new SortControl("", false);
      SortControl sc2=null;
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      ObjectOutput out = new ObjectOutputStream(buffer);
      out.writeObject(sc);
      out.close();
      ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
      sc2 = (SortControl) in.readObject();
      in.close();
      assertEquals(sc.getID(),sc2.getID());
    }catch (Exception e) {
      fail("Failed with:"+e);
    }
  }
View Full Code Here

    /**
     * tests how constructors with arrayas process null
     */
    public void testSortControl() throws Exception {
        try {
            new SortControl((String[]) null, false);
            fail("NullPointerException expected");
        } catch (NullPointerException e) {}

        try {
            new SortControl((SortKey[]) null, false);
            fail("NullPointerException expected");
        } catch (NullPointerException e) {}
    }
View Full Code Here

    /**
     * @tests isCritical()
     */
    public void testSortControlStringArrayBoolean002() throws Exception {
        assertTrue(new SortControl("", true).isCritical());
        assertFalse(new SortControl("", false).isCritical());

        assertTrue(new SortControl(new String[0], true).isCritical());
        assertFalse(new SortControl(new String[0], false).isCritical());

        assertTrue(new SortControl(new SortKey[0], true).isCritical());
        assertFalse(new SortControl(new SortKey[0], false).isCritical());

    }
View Full Code Here

     * </p>
     */
    public void testEncodedValueOfSortControl001() throws Exception {
        SortKey[] sk = { new SortKey("pepe", false, "leo") };

        SortControl sc = new SortControl(sk, true);
        assertEquals("30 10 30 0e 04 04 70 65 70 65 80 03 6c 65 6f 81 01 ff",
                toHexString(sc.getEncodedValue()));
    }
View Full Code Here

    }
   
    public void testEncodedValueOfSortControlNull() throws Exception{
        String[] sk = {"pepe", null, "", "haha" };

        SortControl sc = new SortControl(sk, true);
        assertEquals("30 18 30 06 04 04 70 65 70 65 30 02 04 00 30 02 04 00 30 06 04 04 68 61 68 61",
                toHexString(sc.getEncodedValue()));
       
        String[] sk2 = {"pepe", "", "haha" };
        sc = new SortControl(sk2, true);
        assertEquals("30 14 30 06 04 04 70 65 70 65 30 02 04 00 30 06 04 04 68 61 68 61",
                toHexString(sc.getEncodedValue()));
       
        SortKey[] sk3 = {new SortKey("pepe", false, "haha"), null, new SortKey("", true, "haha2"), new SortKey("haah", true, "pepe")};
        try{
            sc = new SortControl(sk3, true);
            fail("should throw NPE");
        }catch(NullPointerException e){
        }
       
        SortKey[] sk4 = {new SortKey("pepe", false, "haha"), new SortKey("", true, "haha2"), new SortKey("haah", true, "pepe")};
        sc = new SortControl(sk4, true);
        assertEquals("30 2a 30 0f 04 04 70 65 70 65 80 04 68 61 68 61 81 01 ff 30 09 04 00 80 05 68 61 68 61 32 30 0c 04 04 68 61 61 68 80 04 70 65 70 65",
                toHexString(sc.getEncodedValue()));

    }
View Full Code Here

     * </p>
     */
    public void testEncodedValueOfSortControl003() throws Exception {
        SortKey[] sk = { new SortKey("", true, "") };

        SortControl sc = new SortControl(sk, true);
        assertEquals("30 06 30 04 04 00 80 00", toHexString(sc
                .getEncodedValue()));

        SortKey[] sk1 = { new SortKey("pepe", true, "laura") };

        sc = new SortControl(sk1, true);
        assertEquals("30 0f 30 0d 04 04 70 65 70 65 80 05 6c 61 75 72 61",
                toHexString(sc.getEncodedValue()));
    }
View Full Code Here

     * The expecting result is the control's ASN.1 BER encoded value.
     * </p>
     */
    public void testEncodedValueOfSortControl006() throws Exception {
        String[] sk = { "" };
        SortControl sc = new SortControl(sk, true);
        assertEquals("30 04 30 02 04 00", toHexString(sc.getEncodedValue()));

        String[] sk1 = { "pepe", "", "toto" };
        sc = new SortControl(sk1, true);
        assertEquals(
                "30 14 30 06 04 04 70 65 70 65 30 02 04 00 30 06 04 04 74 6f 74 6f",
                toHexString(sc.getEncodedValue()));
    }
View Full Code Here

     * <p>
     * The expecting result is the control's ASN.1 BER encoded value.
     * </p>
     */
    public void testEncodedValueOfSortControl014() throws Exception {
        SortControl sc;

        sc = new SortControl((String) null, false);
        assertEquals("30 04 30 02 04 00", toHexString(sc.getEncodedValue()));

        sc = new SortControl("", true);
        assertEquals("30 04 30 02 04 00", toHexString(sc.getEncodedValue()));

        sc = new SortControl("pepe", false);
        assertEquals("30 08 30 06 04 04 70 65 70 65", toHexString(sc
                .getEncodedValue()));
    }
View Full Code Here

TOP

Related Classes of javax.naming.ldap.SortControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.