incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r1044020 - in /incubator/aries/trunk/jndi/jndi-core/src: main/java/org/apache/aries/jndi/DelegateContext.java test/java/org/apache/aries/jndi/InitialContextTest.java
Date Thu, 09 Dec 2010 16:23:18 GMT
Author: mahrwald
Date: Thu Dec  9 16:23:18 2010
New Revision: 1044020

URL: http://svn.apache.org/viewvc?rev=1044020&view=rev
Log:
ARIES-513: Fix faulty interaction with InitialLdapContext

Modified:
    incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java
    incubator/aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java

Modified: incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java?rev=1044020&r1=1044019&r2=1044020&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java
(original)
+++ incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java
Thu Dec  9 16:23:18 2010
@@ -35,17 +35,21 @@ import javax.naming.directory.DirContext
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.ExtendedResponse;
+import javax.naming.ldap.LdapContext;
 
 import org.osgi.framework.BundleContext;
 
-public class DelegateContext implements DirContext {
+public class DelegateContext implements DirContext, LdapContext {
     
-    private Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+    private final Hashtable<Object, Object> env = new Hashtable<Object, Object>();
 
-    private BundleContext bundleContext;
+    private final BundleContext bundleContext;
     private ContextProvider contextProvider;
-    private Map<String, ContextProvider> urlContexts = new HashMap<String, ContextProvider>();
-    private boolean rebind;
+    private final Map<String, ContextProvider> urlContexts = new HashMap<String,
ContextProvider>();
+    private final boolean rebind;
 
     public DelegateContext(BundleContext bundleContext, Hashtable<?, ?> theEnv) {
         this.bundleContext = bundleContext;
@@ -374,4 +378,35 @@ public class DelegateContext implements 
                                     SearchControls cons) throws NamingException {
         return ((DirContext) findContext(name)).search(name, filterExpr, filterArgs, cons);
     }
+
+    public ExtendedResponse extendedOperation(ExtendedRequest request)
+        throws NamingException {
+      return ((LdapContext) getDefaultContext()).extendedOperation(request);
+    }
+
+    public Control[] getConnectControls() throws NamingException {
+      return ((LdapContext) getDefaultContext()).getConnectControls();
+    }
+
+    public Control[] getRequestControls() throws NamingException {
+      return ((LdapContext) getDefaultContext()).getRequestControls();
+    }
+
+    public Control[] getResponseControls() throws NamingException {
+      return ((LdapContext) getDefaultContext()).getResponseControls();
+    }
+
+    public LdapContext newInstance(Control[] requestControls)
+        throws NamingException {
+      return ((LdapContext) getDefaultContext()).newInstance(requestControls);
+    }
+
+    public void reconnect(Control[] connCtls) throws NamingException {
+      ((LdapContext) getDefaultContext()).reconnect(connCtls);
+    }
+
+    public void setRequestControls(Control[] requestControls)
+        throws NamingException {
+      ((LdapContext) getDefaultContext()).setRequestControls(requestControls);
+    }
 }
\ No newline at end of file

Modified: incubator/aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java?rev=1044020&r1=1044019&r2=1044020&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java
(original)
+++ incubator/aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java
Thu Dec  9 16:23:18 2010
@@ -11,7 +11,12 @@ import javax.naming.InitialContext;
 import javax.naming.Name;
 import javax.naming.NamingException;
 import javax.naming.NoInitialContextException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
 import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
 import javax.naming.spi.ObjectFactory;
 
 import org.apache.aries.jndi.startup.Activator;
@@ -101,4 +106,28 @@ public class InitialContextTest 
     Object someObject = initialCtx.lookup("testURL:somedata");
     assertEquals("Expected to be given a string, but got something else.", "someText", someObject);
   }
+  
+  @Test
+  public void testLookFromLdapICF() throws Exception
+  {
+    InitialContextFactoryBuilder icf = Skeleton.newMock(InitialContextFactoryBuilder.class);
+    bc.registerService(new String[] {InitialContextFactoryBuilder.class.getName(), icf.getClass().getName()},
icf, new Properties());
+    
+    LdapContext backCtx = Skeleton.newMock(LdapContext.class);
+    InitialContextFactory fac = Skeleton.newMock(InitialContextFactory.class);
+    Skeleton.getSkeleton(fac).setReturnValue(
+        new MethodCall(InitialContextFactory.class, "getInitialContext", Hashtable.class),

+        backCtx);
+    Skeleton.getSkeleton(icf).setReturnValue(
+        new MethodCall(InitialContextFactoryBuilder.class, "createInitialContextFactory",
Hashtable.class), 
+        fac);
+    
+    Properties props = new Properties();
+    props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
+    InitialLdapContext ilc = new InitialLdapContext(props, new Control[0]);
+    
+    ExtendedRequest req = Skeleton.newMock(ExtendedRequest.class);
+    ilc.extendedOperation(req);
+    Skeleton.getSkeleton(backCtx).assertCalled(new MethodCall(LdapContext.class, "extendedOperation",
req));
+  }
 }
\ No newline at end of file



Mime
View raw message