本文整理汇总了Java中javax.naming.directory.SearchResult.setNameInNamespace方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResult.setNameInNamespace方法的具体用法?Java SearchResult.setNameInNamespace怎么用?Java SearchResult.setNameInNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.directory.SearchResult
的用法示例。
在下文中一共展示了SearchResult.setNameInNamespace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMockedLDAPSearchResult
import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
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(any(String.class), any(String.class), any(SearchControls.class))).thenReturn(mockedNamingEnumeration);
LDAPInitialDirContextFactoryImpl mockedLdapInitialDirContextFactory = mock(LDAPInitialDirContextFactoryImpl.class);
when(mockedLdapInitialDirContextFactory.getDefaultIntialDirContext(0)).thenReturn(mockedInitialDirContext);
return mockedLdapInitialDirContextFactory;
}
示例2: retrieveName_notRelative
import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
@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));
}
示例3: retrieveName_notRelative_Empty
import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
@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));
}