Java Code Examples for javax.naming.directory.SearchResult#setNameInNamespace()

The following examples show how to use javax.naming.directory.SearchResult#setNameInNamespace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChainingUserRegistrySynchronizerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private LDAPInitialDirContextFactoryImpl getMockedLDAPSearchResult(boolean withEmail) throws NamingException
{
    @SuppressWarnings("unchecked")
    NamingEnumeration<SearchResult> mockedNamingEnumeration = mock(NamingEnumeration.class);
    when(mockedNamingEnumeration.hasMore()).thenReturn(true).thenReturn(false);

    BasicAttributes attributes = new BasicAttributes();
    attributes.put(new BasicAttribute("sAMAccountName", "U1"));
    attributes.put(new BasicAttribute("givenName", "U1"));
    if (withEmail)
    {
        attributes.put(new BasicAttribute("mail", "[email protected]"));
    }
    SearchResult mockedSearchResult = new SearchResult("CN:U1", null, attributes);
    mockedSearchResult.setNameInNamespace("CN:U1");

    when(mockedNamingEnumeration.next()).thenReturn(mockedSearchResult);

    InitialDirContext mockedInitialDirContext = mock(InitialDirContext.class);
    when(mockedInitialDirContext.search((String)any(), anyString(), any(SearchControls.class))).thenReturn(mockedNamingEnumeration);

    LDAPInitialDirContextFactoryImpl mockedLdapInitialDirContextFactory = mock(LDAPInitialDirContextFactoryImpl.class);
    when(mockedLdapInitialDirContextFactory.getDefaultIntialDirContext(0)).thenReturn(mockedInitialDirContext);
    return mockedLdapInitialDirContextFactory;
}
 
Example 2
Source File: ADMRealmImplTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void retrieveName_notRelative() {
    // given
    SearchResult searchResult = new SearchResult(null, null, null, false);
    searchResult.setNameInNamespace("cn=ldap01");
    searchResult
            .setName("ldap://estdevmail1.dev.est.fujitsu.com:389/cn=ldap01");
    ldapProps.put(Context.PROVIDER_URL, "");
    // when
    String name = realmImpl.retrieveName(ldapProps, searchResult);

    // then
    assertEquals("cn=ldap01", name);
    assertEquals("ldap://estdevmail1.dev.est.fujitsu.com:389",
            ldapProps.getProperty(Context.PROVIDER_URL));
}
 
Example 3
Source File: ADMRealmImplTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void retrieveName_notRelative_Empty() {
    // given
    SearchResult searchResult = new SearchResult(null, null, null, false);
    searchResult.setNameInNamespace("cn=ldap01");
    searchResult.setName("");
    ldapProps.put(Context.PROVIDER_URL, "a");
    // when
    String name = realmImpl.retrieveName(ldapProps, searchResult);

    // then
    assertEquals("cn=ldap01", name);
    assertEquals("a", ldapProps.getProperty(Context.PROVIDER_URL));
}
 
Example 4
Source File: SearchFilterQueryTest.java    From scriptella-etl with Apache License 2.0 4 votes vote down vote up
public void testExecute() {
    QueryCallback qc = new QueryCallback() {
        public void processRow(final ParametersCallback parameters) {
            assertEquals("uid"+rows, parameters.getParameter("uid"));
            assertEquals("search"+rows, parameters.getParameter("cn"));
            assertEquals("cn=search"+rows+", ou=ldap, dc=scriptella", parameters.getParameter("dn"));
            rows++;
        }
    };

    SearchFilterQuery q = new SearchFilterQuery(null, MockParametersCallbacks.UNSUPPORTED, qc) {
        protected NamingEnumeration<SearchResult> query(final LdapConnection connection, final String filter) {
            List<SearchResult> res = new ArrayList<SearchResult>();
            for (int i=0;i<2;i++) {
                BasicAttributes a = new BasicAttributes("uid","uid"+i);
                a.put("cn", "search"+i);
                SearchResult sr = new SearchResult("cn=search"+i+", ou=ldap, dc=scriptella", null, a);
                sr.setNameInNamespace(sr.getName());
                res.add(sr);
            }
            final Iterator<SearchResult> it = res.iterator();
            return new NamingEnumeration<SearchResult>() {

                public SearchResult next() {
                    return it.next();
                }

                public boolean hasMore() {
                    return it.hasNext();
                }

                public void close() {
                    closed=true;
                }

                public boolean hasMoreElements() {
                    return hasMore();
                }

                public SearchResult nextElement() {
                    return next();
                }
            };
        }
    };
    q.execute("filter");//in this test case filter doesn't matter
    assertTrue("Naming enumeration must be closed after iteration", closed);
    assertEquals(2, rows);
}