Java 类javax.naming.ldap.SortKey 实例源码

项目:teiid    文件:LDAPQueryExecution.java   
/** 
 * Set the standard request controls
 */
private void setRequestControls(byte[] cookie) throws TranslatorException {
    List<Control> ctrl = new ArrayList<Control>();
    SortKey[] keys = searchDetails.getSortKeys();
    try {           
        if (keys != null) {
            ctrl.add(new SortControl(keys, Control.NONCRITICAL));
        }
        if (this.executionFactory.usePagination()) {
            ctrl.add(new PagedResultsControl(this.executionContext.getBatchSize(), cookie, Control.CRITICAL));
        }
        if (!ctrl.isEmpty()) {
            this.ldapCtx.setRequestControls(ctrl.toArray(new Control[ctrl.size()]));
            LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Sort/pagination controls were created successfully."); //$NON-NLS-1$
        }
    } catch (NamingException ne) {
           final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.setControlsError") +  //$NON-NLS-1$
           " : "+ne.getExplanation(); //$NON-NLS-1$
        throw new TranslatorException(ne, msg);
    } catch(IOException e) {
        throw new TranslatorException(e);
    }
}
项目:teiid    文件:TestIQueryToLdapSearchParser.java   
/**
 * Test a Query without criteria
 */
@Test public void testSelectFrom1() throws Exception {
    LDAPSearchDetails searchDetails = helpGetSearchDetails("SELECT UserID, Name FROM LdapModel.People"); //$NON-NLS-1$

    //-----------------------------------
    // Set Expected SearchDetails Values
    //-----------------------------------
    String expectedContextName = "ou=people,dc=metamatrix,dc=com"; //$NON-NLS-1$
    String expectedContextFilter = "(objectClass=*)"; //$NON-NLS-1$

    List<String> expectedAttrNameList = new ArrayList<String>();
    expectedAttrNameList.add("uid"); //$NON-NLS-1$
    expectedAttrNameList.add("cn"); //$NON-NLS-1$

    long expectedCountLimit = -1;
    int expectedSearchScope = SearchControls.ONELEVEL_SCOPE;
    SortKey[] expectedSortKeys = null;

    helpTestSearchDetails(searchDetails, expectedContextName, expectedContextFilter, expectedAttrNameList,
            expectedCountLimit, expectedSearchScope, expectedSortKeys);

}
项目:teiid    文件:TestIQueryToLdapSearchParser.java   
/**
 * Test a Query with a criteria
 */
@Test public void testSelectFromWhere1() throws Exception {
    LDAPSearchDetails searchDetails = helpGetSearchDetails("SELECT UserID, Name FROM LdapModel.People WHERE Name = 'R%'"); //$NON-NLS-1$

    //-----------------------------------
    // Set Expected SearchDetails Values
    //-----------------------------------
    String expectedContextName = "ou=people,dc=metamatrix,dc=com"; //$NON-NLS-1$
    String expectedContextFilter = "(cn=R%)"; //$NON-NLS-1$

    List<String> expectedAttrNameList = new ArrayList<String>();
    expectedAttrNameList.add("uid"); //$NON-NLS-1$
    expectedAttrNameList.add("cn"); //$NON-NLS-1$

    long expectedCountLimit = -1;
    int expectedSearchScope = SearchControls.ONELEVEL_SCOPE;
    SortKey[] expectedSortKeys = null;

    helpTestSearchDetails(searchDetails, expectedContextName, expectedContextFilter, expectedAttrNameList,
            expectedCountLimit, expectedSearchScope, expectedSortKeys);

}
项目:teiid    文件:TestIQueryToLdapSearchParser.java   
/**
 * Test a Query with a criteria
 */
@Test public void testEscaping() throws Exception {
    LDAPSearchDetails searchDetails = helpGetSearchDetails("SELECT UserID, Name FROM LdapModel.People WHERE Name = 'R*'"); //$NON-NLS-1$

    //-----------------------------------
    // Set Expected SearchDetails Values
    //-----------------------------------
    String expectedContextName = "ou=people,dc=metamatrix,dc=com"; //$NON-NLS-1$
    String expectedContextFilter = "(cn=R\\2a)"; //$NON-NLS-1$

    List<String> expectedAttrNameList = new ArrayList<String>();
    expectedAttrNameList.add("uid"); //$NON-NLS-1$
    expectedAttrNameList.add("cn"); //$NON-NLS-1$

    long expectedCountLimit = -1;
    int expectedSearchScope = SearchControls.ONELEVEL_SCOPE;
    SortKey[] expectedSortKeys = null;

    helpTestSearchDetails(searchDetails, expectedContextName, expectedContextFilter, expectedAttrNameList,
            expectedCountLimit, expectedSearchScope, expectedSortKeys);

}
项目:teiid    文件:TestIQueryToLdapSearchParser.java   
@Test public void testNot() throws Exception {
    LDAPSearchDetails searchDetails = helpGetSearchDetails("SELECT UserID, Name FROM LdapModel.People WHERE not (Name like 'R%' or Name like 'S%')"); //$NON-NLS-1$

    //-----------------------------------
    // Set Expected SearchDetails Values
    //-----------------------------------
    String expectedContextName = "ou=people,dc=metamatrix,dc=com"; //$NON-NLS-1$
    String expectedContextFilter = "(&(!(cn=R*))(!(cn=S*)))"; //$NON-NLS-1$

    List<String> expectedAttrNameList = new ArrayList<String>();
    expectedAttrNameList.add("uid"); //$NON-NLS-1$
    expectedAttrNameList.add("cn"); //$NON-NLS-1$

    long expectedCountLimit = -1;
    int expectedSearchScope = SearchControls.ONELEVEL_SCOPE;
    SortKey[] expectedSortKeys = null;

    helpTestSearchDetails(searchDetails, expectedContextName, expectedContextFilter, expectedAttrNameList,
            expectedCountLimit, expectedSearchScope, expectedSortKeys);

}
项目:teiid    文件:TestIQueryToLdapSearchParser.java   
@Test public void testGT() throws Exception {
    LDAPSearchDetails searchDetails = helpGetSearchDetails("SELECT UserID, Name FROM LdapModel.People WHERE Name > 'R'"); //$NON-NLS-1$

    //-----------------------------------
    // Set Expected SearchDetails Values
    //-----------------------------------
    String expectedContextName = "ou=people,dc=metamatrix,dc=com"; //$NON-NLS-1$
    String expectedContextFilter = "(!(cn<=R))"; //$NON-NLS-1$

    List<String> expectedAttrNameList = new ArrayList<String>();
    expectedAttrNameList.add("uid"); //$NON-NLS-1$
    expectedAttrNameList.add("cn"); //$NON-NLS-1$

    long expectedCountLimit = -1;
    int expectedSearchScope = SearchControls.ONELEVEL_SCOPE;
    SortKey[] expectedSortKeys = null;

    helpTestSearchDetails(searchDetails, expectedContextName, expectedContextFilter, expectedAttrNameList,
            expectedCountLimit, expectedSearchScope, expectedSortKeys);
}
项目:teiid    文件:TestIQueryToLdapSearchParser.java   
@Test public void testLT() throws Exception {
    LDAPSearchDetails searchDetails = helpGetSearchDetails("SELECT UserID, Name FROM LdapModel.People WHERE Name < 'R'"); //$NON-NLS-1$

    //-----------------------------------
    // Set Expected SearchDetails Values
    //-----------------------------------
    String expectedContextName = "ou=people,dc=metamatrix,dc=com"; //$NON-NLS-1$
    String expectedContextFilter = "(!(cn>=R))"; //$NON-NLS-1$

    List<String> expectedAttrNameList = new ArrayList<String>();
    expectedAttrNameList.add("uid"); //$NON-NLS-1$
    expectedAttrNameList.add("cn"); //$NON-NLS-1$

    long expectedCountLimit = -1;
    int expectedSearchScope = SearchControls.ONELEVEL_SCOPE;
    SortKey[] expectedSortKeys = null;

    helpTestSearchDetails(searchDetails, expectedContextName, expectedContextFilter, expectedAttrNameList,
            expectedCountLimit, expectedSearchScope, expectedSortKeys);
}
项目:teiid    文件:TestIQueryToLdapSearchParser.java   
private void helpTestLike(String query, String expectedContextFilter)
        throws TranslatorException {
    LDAPSearchDetails searchDetails = helpGetSearchDetails("SELECT UserID FROM LdapModel.People WHERE " + query); //$NON-NLS-1$

       // Set Expected SearchDetails Values
       //-----------------------------------
       String expectedContextName = "ou=people,dc=metamatrix,dc=com"; //$NON-NLS-1$


       List<String> expectedAttrNameList = new ArrayList<String>();
       expectedAttrNameList.add("uid"); //$NON-NLS-1$

       long expectedCountLimit = -1;
       int expectedSearchScope = SearchControls.ONELEVEL_SCOPE;
       SortKey[] expectedSortKeys = null;

       helpTestSearchDetails(searchDetails, expectedContextName, expectedContextFilter, expectedAttrNameList,
            expectedCountLimit, expectedSearchScope, expectedSortKeys);
}
项目:teiid    文件:LDAPSearchDetails.java   
/**
 * Constructor
 * @param name the context name
 * @param searchScope the search scope
 * @param filter the context filter
 * @param attributeList the list of attributes
 * @param keys
 * @param limit
 * @param elementList
 */
public LDAPSearchDetails(String name, int searchScope, String filter, SortKey[] keys, long limit, ArrayList elementList, int timeLimit) {

    this.contextName = name;
    this.searchScope = searchScope;
    this.contextFilter = filter;
    this.keys = keys;
    this.limit = limit;
    this.elementList = elementList;
    this.timeLimit = timeLimit;
}
项目:teiid    文件:TestIQueryToLdapSearchParser.java   
/**
  * Helper method for testing the provided LDAPSearchDetails against expected values
  * @param searchDetails the LDAPSearchDetails object
  * @param expectedContextName the expected context name
  * @param expectedContextFilter the expected context filter string
  * @param expectedAttrNameList list of expected attribute names
  * @param expectedCountLimit the expected count limit
  * @param expectedSearchScope the expected search scope
  * @param expectedSortKeys the expected sortKeys list.
  */
 public void helpTestSearchDetails(final LDAPSearchDetails searchDetails, final String expectedContextName,
        final String expectedContextFilter, final List<String> expectedAttrNameList, final long expectedCountLimit, 
        final int expectedSearchScope, final SortKey[] expectedSortKeys) {

    // Get all of the actual values
     String contextName = searchDetails.getContextName();
     String contextFilter = searchDetails.getContextFilter();
     List<Column> attrList = searchDetails.getElementList();
     long countLimit = searchDetails.getCountLimit();
    int searchScope = searchDetails.getSearchScope();
    SortKey[] sortKeys = searchDetails.getSortKeys();

    // Compare actual with Expected
    assertEquals(expectedContextName, contextName);
    assertEquals(expectedContextFilter, contextFilter);

    assertEquals(attrList.size(),expectedAttrNameList.size());
    Iterator<Column> iter = attrList.iterator();
    Iterator<String> eIter = expectedAttrNameList.iterator();
    while(iter.hasNext()&&eIter.hasNext()) {
String actualName = iter.next().getSourceName();
String expectedName = eIter.next();
assertEquals(actualName, expectedName);
    }

    assertEquals(expectedCountLimit, countLimit);
    assertEquals(expectedSearchScope, searchScope);
    assertArrayEquals(expectedSortKeys, sortKeys);
 }
项目:cn1    文件:SortControlTest.java   
/**
 * @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());

}
项目:freeVM    文件:SortControlTest.java   
/**
 * @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());

}
项目:freeVM    文件:SortControlTest.java   
/**
 * @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());

}
项目:cn1    文件:SortControlTest.java   
/**
 * <p>
 * Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'
 * </p>
 * <p>
 * Here we are testing if this method retrieves the control's ASN.1 BER
 * encoded value. In this case we create a sort control using an array of
 * sortkey.
 * </p>
 * <p>
 * The expecting result is the control's ASN.1 BER encoded value.
 * </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()));
}
项目:freeVM    文件:SortControlTest.java   
/**
 * <p>
 * Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'
 * </p>
 * <p>
 * Here we are testing if this method retrieves the control's ASN.1 BER
 * encoded value. In this case we create a sort control using an array of
 * sortkey.
 * </p>
 * <p>
 * The expecting result is the control's ASN.1 BER encoded value.
 * </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()));
}
项目:freeVM    文件:SortControlTest.java   
/**
 * <p>
 * Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'
 * </p>
 * <p>
 * Here we are testing if this method retrieves the control's ASN.1 BER
 * encoded value. In this case we create a sort control using an array of
 * sortkey.
 * </p>
 * <p>
 * The expecting result is the control's ASN.1 BER encoded value.
 * </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()));
}
项目:teiid    文件:LDAPSearchDetails.java   
/**
 * get the sort keys
 * @return the sort keys
 */
public SortKey[] getSortKeys() {
    return keys;
}