@Test public void testConstructAdapterFromName_Ldaps() throws InvalidNameException { CompositeName name = new CompositeName(); name.add("ldaps://localhost:389/ou=People,o=JNDITutorial"); DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); assertThat(result.getDn().toString()).isEqualTo("ou=People,o=JNDITutorial"); assertThat(result.getReferralUrl().toString()).isEqualTo("ldaps://localhost:389"); }
return constructAdapterFromName(attrs, name, nameInNamespace);
@Before public void setUp() throws Exception { contextMock = mock(Context.class); contextMock2 = mock(Context.class); tested = new DefaultDirObjectFactory(); }
@Test public void testGetObjectInstance_ObjectNotContext() throws Exception { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(new Object(), DN, null, new Hashtable(), expectedAttributes); assertThat(adapter.getDn()).isEqualTo(DN); assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); }
return constructAdapterFromName(attrs, name, nameInNamespace);
public synchronized SecurityComponents createSecurityComponents() { DefaultDirObjectFactory factory = new DefaultDirObjectFactory(); DefaultSpringSecurityContextSource securityContextSource = new DefaultSpringSecurityContextSource(getLDAPURL()); if (managerDN != null) {
@Test public void testGetObjectInstance() throws Exception { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(contextMock, DN, null, new Hashtable(), expectedAttributes); verify(contextMock).close(); assertThat(adapter.getDn()).isEqualTo(DN); assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); }
@Test public void testConstructAdapterFromName_OnlySlash() throws InvalidNameException { CompositeName name = new CompositeName(); name.add("ldap://localhost:389/"); DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); assertThat(result.getDn().toString()).isEqualTo(""); assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389"); } }
return constructAdapterFromName(attrs, name, nameInNamespace);
public synchronized SecurityComponents createSecurityComponents() { DefaultDirObjectFactory factory = new DefaultDirObjectFactory(); DefaultSpringSecurityContextSource securityContextSource = new DefaultSpringSecurityContextSource(getLDAPURL()); if (managerDN != null){
@Test public void testGetObjectInstance_nullObject() throws Exception { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(null, DN, null, new Hashtable(), expectedAttributes); assertThat(adapter.getDn()).isEqualTo(DN); assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); }
@Test public void testConstructAdapterFromName() throws InvalidNameException { CompositeName name = new CompositeName(); name.add("ldap://localhost:389/ou=People,o=JNDITutorial"); DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); assertThat(result.getDn().toString()).isEqualTo("ou=People,o=JNDITutorial"); assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389"); }
return constructAdapterFromName(attrs, name, nameInNamespace);
@Test public void testGetObjectInstance_CompositeName() throws Exception { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); CompositeName name = new CompositeName(); name.add(DN_STRING); DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(contextMock, name, null, new Hashtable(), expectedAttributes); verify(contextMock).close(); assertThat(adapter.getDn()).isEqualTo(DN); assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); }
@Test public void testConstructAdapterFromName_EmptyName() throws InvalidNameException { CompositeName name = new CompositeName(); name.add("ldap://localhost:389"); DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); assertThat(result.getDn().toString()).isEqualTo(""); assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389"); }
/** * Make sure that the base suffix is stripped off from the DN. * * @throws Exception */ @Test public void testGetObjectInstance_BaseSet() throws Exception { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); when(contextMock2.getNameInNamespace()).thenReturn("dc=jayway, dc=se"); DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(contextMock, LdapUtils.newLdapName( "ou=some unit"), contextMock2, new Hashtable(), expectedAttributes); verify(contextMock).close(); assertThat(adapter.getDn().toString()).isEqualTo("ou=some unit"); assertThat(adapter.getNameInNamespace()).isEqualTo("ou=some unit,dc=jayway,dc=se"); assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); }