Added: sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImplTest.java URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImplTest.java?rev=1156202&view=auto ============================================================================== --- sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImplTest.java (added) +++ sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImplTest.java Wed Aug 10 14:52:04 2011 @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sling.samples.ldap.resource.impl; + +import org.apache.directory.ldap.client.api.LdapNetworkConnection; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.apache.sling.samples.ldap.resource.api.LdapResource; + +import java.util.List; +import java.util.Map; + +public class LdapResourceProviderImplTest extends AbstractLdapTest { + + public void testGetResource() throws Exception { + final String path = "/ldap/dc=com/dc=something/ou=people/uid=some.uid"; + provider.getResource(resourceResolver, path); + assertEquals(LdapService.translatePathToDn(path, provider.getProviderRoot()), ldapNetworkConnection.dn); + } + + + public void testTranslateFromPathToDn() throws Exception { + String result = LdapService.translatePathToDn("/ldap/dc=somewhere,dc=com/ou=people/uid=something", provider.getProviderRoot()); + assertEquals("Translate mismatch", "uid=something,ou=people,dc=somewhere,dc=com", result); + } + + public void testTranslateFromDnToPath() { + String result = LdapService.translateDnToPath("uid=something,ou=people," + BASE_DN, provider.getBaseDn(), provider.getProviderRoot()); + assertEquals("Translate mismatch", "/ldap/" + BASE_DN + "/ou=people/uid=something", result); + } + + public void testGetReferencingResources() { + final String searchBaseDn = "ou=people,dc=somewhere,dc=com"; + final String entryDn = "cn=something,ou=somewhere,ou=partners,dc=somewhere,dc=com"; + final String attributeName = "uniqueMember"; + provider.getReferencingResources(searchBaseDn, entryDn, attributeName, resourceResolver); + assertEquals(searchBaseDn, ldapNetworkConnection.baseDn); + assertEquals("(" + attributeName + "=" + entryDn + ")", ldapNetworkConnection.filter); + assertEquals("dn", ldapNetworkConnection.attributes[0]); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } +}
Added: sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/MockLdapNetworkConnection.java URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/MockLdapNetworkConnection.java?rev=1156202&view=auto ============================================================================== --- sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/MockLdapNetworkConnection.java (added) +++ sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/MockLdapNetworkConnection.java Wed Aug 10 14:52:04 2011 @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sling.samples.ldap.resource.impl; + +import org.apache.directory.ldap.client.api.EntryCursorImpl; +import org.apache.directory.ldap.client.api.LdapNetworkConnection; +import org.apache.directory.shared.ldap.model.cursor.EntryCursor; +import org.apache.directory.shared.ldap.model.entry.Entry; +import org.apache.directory.shared.ldap.model.exception.LdapException; +import org.apache.directory.shared.ldap.model.message.SearchScope; + +import java.io.IOException; + +public class MockLdapNetworkConnection extends LdapNetworkConnection { + public String baseDn; + public String filter; + public SearchScope scope; + public String[] attributes; + public String dn; + + @Override + public void bind() throws LdapException, IOException { + // Ignore + } + + @Override + public void bind(String name, String credentials) throws LdapException, IOException { + // Ignore + } + + @Override + public boolean connect() throws LdapException, IOException { + return true; + } + + @Override + public boolean isAuthenticated() { + return true; + } + + @Override + public boolean isConnected() { + return true; + } + + @Override + public void unBind() throws LdapException { + // Ignore + } + + @Override + public Entry lookup(String dn) throws LdapException { + this.dn = dn; + return null; + } + + @Override + public EntryCursor search(String baseDn, String filter, SearchScope scope, String... attributes) throws LdapException { + this.baseDn = baseDn; + this.filter = filter; + this.scope = scope; + this.attributes = attributes; + return new EntryCursorImpl(null); + } +} Added: sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperationTest.java URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperationTest.java?rev=1156202&view=auto ============================================================================== --- sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperationTest.java (added) +++ sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperationTest.java Wed Aug 10 14:52:04 2011 @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sling.samples.ldap.resource.impl.operations; + +import org.apache.sling.samples.ldap.resource.impl.AbstractLdapTest; + +import java.util.List; +import java.util.Map; + +public class ResolveReferencesOperationTest extends AbstractLdapTest { + + public static final String SEARCH_BASE_DN = "ou=people,dc=somewhere,dc=com"; + public static final String ATTRIBUTE_NAME = "uniqueMember"; + public static final String ENTRY_DN = "cn=employee,ou=somewhere,ou=partners,dc=somewhere,dc=com"; + private ResolveReferencesOperation operation; + + public void setUp() throws Exception { + super.setUp(); + operation = new ResolveReferencesOperation(SEARCH_BASE_DN, ATTRIBUTE_NAME, ENTRY_DN); + } + + public void testInvoke() throws Exception { + List<String> entryIterator = ldapService.invoke(operation); + assertEquals(SEARCH_BASE_DN, ldapNetworkConnection.baseDn); + assertEquals("dn", ldapNetworkConnection.attributes[0]); + assertEquals("(" + ATTRIBUTE_NAME + "=" + ENTRY_DN + ")" , ldapNetworkConnection.filter); + + } +}