harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r585787 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/provider/ldap/ main/java/org/apache/harmony/jndi/provider/ldap/asn1/ test/java/org/apache/harmony/jndi/provider/ldap/
Date Thu, 18 Oct 2007 02:16:49 GMT
Author: leoli
Date: Wed Oct 17 19:16:48 2007
New Revision: 585787

URL: http://svn.apache.org/viewvc?rev=585787&view=rev
Log:
Apply patch for HARMONY-4956([classlib][ldap] Implement ldap request: Compare, Extended, ModifyDN,
Modify, Abandon).

Added:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ExtendedOp.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/CompareOpTest.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapMessageTest.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOpTest.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java
Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java?rev=585787&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java
Wed Oct 17 19:16:48 2007
@@ -0,0 +1,64 @@
+/* 
+ *  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.harmony.jndi.provider.ldap;
+
+import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+
+public class CompareOp implements LdapOperation, ASN1Encodable {
+
+    private String entry;
+
+    private AttributeTypeAndValuePair ava;
+
+    public CompareOp(String entry, AttributeTypeAndValuePair pair) {
+        this.entry = entry;
+        this.ava = pair;
+    }
+
+    private LdapResult result;
+
+    public ASN1Encodable getRequest() {
+        return this;
+    }
+
+    public int getRequestId() {
+        return LdapASN1Constant.OP_COMPARE_REQUEST;
+    }
+
+    public ASN1Decodable getResponse() {
+        return result = (result == null) ? new LdapResult() : result;
+    }
+
+    public int getResponseId() {
+        return LdapASN1Constant.OP_COMPARE_RESPONSE;
+    }
+
+    public void encodeValues(Object[] values) {
+        values[0] = Utils.getBytes(entry);
+        Object[] objs = new Object[2];
+        objs[0] = Utils.getBytes(ava.getType());
+        objs[1] = ava.getValue();
+        // FIXME: convert according to schema
+        values[1] = objs;
+    }
+
+}

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ExtendedOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ExtendedOp.java?rev=585787&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ExtendedOp.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ExtendedOp.java
Wed Oct 17 19:16:48 2007
@@ -0,0 +1,89 @@
+/* 
+ *  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.harmony.jndi.provider.ldap;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.ExtendedResponse;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+
+public class ExtendedOp implements LdapOperation, ASN1Encodable,
+        ASN1Decodable {
+
+    private ExtendedRequest request;
+
+    private ExtendedResponse response;
+
+    private LdapResult result;
+
+    public ExtendedOp(ExtendedRequest request) {
+        this.request = request;
+    }
+
+    public ASN1Encodable getRequest() {
+        return this;
+    }
+
+    public int getRequestId() {
+        return LdapASN1Constant.OP_EXTENDED_REQUEST;
+    }
+
+    public ASN1Decodable getResponse() {
+        return this;
+    }
+
+    public int getResponseId() {
+        return LdapASN1Constant.OP_EXTENDED_RESPONSE;
+    }
+
+    public ExtendedRequest getExtendedRequest() {
+        return request;
+    }
+
+    public ExtendedResponse getExtendedResponse() {
+        return response;
+    }
+
+    public LdapResult getResult() {
+        return result;
+    }
+
+    public void encodeValues(Object[] values) {
+        values[0] = Utils.getBytes(request.getID());
+        values[1] = request.getEncodedValue();
+    }
+
+    public void decodeValues(Object[] values) {
+        result = new LdapResult();
+        result.decodeValues(values);
+        if (values[4] != null) {
+            String id = Utils.getString((byte[]) values[4]);
+            byte[] value = (byte[]) values[5];
+            try {
+                response = request.createExtendedResponse(id, value, 0,
+                        value.length);
+            } catch (NamingException e) {
+                // FIXME: how to deal with this exception
+            }
+        }
+    }
+}

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java?rev=585787&r1=585786&r2=585787&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java
Wed Oct 17 19:16:48 2007
@@ -138,7 +138,8 @@
     public void encodeValues(Object[] values) {
         values[0] = ASN1Integer.fromIntValue(messageId);
         // DelRequest are ASN.1 primitive
-        if (opIndex == LdapASN1Constant.OP_DEL_REQUEST) {
+        if (opIndex == LdapASN1Constant.OP_ABANDON_REQUEST
+                || opIndex == LdapASN1Constant.OP_DEL_REQUEST) {
             Object[] objs = new Object[1];
             requestOp.encodeValues(objs);
             values[1] = new ChosenValue(opIndex, objs[0]);

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java?rev=585787&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java
Wed Oct 17 19:16:48 2007
@@ -0,0 +1,69 @@
+/* 
+ *  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.harmony.jndi.provider.ldap;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+
+public class ModifyDNOp implements LdapOperation, ASN1Encodable {
+    private LdapResult result;
+
+    private String entry;
+
+    private String newrdn;
+
+    private boolean deleteoldrdn;
+
+    private String newSuperior;
+
+    public ModifyDNOp(String entry, String newrdn, boolean deleteoldrdn,
+            String newSuperior) {
+        this.entry = entry;
+        this.newrdn = newrdn;
+        this.deleteoldrdn = deleteoldrdn;
+        this.newSuperior = newSuperior;
+    }
+
+    public ASN1Encodable getRequest() {
+        return this;
+    }
+
+    public int getRequestId() {
+        return LdapASN1Constant.OP_MODIFY_DN_REQUEST;
+    }
+
+    public ASN1Decodable getResponse() {
+        return result = (result == null) ? new LdapResult() : result;
+    }
+
+    public int getResponseId() {
+        return LdapASN1Constant.OP_MODIFY_DN_RESPONSE;
+    }
+
+    public void encodeValues(Object[] values) {
+        values[0] = Utils.getBytes(entry);
+        values[1] = Utils.getBytes(newrdn);
+        values[2] = Boolean.valueOf(deleteoldrdn);
+        if (newSuperior != null) {
+            values[3] = Utils.getBytes(newSuperior);
+        }
+    }
+
+}

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java?rev=585787&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
Wed Oct 17 19:16:48 2007
@@ -0,0 +1,85 @@
+/* 
+ *  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.harmony.jndi.provider.ldap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+import org.apache.harmony.security.asn1.ASN1Integer;
+
+public class ModifyOp implements LdapOperation, ASN1Encodable {
+
+    private String dn;
+
+    private List<Modification> modifications = new ArrayList<Modification>();
+
+    private LdapResult result;
+
+    public ModifyOp(String dn) {
+        this.dn = dn;
+    }
+    
+    public ASN1Encodable getRequest() {
+        return this;
+    }
+
+    public int getRequestId() {
+        return LdapASN1Constant.OP_MODIFY_REQUEST;
+    }
+
+    public ASN1Decodable getResponse() {
+        return result = (result == null) ? new LdapResult() : result;
+    }
+
+    public int getResponseId() {
+        return LdapASN1Constant.OP_MODIFY_RESPONSE;
+    }
+
+    public void encodeValues(Object[] values) {
+        values[0] = Utils.getBytes(dn);
+        values[1] = modifications;
+    }
+
+    public void addModification(int type, LdapAttribute attr) {
+        if (type >= 0 && type <= 2 && attr != null) {
+            modifications.add(new Modification(type, attr));
+        }
+
+        // FIXME: what exception be thrown?
+    }
+
+    private static class Modification implements ASN1Encodable {
+        int type;
+
+        LdapAttribute attr;
+
+        public Modification(int type, LdapAttribute attr) {
+            this.type = type;
+            this.attr = attr;
+        }
+
+        public void encodeValues(Object[] values) {
+            values[0] = ASN1Integer.fromIntValue(type);
+            values[1] = attr;
+        }
+    }
+}

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java?rev=585787&r1=585786&r2=585787&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java
Wed Oct 17 19:16:48 2007
@@ -38,14 +38,32 @@
     public static final int OP_BIND_RESPONSE = 1;
 
     // FIXME change them to appropriate index number in the future.
-    public static final int OP_ADD_REQUEST = 2;
+    public static final int OP_MODIFY_REQUEST = 2;
     
-    public static final int OP_ADD_RESPONSE = 3;
+    public static final int OP_MODIFY_RESPONSE = 3;
 
-    public static final int OP_DEL_REQUEST = 4;
+    public static final int OP_ADD_REQUEST = 4;
+    
+    public static final int OP_ADD_RESPONSE = 5;
+    
+    public static final int OP_DEL_REQUEST = 6;
+
+    public static final int OP_DEL_RESPONSE = 7;
+
+    public static final int OP_MODIFY_DN_REQUEST = 8;
+    
+    public static final int OP_MODIFY_DN_RESPONSE = 9;
+
+    public static final int OP_COMPARE_REQUEST = 10;
+    
+    public static final int OP_COMPARE_RESPONSE = 11;
+
+    public static final int OP_ABANDON_REQUEST = 12;
 
-    public static final int OP_DEL_RESPONSE = 5;
+    public static final int OP_EXTENDED_REQUEST = 13;
     
+    public static final int OP_EXTENDED_RESPONSE = 14;
+
     public static final ASN1Type Attribute = new ASN1SequenceWrap(
             new ASN1Type[] { ASN1OctetString.getInstance(), // type
                     new ASN1SetOf(ASN1OctetString.getInstance()) }); // vals
@@ -116,6 +134,22 @@
                         }
                     }));
     
+    public static final ASN1Type AttributeValueAssertion = new ASN1SequenceWrap(
+            new ASN1Type[] { ASN1OctetString.getInstance(), // attributeDesc
+                    ASN1OctetString.getInstance() }); // assertionValue
+    
+    public static final ASN1Type AbandonRequest = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 16, ASN1Integer.getInstance());
+    
+    public static final ASN1Type CompareRequest = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 14, new ASN1SequenceWrap(
+                    new ASN1Type[] { ASN1OctetString.getInstance(), // entry
+                            AttributeValueAssertion })); // ava
+
+
+    public static final ASN1Type CompareResponse = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 15, LDAPResult);
+    
     public static final ASN1Type DelRequest = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 10, ASN1OctetString.getInstance());
     
@@ -123,15 +157,91 @@
     public static final ASN1Type DelResponse = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 11, LDAPResult);
     
+    public static final ASN1Type ExtendedRequest = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 23, new ASN1SequenceWrap(
+                    new ASN1Type[] {
+                            new ASN1Implicit(
+                                    ASN1Constants.CLASS_CONTEXTSPECIFIC, 0, // requestName
+                                    ASN1OctetString.getInstance()),
+                            new ASN1Implicit(
+                                    ASN1Constants.CLASS_CONTEXTSPECIFIC, 1, // requestValue
+                                    ASN1OctetString.getInstance()) }) {
+                {
+                    setOptional(1); // requestValue is optional
+                }
+            });
+
+
+    public static final ASN1Type ExtendedResponse = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 24, Utils.conjoinSequence(
+                    (ASN1Sequence) LDAPResult, // LDAPResult
+                    new ASN1SequenceWrap(new ASN1Type[] {
+                            new ASN1Implicit(
+                                    ASN1Constants.CLASS_CONTEXTSPECIFIC, 10, // responseName
+                                    ASN1OctetString.getInstance()),
+                            new ASN1Implicit(
+                                    ASN1Constants.CLASS_CONTEXTSPECIFIC, 11, // response
+                                    ASN1OctetString.getInstance()) }) {
+                        {
+                            setOptional(0);
+                            setOptional(1);
+                        }
+                    }));
+    
+    public static final ASN1Type ModifyDNRequest = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 12, new ASN1SequenceWrap(
+                    new ASN1Type[] {
+                            ASN1OctetString.getInstance(), // entry
+                            ASN1OctetString.getInstance(), // newrdn
+                            ASN1Boolean.getInstance(), // deleteoldrdn
+                            new ASN1Implicit(
+                                    ASN1Constants.CLASS_CONTEXTSPECIFIC, 0,
+                                    ASN1OctetString.getInstance()) }) { // newSuperior
+                {
+                    setOptional(3);
+                }
+            });
+
+
+    public static final ASN1Type ModifyDNResponse = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 13, LDAPResult);
+    
+    public static final ASN1Type AttributeTypeAndValues = new ASN1SequenceWrap(
+            new ASN1Type[] { ASN1OctetString.getInstance(), // type
+                    new ASN1SetOf(ASN1OctetString.getInstance()) }); // vals
+    
+    public static final ASN1Type ModifyRequest = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 6, new ASN1SequenceWrap(
+                    new ASN1Type[] {
+                            ASN1OctetString.getInstance(), // object
+                            new ASN1SequenceOf(new ASN1SequenceWrap( // modification
+                                    new ASN1Type[] {
+                                            ASN1Enumerated.getInstance(), // operation
+                                            AttributeTypeAndValues })) })); // modification
+
+
+    public static final ASN1Type ModifyResponse = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 7, LDAPResult);
+    
     public static final ASN1Type LDAPMessage = new ASN1SequenceWrap(
             new ASN1Type[] {
                     ASN1Integer.getInstance(),
-                    new ASN1ChoiceWrap(new ASN1Type[] { BindRequest,
+                    new ASN1ChoiceWrap(new ASN1Type[] { 
+                            BindRequest,
                             BindResponse,
+                            ModifyRequest,
+                            ModifyResponse, 
                             AddRequest,
                             AddResponse,
                             DelRequest,
                             DelResponse,
+                            ModifyDNRequest,
+                            ModifyDNResponse, 
+                            CompareRequest, 
+                            CompareResponse,
+                            AbandonRequest, 
+                            ExtendedRequest, 
+                            ExtendedResponse
                             }),
                     new ASN1SequenceOf(Control) }) {
         {

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/CompareOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/CompareOpTest.java?rev=585787&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/CompareOpTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/CompareOpTest.java
Wed Oct 17 19:16:48 2007
@@ -0,0 +1,36 @@
+/* 
+ *  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.harmony.jndi.provider.ldap;
+
+import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+
+import junit.framework.TestCase;
+
+public class CompareOpTest extends TestCase {
+    public void test_encodeValues_$LObject() {
+        String entry = "test entry";
+        AttributeTypeAndValuePair pair = new AttributeTypeAndValuePair("attr1",
+                Utils.getBytes("value1"));
+        CompareOp op = new CompareOp(entry, pair);
+        
+        ASN1TestUtils.checkEncode(op, LdapASN1Constant.CompareRequest);
+    }
+}

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapMessageTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapMessageTest.java?rev=585787&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapMessageTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapMessageTest.java
Wed Oct 17 19:16:48 2007
@@ -0,0 +1,93 @@
+/* 
+ *  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.harmony.jndi.provider.ldap;
+
+import javax.naming.ldap.Control;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+import org.apache.harmony.security.asn1.ASN1Integer;
+
+public class LdapMessageTest extends TestCase {
+
+    static class MockAbandonRequest implements ASN1Encodable {
+        int messageId;
+
+        public MockAbandonRequest(int id) {
+            messageId = id;
+        }
+
+        public void encodeValues(Object[] values) {
+            values[0] = ASN1Integer.fromIntValue(messageId);
+        }
+
+    }
+
+    static class MockDeleteRequest implements ASN1Encodable {
+        String dn;
+
+        public MockDeleteRequest(String dn) {
+            this.dn = dn;
+        }
+
+        public void encodeValues(Object[] values) {
+            values[0] = Utils.getBytes(dn);
+        }
+
+    }
+
+    static class MockExtendedRequest implements ASN1Encodable {
+        String name;
+
+        String value;
+
+        public MockExtendedRequest(String name, String value) {
+            this.name = name;
+            this.value = value;
+        }
+
+        public void encodeValues(Object[] values) {
+            values[0] = Utils.getBytes(name);
+            values[1] = Utils.getBytes(value);
+        }
+
+    }
+
+    public void test_encodeValues_$LObject() {
+        LdapMessage message = new LdapMessage(
+                LdapASN1Constant.OP_ABANDON_REQUEST, new MockAbandonRequest(1),
+                null);
+        ASN1TestUtils.checkEncode(message, LdapASN1Constant.LDAPMessage);
+
+        message = new LdapMessage(LdapASN1Constant.OP_DEL_REQUEST,
+                new MockDeleteRequest("dn"), null);
+        ASN1TestUtils.checkEncode(message, LdapASN1Constant.LDAPMessage);
+
+        message = new LdapMessage(LdapASN1Constant.OP_DEL_REQUEST,
+                new MockDeleteRequest("dn"), new Control[0]);
+        ASN1TestUtils.checkEncode(message, LdapASN1Constant.LDAPMessage);
+
+        message = new LdapMessage(LdapASN1Constant.OP_EXTENDED_REQUEST,
+                new MockExtendedRequest("extended", "test"), new Control[0]);
+        ASN1TestUtils.checkEncode(message, LdapASN1Constant.LDAPMessage);
+    }
+}

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOpTest.java?rev=585787&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOpTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOpTest.java
Wed Oct 17 19:16:48 2007
@@ -0,0 +1,37 @@
+/* 
+ *  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.harmony.jndi.provider.ldap;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+
+import junit.framework.TestCase;
+
+public class ModifyDNOpTest extends TestCase {
+    public void test_encodeValues_$LObject() {
+        String entry = "test entry";
+        String newrdn = "test new rdn";
+        String newSuperior = "test new Superior";
+
+        ModifyDNOp op = new ModifyDNOp(entry, newrdn, false, newSuperior);
+        ASN1TestUtils.checkEncode(op, LdapASN1Constant.ModifyDNRequest);
+        
+        op = new ModifyDNOp(entry, newrdn, false, null);
+        ASN1TestUtils.checkEncode(op, LdapASN1Constant.ModifyDNRequest);
+    }
+}

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java?rev=585787&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java
Wed Oct 17 19:16:48 2007
@@ -0,0 +1,45 @@
+/* 
+ *  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.harmony.jndi.provider.ldap;
+
+import javax.naming.directory.DirContext;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+
+import junit.framework.TestCase;
+
+public class ModifyOpTest extends TestCase {
+    public void test_encodeValues_$LObject() {
+        String dn = "test dn";
+        ModifyOp op = new ModifyOp(dn);
+        
+        ASN1TestUtils.checkEncode(op, LdapASN1Constant.ModifyRequest);
+        
+        LdapAttribute attr = new LdapAttribute("attr1");
+        attr.add("value1");
+        attr.add("value2");
+        
+        op.addModification(DirContext.ADD_ATTRIBUTE, attr);
+        
+        attr = new LdapAttribute("attr2");
+        op.addModification(DirContext.REMOVE_ATTRIBUTE, attr);
+        
+        ASN1TestUtils.checkEncode(op, LdapASN1Constant.ModifyRequest);
+    }
+}



Mime
View raw message