harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r651216 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/internal/nls/ main/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/harmony/jndi/provider/ldap/
Date Thu, 24 Apr 2008 10:20:09 GMT
Author: lvjing
Date: Thu Apr 24 03:20:02 2008
New Revision: 651216

URL: http://svn.apache.org/viewvc?rev=651216&view=rev
Log:
Apply patch for HARMONY-5787, [classlib][jndi][ldap] - Refine modiyAttributes method in LdapSchemaContextImpl

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties?rev=651216&r1=651215&r2=651216&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
Thu Apr 24 03:20:02 2008
@@ -218,3 +218,4 @@
 ldap.35=[LDAP: error code {0}]
 ldap.36=Must have numeric OID
 ldap.37=Can't delete schema root
+ldap.38=Can't modify schema root

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java?rev=651216&r1=651215&r2=651216&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
Thu Apr 24 03:20:02 2008
@@ -275,6 +275,7 @@
         }
     }
 
+    @Override
     public void modifyAttributes(Name name, int i, Attributes attributes)
             throws NamingException {
         checkName(name);
@@ -301,79 +302,115 @@
         }
 
         modifyAttributes(name, items);
-
     }
 
     private static final int jndi2ldap[] = { -1, 0, 2, 1, };
 
+    @Override
     public void modifyAttributes(Name name, ModificationItem[] modificationItems)
             throws NamingException {
-        checkName(name);
-
-        Name targetDN = (rdn.size() != 0) ? name.addAll(rdn) : name;
-        int size = targetDN.size();
-        ModifyOp op = new ModifyOp(targetDN.toString());
-        String oldValue = "(objectclass)";
-        switch (size) {
-        case 0:
-            break;
-        case 1:
-            String schemaType = schemaJndi2Ldap.get(name.get(0).toLowerCase());
-            if (null == schemaType) {
-                throw new NameNotFoundException(name.toString());
-            }
-            if (modificationItems == null) {
-                throw new NullPointerException(Messages.getString("ldap.27")); //$NON-NLS-1$
-            }
-            break;
-        default:
-            Hashtable<String, Object> classDef = parent
-                    .findSchemaDefInfo(schemaJndi2Ldap.get(name.get(0)
-                            .toLowerCase()), name.get(1));
-            if (modificationItems == null) {
-                throw new NullPointerException(Messages.getString("ldap.27")); //$NON-NLS-1$
-            }
-            if (null == classDef) {
-                throw new NameNotFoundException(name.toString());
+        // First get the old schema.
+        int size = name.size();
+        Hashtable<String, Object> subSchemaTree = doLookup(name
+                .getPrefix(size - 1), size - 1);
+
+        String subSchemaType = name.getSuffix(size - 1).toString()
+                .toLowerCase();
+
+        Object schema = subSchemaTree.get(jndi2ldap(subSchemaType));
+        if (schema == null) {
+            throw new NameNotFoundException(name.toString());
+        }
+
+        if (level - size == 2) {
+            // ldap.38=Can't modify schema root
+            throw new SchemaViolationException(Messages.getString("ldap.38")); //$NON-NLS-1$
+        }
+
+        if (modificationItems.length == 0) {
+            return;
+        }
+
+        String schemaLine = schema.toString();
+        if (schema instanceof Hashtable) {
+            Hashtable table = (Hashtable) schema;
+            schemaLine = table.get(SchemaParser.ORIG).toString();
+        }
+
+        // Construct the new schema.
+        Attributes attributes = getAttributes(name);
+        int modifyOperation;
+        Attribute modifyAttribute;
+        Attribute attribute;
+        NamingEnumeration<?> enu;
+        for (int i = 0; i < modificationItems.length; i++) {
+            modifyOperation = modificationItems[i].getModificationOp();
+            modifyAttribute = modificationItems[i].getAttribute();
+
+            switch (modifyOperation) {
+            case DirContext.ADD_ATTRIBUTE:
+                attribute = attributes.get(modifyAttribute.getID());
+                if (attribute == null) {
+                    attributes.put(modifyAttribute);
+                } else {
+                    enu = modifyAttribute.getAll();
+                    while (enu.hasMoreElements()) {
+                        attribute.add(enu.nextElement());
+                    }
+                    attributes.put(attribute);
+                }
+                break;
+
+            case DirContext.REMOVE_ATTRIBUTE:
+                attribute = attributes.get(modifyAttribute.getID());
+                enu = modifyAttribute.getAll();
+                while (enu.hasMoreElements()) {
+                    attribute.remove(enu.nextElement());
+                }
+                if (attribute.size() == 0) {
+                    attributes.remove(modifyAttribute.getID());
+                }
+                break;
+
+            case DirContext.REPLACE_ATTRIBUTE:
+                attributes.remove(modifyAttribute.getID());
+                attributes.put(modifyAttribute);
+                break;
+            default:
+                // Never reach here.
             }
-
-            oldValue = (String) classDef.get("orig");
         }
-        BasicAttribute oldAttr = new LdapAttribute(new BasicAttribute(
-                OBJECT_CLASSES, oldValue), parent);
-        StringBuilder addValue = new StringBuilder();
-        for (ModificationItem item : modificationItems) {
-            Attribute attr = item.getAttribute();
-            addValue.append(attr.getID()).append(" ").append(attr.get());
-        }
-        addValue.append(" )");
-        BasicAttribute newAttr = new LdapAttribute(new BasicAttribute(
-                OBJECT_CLASSES, oldValue.replace(")", addValue.toString())),
-                this);
+        String newSchemaLine = SchemaParser.format(attributes);
+
+        // Remove old schema, then add new schema.
+        ModifyOp op = new ModifyOp(parent.subschemasubentry);
+        Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn);
+        BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute(
+                jndi2ldap(modifySchemaName.toString()), schemaLine), parent);
         op.addModification(jndi2ldap[DirContext.REMOVE_ATTRIBUTE],
-                new LdapAttribute(oldAttr, parent));
+                new LdapAttribute(schemaEntry, parent));
+        BasicAttribute addSchemaEntry = new LdapAttribute(new BasicAttribute(
+                jndi2ldap(modifySchemaName.toString()), newSchemaLine), parent);
         op.addModification(jndi2ldap[DirContext.ADD_ATTRIBUTE],
-                new LdapAttribute(newAttr, parent));
-
-        try {
-            doBasicOperation(op);
-        } catch (Exception e) {
-            throw new SchemaViolationException("Cannot modify schema root");
-        }
+                new LdapAttribute(addSchemaEntry, parent));
 
+        doBasicOperation(op);
+        subSchemaTree.remove(subSchemaType);
+        subSchemaTree.put(subSchemaType, newSchemaLine);
     }
 
+    @Override
     public void modifyAttributes(String s, int i, Attributes attributes)
             throws NamingException {
         Name name = convertFromStringToName(s);
         modifyAttributes(name, i, attributes);
     }
 
+    @Override
     public void modifyAttributes(String s, ModificationItem[] modificationItems)
             throws NamingException {
         Name name = convertFromStringToName(s);
         modifyAttributes(name, modificationItems);
-
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java?rev=651216&r1=651215&r2=651216&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java
Thu Apr 24 03:20:02 2008
@@ -725,6 +725,424 @@
         assertEquals(1, count);
     }
 
+    public void testRemoveAttributes_DESC() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("DESC", "for test");
+
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.REMOVE_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        assertNull(attrs.get("DESC"));
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testRemoveAttributes_DESC2() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("DESC", "different desc");
+
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.REMOVE_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        Attribute descAttr = attrs.get("DESC");
+
+        assertEquals("DESC", descAttr.getID());
+        assertEquals("for test", descAttr.get());
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testRemoveAttributes_Name() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("NAME", "MMObjectClass");
+
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.REMOVE_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        assertNull(attrs.get("NAME"));
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testRemoveAttributes_NUMERICOID() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("NUMERICOID", "test");
+
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.REMOVE_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        assertNotNull(attrs.get("NUMERICOID"));
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testRemoveAttributes_Multiple() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("DESC", "for test");
+        newAttributes.put("SUP", "top");
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.REMOVE_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        assertNull(attrs.get("DESC"));
+        assertNull(attrs.get("SUP"));
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testRemoveAttributes_MultipleValue() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("MUST", "cn");
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.REMOVE_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        Attribute attr = attrs.get("must");
+        Enumeration enu = attr.getAll();
+        assertEquals("objectclass", enu.nextElement());
+        assertFalse(enu.hasMoreElements());
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testRemoveAttributes_MultipleValue2() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put(must);
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.REMOVE_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        assertNull(attrs.get("must"));
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testAddAttributes_DESC() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("DESC", "for test");
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.ADD_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        Attribute descAttr = attrs.get("DESC");
+
+        assertEquals("DESC", descAttr.getID());
+        assertEquals("for test", descAttr.get());
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testAddAttributes_MultipleMust() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("MUST", "objectclass");
+
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.ADD_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        Attribute mustAttr = attrs.get("MUST");
+        assertEquals(2, mustAttr.size());
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testAddAttributes_DuplicateDESC() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("DESC", "for test");
+
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.ADD_ATTRIBUTE, newAttributes);
+
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        Attribute descAttr = attrs.get("DESC");
+        assertEquals(1, descAttr.size());
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testReplaceAttributes() throws NamingException {
+        // Creates a new schema.
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext subSchema = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"), attrs);
+        Attributes newAttributes = new BasicAttributes();
+        newAttributes.put("DESC", "modifed test desc");
+        schema.modifyAttributes("ClassDefinition/MMObjectClass",
+                DirContext.REPLACE_ATTRIBUTE, newAttributes);
+        attrs = schema.getAttributes("ClassDefinition/MMObjectClass");
+        Attribute descAttr = attrs.get("DESC");
+
+        assertEquals("DESC", descAttr.getID());
+        assertEquals("modifed test desc", descAttr.get());
+
+        schema.destroySubcontext(new CompositeName(
+                "ClassDefinition/MMObjectClass"));
+        try {
+            schema.list("ClassDefinition/MMObjectClass");
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
+    public void testModifyAttributes_Exception() throws NamingException {
+        Attributes attrs = new BasicAttributes(true); // Ignore case
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
+        attrs.put("NAME", "MMObjectClass");
+        attrs.put("DESC", "for test");
+        attrs.put("SUP", "top");
+        attrs.put("STRUCTURAL", "true");
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        try {
+            schema.modifyAttributes("invalid", null);
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+
+        try {
+            schema.modifyAttributes("invalid/invalid/invalid", null);
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+
+        try {
+            schema.modifyAttributes("invalid/invalid", null);
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+
+        try {
+            schema.modifyAttributes("classdefinition/invalid", null);
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+
+        try {
+            schema.modifyAttributes("classdefinition/javaClass/name", null);
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+
+        try {
+            schema.modifyAttributes("classdefinition/javaClass/invalid", null);
+            fail("Should throw NameNotFoundException.");
+        } catch (NameNotFoundException e) {
+            // Expected.
+        }
+    }
+
     public void testCreateAndDeleteSubContext() throws NamingException {
         // Creates the attributes.
         Attributes attrs = new BasicAttributes(false); // Ignore case



Mime
View raw message