You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by lv...@apache.org on 2008/04/24 07:58:42 UTC
svn commit: r651164 - in /harmony/enhanced/classlib/trunk/modules/jndi/src:
main/java/org/apache/harmony/jndi/internal/nls/
main/java/org/apache/harmony/jndi/provider/ldap/
main/java/org/apache/harmony/jndi/provider/ldap/parser/
test/java/org/apache/ha...
Author: lvjing
Date: Wed Apr 23 22:58:33 2008
New Revision: 651164
URL: http://svn.apache.org/viewvc?rev=651164&view=rev
Log:
Apply patch for HARMONY-5781,[classlib][jndi][ldap] - refine createSubcontext and destroySubcontext in LdapSchemaContextImpl
Removed:
harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImplTest.java
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/main/java/org/apache/harmony/jndi/provider/ldap/parser/SchemaParser.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=651164&r1=651163&r2=651164&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 Wed Apr 23 22:58:33 2008
@@ -216,3 +216,5 @@
ldap.33=Scope should be one of 'OBJECT_SCOPE', 'ONELEVEL_SCOPE' or 'SUBTREE_SCOPE'
ldap.34=[LDAP: error code {0} - {1}]
ldap.35=[LDAP: error code {0}]
+ldap.36=Must have numeric OID
+ldap.37=Can't delete 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=651164&r1=651163&r2=651164&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 Wed Apr 23 22:58:33 2008
@@ -27,10 +27,10 @@
import javax.naming.Binding;
import javax.naming.CompositeName;
-import javax.naming.ConfigurationException;
import javax.naming.Context;
import javax.naming.InvalidNameException;
import javax.naming.Name;
+import javax.naming.NameAlreadyBoundException;
import javax.naming.NameClassPair;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
@@ -56,13 +56,13 @@
public class LdapSchemaContextImpl extends LdapContextImpl {
- public static final String CLASS_DEFINITION = "classdefinition";
+ public static final String CLASS_DEFINITION = "ClassDefinition";
- public static final String ATTRIBUTE_DEFINITION = "attributedefinition";
+ public static final String ATTRIBUTE_DEFINITION = "AttributeDefinition";
- public static final String SYNTAX_DEFINITION = "syntaxdefinition";
+ public static final String SYNTAX_DEFINITION = "SyntaxDefinition";
- public static final String MATCHING_RULE = "matchingrule";
+ public static final String MATCHING_RULE = "MatchingRule";
public static final String OBJECT_CLASSES = "objectclasses";
@@ -78,10 +78,11 @@
final private static Hashtable<String, String> schemaJndi2Ldap = new Hashtable<String, String>();
static {
- schemaJndi2Ldap.put(CLASS_DEFINITION, OBJECT_CLASSES);
- schemaJndi2Ldap.put(ATTRIBUTE_DEFINITION, ATTRIBUTE_TYPES);
- schemaJndi2Ldap.put(SYNTAX_DEFINITION, LDAP_SYNTAXES);
- schemaJndi2Ldap.put(MATCHING_RULE, MATCHING_RULES);
+ schemaJndi2Ldap.put(CLASS_DEFINITION.toLowerCase(), OBJECT_CLASSES);
+ schemaJndi2Ldap
+ .put(ATTRIBUTE_DEFINITION.toLowerCase(), ATTRIBUTE_TYPES);
+ schemaJndi2Ldap.put(SYNTAX_DEFINITION.toLowerCase(), LDAP_SYNTAXES);
+ schemaJndi2Ldap.put(MATCHING_RULE.toLowerCase(), MATCHING_RULES);
}
final private static Hashtable<String, String> schemaLdap2Jndi = new Hashtable<String, String>();
@@ -140,86 +141,67 @@
throw new OperationNotSupportedException();
}
+ @Override
public String getNameInNamespace() throws NamingException {
throw new OperationNotSupportedException();
}
+ @Override
public DirContext createSubcontext(Name name, Attributes attributes)
throws NamingException {
- checkName(name);
-
- Name schemaType = name.getPrefix(name.size() - 1);
+ int size = name.size();
+ Hashtable<String, Object> subSchemaTree = doLookup(name
+ .getPrefix(size - 1), size - 1);
if (null == attributes || attributes.size() == 0) {
- throw new SchemaViolationException(Messages.getString("jndi.8D"));
+ // jndi.8D=Must supply attributes describing schema
+ throw new SchemaViolationException(Messages.getString("jndi.8D")); //$NON-NLS-1$
}
- String schema = schemaJndi2Ldap
- .get(schemaType.toString().toLowerCase());
- if (null == schema) {
- throw new SchemaViolationException(Messages.getString("jndi.8D"));
- }
- if (schemaTable.keySet().contains(schema)) {
- throw new SchemaViolationException(Messages.getString("jndi.8E"));
- }
- String targetDN = rdn.toString() + parent.subschemasubentry;
- StringBuilder builder = new StringBuilder("( ");
- NamingEnumeration<String> ids = attributes.getIDs();
-
- // FIXME what if attribute value has \' or \", or can Attributes be used
- // directly
- boolean hasNOID = false;
- while (ids.hasMoreElements()) {
- String id = ids.nextElement();
- Attribute attribute = attributes.get(id);
- if (id.equalsIgnoreCase("NUMERICOID")) {
- builder.append(attribute);
- builder.append(" ");
- hasNOID = true;
- } else {
- builder.append(id);
- builder.append(" ");
- builder.append(attribute);
- builder.append(" ");
- }
+ if (level - size == 2) {
+ // jndi.8E=Cannot create new entry under schema root
+ throw new SchemaViolationException(Messages.getString("jndi.8E")); //$NON-NLS-1$
}
- builder.append(")");
- if (!hasNOID) {
- throw new ConfigurationException(Messages.getString("jndi.8F"));
+
+ String subSchemaType = name.getSuffix(size - 1).toString();
+
+ if (subSchemaTree.get(subSchemaType.toLowerCase()) != null) {
+ throw new NameAlreadyBoundException(subSchemaType);
}
- ModifyOp op = new ModifyOp(targetDN);
+ String schemaLine = SchemaParser.format(attributes);
+
+ ModifyOp op = new ModifyOp(parent.subschemasubentry);
+ Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn);
BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute(
- schema, builder.toString()), parent);
+ jndi2ldap(modifySchemaName.toString()), schemaLine), parent);
op.addModification(jndi2ldap[DirContext.ADD_ATTRIBUTE],
new LdapAttribute(schemaEntry, parent));
-
try {
doBasicOperation(op);
+ subSchemaTree.put(subSchemaType.toLowerCase(), schemaLine);
} catch (ReferralException e) {
// TODO
}
- return new LdapSchemaContextImpl(parent, parent.env, name, null,
- LdapSchemaContextImpl.SCHEMA_ROOT_LEVEL);
+ return (DirContext) lookup(name);
+
}
+ @Override
public DirContext createSubcontext(String name, Attributes attributes)
throws NamingException {
Name n = convertFromStringToName(name);
return createSubcontext(n, attributes);
}
- /* (non-Javadoc)
- * @see org.apache.harmony.jndi.provider.ldap.LdapContextImpl#getAttributes(javax.naming.Name)
- */
@Override
public Attributes getAttributes(Name name) throws NamingException {
int size = name.size();
Hashtable<String, Object> attributesTable = doLookup(name, size);
- BasicAttributes schemaAttributes = new BasicAttributes();
+ BasicAttributes schemaAttributes = new BasicAttributes(true);
switch (level - size) {
case 1:
@@ -394,47 +376,64 @@
}
+ @Override
public Context createSubcontext(Name name) throws NamingException {
DirContext subContext = createSubcontext(name, null);
return subContext;
}
+ @Override
public Context createSubcontext(String name) throws NamingException {
Name n = convertFromStringToName(name);
return createSubcontext(n);
}
+ @Override
public void destroySubcontext(Name name) throws NamingException {
- checkName(name);
+ int size = name.size();
+ Hashtable<String, Object> subSchemaTree = doLookup(name
+ .getPrefix(size - 1), size - 1);
- // Name schemaType = name.getPrefix(name.size() - 1);
- String targetDN = rdn.toString() + parent.subschemasubentry;
- ModifyOp op = new ModifyOp(targetDN);
- String schemaType = null;
- try {
- schemaType = schemaJndi2Ldap.get(name.getPrefix(name.size() - 1)
- .toString().toLowerCase());
- } catch (IndexOutOfBoundsException e) {
- throw new ArrayIndexOutOfBoundsException();
+ String subSchemaType = name.getSuffix(size - 1).toString()
+ .toLowerCase();
+
+ Object schema = subSchemaTree.get(jndi2ldap(subSchemaType));
+ if (schema == null) {
+ // Return silently.
+ return;
}
- Hashtable<String, Object> classDef = parent.findSchemaDefInfo(
- schemaType, name.get(1));
- if (null == classDef) {
+ if (level - size == 2) {
+ // ldap.37=Can't delete schema root
+ throw new SchemaViolationException(Messages.getString("ldap.37")); //$NON-NLS-1$
+ }
+
+ if (level == size) {
+ // Return silently.
return;
}
- String oldValue = (String) classDef.get("orig");
- LdapAttribute oldAttr = new LdapAttribute(new BasicAttribute(
- schemaType, oldValue), parent);
- op.addModification(jndi2ldap[DirContext.REMOVE_ATTRIBUTE], oldAttr);
+ String schemaLine = schema.toString();
+ if (schema instanceof Hashtable) {
+ Hashtable table = (Hashtable) schema;
+ schemaLine = table.get(SchemaParser.ORIG).toString();
+ }
+
+ 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(schemaEntry, parent));
try {
doBasicOperation(op);
- } catch (Exception e) {
- // TODO need to handle referal exception in the future
+ subSchemaTree.remove(subSchemaType);
+ } catch (ReferralException e) {
+ // TODO
}
}
+ @Override
public void destroySubcontext(String name) throws NamingException {
destroySubcontext(convertFromStringToName(name));
}
@@ -445,7 +444,7 @@
ldapName = jndiName;
}
- return ldapName.toLowerCase();
+ return ldapName;
}
private String jndi2ldap(String ldapName) {
@@ -583,6 +582,7 @@
return tempSchema;
}
+ @Override
public Object lookup(String name) throws NamingException {
return lookup(convertFromStringToName(name));
}
Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/SchemaParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/SchemaParser.java?rev=651164&r1=651163&r2=651164&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/SchemaParser.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/SchemaParser.java Wed Apr 23 22:58:33 2008
@@ -20,6 +20,14 @@
import java.util.Hashtable;
import java.util.StringTokenizer;
+import javax.naming.ConfigurationException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+
+import org.apache.harmony.jndi.internal.nls.Messages;
+
public class SchemaParser {
public final static String SPACE = " "; //$NON-NLS-1$
@@ -30,13 +38,43 @@
public final static String SINGLE_QUOTE = "'"; //$NON-NLS-1$
- public final static String NAME = "name"; //$NON-NLS-1$
+ public final static String DOLLAR = "$"; //$NON-NLS-1$
+
+ public final static String NAME = "NAME"; //$NON-NLS-1$
public final static String ORIG = "orig"; //$NON-NLS-1$
- public final static String NUMERICOID = "numericoid"; //$NON-NLS-1$
+ public final static String NUMERICOID = "NUMERICOID"; //$NON-NLS-1$
+
+ public final static String MUST = "MUST"; //$NON-NLS-1$
+
+ public final static String MAY = "MAY"; //$NON-NLS-1$
+
+ public final static String SUP = "SUP"; //$NON-NLS-1$
+
+ public final static String ABSTRACT = "ABSTRACT"; //$NON-NLS-1$
+
+ public final static String STRUCTURAL = "STRUCTURAL"; //$NON-NLS-1$
+
+ public final static String AUXILIARY = "AUXILIARY"; //$NON-NLS-1$
+
+ public final static String SINGLE_VALUE = "SINGLE-VALUE"; //$NON-NLS-1$
+
+ public final static String NO_USER_MODIFICATION = "NO-USER-MODIFICATION"; //$NON-NLS-1$
+
+ public final static String X_PREFIX = "X-"; //$NON-NLS-1$
+
+ public final static String DESC = "DESC"; //$NON-NLS-1$
+
+ public final static String USAGE = "USAGE"; //$NON-NLS-1$
+
+ public final static String EQUALITY = "EQUALITY"; //$NON-NLS-1$
- public final static String TRUE = "true"; //$NON-NLS-1$
+ public final static String SYNTAX = "SYNTAX"; //$NON-NLS-1$
+
+ public final static String SUBSTR = "SUBSTR"; //$NON-NLS-1$
+
+ public final static String ORDERING = "ORDERING"; //$NON-NLS-1$
public static String getName(String schemaLine) {
StringTokenizer st = new StringTokenizer(schemaLine);
@@ -58,7 +96,7 @@
}
public static Hashtable<String, Object> parseValue(String schemaLine) {
- StringTokenizer st = new StringTokenizer(schemaLine.toLowerCase());
+ StringTokenizer st = new StringTokenizer(schemaLine);
// Skip (
st.nextToken();
@@ -71,18 +109,19 @@
ArrayList<String> values = null;
StringBuilder desc = new StringBuilder();
while (st.hasMoreTokens()) {
- String attrName = st.nextToken().toLowerCase();
- if (attrName.startsWith("x-")) { //$NON-NLS-1$
- token = st.nextToken();
+
+ String attrName = st.nextToken().toUpperCase();
+ if (attrName.startsWith(X_PREFIX)) {
+ token = st.nextToken();
// remove the ending ' symbol
token = token.substring(1, token.length() - 1);
schemaDef.put(attrName, token);
- } else if (attrName.equals("usage") || attrName.equals("equality") //$NON-NLS-1$//$NON-NLS-2$
- || attrName.equals("syntax") || attrName.equals("ordering") //$NON-NLS-1$ //$NON-NLS-2$
- || attrName.equals("substr")) { //$NON-NLS-1$
+ } else if (attrName.equals(USAGE) || attrName.equals(EQUALITY)
+ || attrName.equals(SYNTAX) || attrName.equals(ORDERING)
+ || attrName.equals(SUBSTR)) {
token = st.nextToken();
schemaDef.put(attrName, token);
- } else if (attrName.equals("desc")) { //$NON-NLS-1$
+ } else if (attrName.equals(DESC)) {
token = st.nextToken();
// remove the leading ' symbol
@@ -140,15 +179,15 @@
}
}
schemaDef.put(attrName, values);
- } else if (attrName.equals("must") || attrName.equals("sup") //$NON-NLS-1$ //$NON-NLS-2$
- || attrName.equals("may")) { //$NON-NLS-1$
+ } else if (attrName.equals(MUST) || attrName.equals(SUP)
+ || attrName.equals(MAY)) {
token = st.nextToken();
values = new ArrayList<String>();
// has multiple values
if (token.startsWith(LEFT_PARENTHESIS)) {
token = st.nextToken();
while (!token.equals(RIGHT_PARENTHESIS)) {
- if (!token.equals("$")) //$NON-NLS-1$
+ if (!token.equals(DOLLAR))
values.add(token);
token = st.nextToken();
}
@@ -156,13 +195,83 @@
values.add(token);
}
schemaDef.put(attrName, values);
- } else if (attrName.equals("abstract") || attrName.equals("structural") //$NON-NLS-1$ //$NON-NLS-2$
- || attrName.equals("auxiliary") //$NON-NLS-1$
- || attrName.equals("single-value") //$NON-NLS-1$
- || attrName.equals("no-user-modification")) { //$NON-NLS-1$
- schemaDef.put(attrName, TRUE);
+ } else if (attrName.equals(ABSTRACT) || attrName.equals(STRUCTURAL)
+ || attrName.equals(AUXILIARY)
+ || attrName.equals(SINGLE_VALUE)
+ || attrName.equals(NO_USER_MODIFICATION)) {
+ schemaDef.put(attrName, "true"); //$NON-NLS-1$
}
}
return schemaDef;
+ }
+
+ /*
+ * Format Attributes object to a string representation which can be
+ * understanded by server.
+ */
+ public static String format(Attributes attributes) throws NamingException {
+ StringBuilder builder = new StringBuilder();
+ builder.append(LEFT_PARENTHESIS);
+ builder.append(SPACE);
+
+ Attribute attribute = attributes.get(NUMERICOID);
+ // The NUMERICOID must be presented. Throw exception if not.
+ if (attribute == null) {
+ // ldap.36=Must have numeric OID
+ throw new ConfigurationException(Messages.getString("ldap.36")); //$NON-NLS-1$
+ }
+ builder.append(attribute.get());
+ builder.append(SPACE);
+
+ NamingEnumeration<String> ids = attributes.getIDs();
+
+ /*
+ * Iterate each attribute, and append the correspoind string
+ * representation for each one.
+ */
+ while (ids.hasMoreElements()) {
+ String id = ids.nextElement();
+ attribute = attributes.get(id);
+ // id is never null, so id.equals("something") can be used.
+ if (id.equals(MUST) || id.equals(MAY) || id.equals(SUP)) {
+ // Same kinds of attributes may have more than one value.
+ if (attribute.size() == 1) {
+ builder.append(id);
+ builder.append(SPACE);
+ builder.append(attribute.get());
+ builder.append(SPACE);
+ } else {
+ builder.append(id);
+ builder.append(SPACE);
+ builder.append(LEFT_PARENTHESIS);
+ builder.append(SPACE);
+ builder.append(attribute.get(0));
+ builder.append(SPACE);
+ for (int i = 1; i < attribute.size(); i++) {
+ builder.append(DOLLAR);
+ builder.append(SPACE);
+ builder.append(attribute.get(i));
+ builder.append(SPACE);
+ }
+ builder.append(RIGHT_PARENTHESIS);
+ builder.append(SPACE);
+ }
+ } else if (id.equals(ABSTRACT) || id.equals(STRUCTURAL)
+ || id.equals(AUXILIARY) || id.equals(SINGLE_VALUE)
+ || id.equals(NO_USER_MODIFICATION)) {
+ builder.append(id);
+ builder.append(SPACE);
+ } else if (!(id.equalsIgnoreCase(NUMERICOID))) {
+ builder.append(id);
+ builder.append(SPACE);
+ builder.append(SINGLE_QUOTE);
+ builder.append(attribute.get());
+ builder.append(SINGLE_QUOTE);
+ builder.append(SPACE);
+ }
+ }
+ builder.append(RIGHT_PARENTHESIS);
+
+ return builder.toString();
}
}
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=651164&r1=651163&r2=651164&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 Wed Apr 23 22:58:33 2008
@@ -17,6 +17,7 @@
package org.apache.harmony.jndi.provider.ldap;
import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.Hashtable;
import javax.naming.Binding;
@@ -25,10 +26,15 @@
import javax.naming.NameClassPair;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
import javax.naming.OperationNotSupportedException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SchemaViolationException;
import junit.framework.TestCase;
@@ -719,4 +725,263 @@
assertEquals(1, count);
}
+ public void testCreateAndDeleteSubContext() throws NamingException {
+ // Creates the attributes.
+ Attributes attrs = new BasicAttributes(false); // Ignore case
+ attrs.put("NAME", "ListObjectClass");
+ attrs.put("SUP", "top");
+ attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.77");
+ attrs.put("DESC", "for test");
+ attrs.put("STRUCTURAL", "fds");
+
+ Attribute must = new BasicAttribute("MUST", "cn");
+ must.add("objectclass");
+ attrs.put(must);
+
+ DirContext dir = schema.createSubcontext(new CompositeName(
+ "ClassDefinition/ListObjectClass"), attrs);
+
+ Attributes createdAttrs = schema
+ .getAttributes("ClassDefinition/ListObjectClass");
+
+ NamingEnumeration<? extends Attribute> enumeration = createdAttrs
+ .getAll();
+
+ int count = 0;
+ while (enumeration.hasMore()) {
+ Attribute att = enumeration.next();
+ count++;
+ }
+ assertEquals(6, count);
+
+ schema.destroySubcontext("ClassDefinition/ListObjectClass");
+ try {
+ schema.getAttributes("ClassDefinition/ListObjectClass");
+ fail("Should throw NameNotFoundException.");
+ } catch (NameNotFoundException e) {
+ // Expected.
+ }
+ }
+
+ public void testDestroySubContext_Exception() throws NamingException {
+ // No Exception.
+ schema.destroySubcontext("invalid");
+
+ try {
+ schema.destroySubcontext("invalid/invalid/invalid");
+ fail("Should throw NameNotFoundException.");
+ } catch (NameNotFoundException e) {
+ // Expected.
+ }
+
+ try {
+ schema.destroySubcontext("invalid/invalid");
+ fail("Should throw NameNotFoundException.");
+ } catch (NameNotFoundException e) {
+ // Expected.
+ }
+
+ // No Exception.
+ schema.destroySubcontext("classdefinition/invalid");
+
+ // No Exception.
+ schema.destroySubcontext("classdefinition/javaClass/name");
+
+ // No Exception.
+ schema.destroySubcontext("classdefinition/javaClass/invalid");
+
+ try {
+ schema.destroySubcontext("");
+ fail("Should throw ArrayIndexOutOfBoundsException.");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ schema.destroySubcontext("classdefinition");
+ fail("Should throw SchemaViolationException.");
+ } catch (SchemaViolationException e) {
+ // Expected.
+ }
+ }
+
+ public void testCreateSubContext_Exception() throws NamingException {
+ // Creates the attributes.
+ Attributes attrs = new BasicAttributes(false); // Ignore case
+ attrs.put("NAME", "ListObjectClass");
+ attrs.put("SUP", "top");
+ attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.77");
+ attrs.put("DESC", "for test");
+ attrs.put("STRUCTURAL", "fds");
+
+ Attribute must = new BasicAttribute("MUST", "cn");
+ must.add("objectclass");
+ attrs.put(must);
+
+ Attributes invalidAttrs = new BasicAttributes();
+
+ try {
+ schema.createSubcontext(new CompositeName("invalid"), attrs);
+ fail("Should throw SchemaViolationException.");
+ } catch (SchemaViolationException e) {
+ // Expected.
+ }
+
+ try {
+ schema.createSubcontext(new CompositeName("invalid"), invalidAttrs);
+ fail("Should throw SchemaViolationException.");
+ } catch (SchemaViolationException e) {
+ // Expected.
+ }
+
+ try {
+ schema.createSubcontext(
+ new CompositeName("invalid/invalid/invalid"), attrs);
+ fail("Should throw NameNotFoundException.");
+ } catch (NameNotFoundException e) {
+ // Expected.
+ }
+
+ try {
+ schema.createSubcontext(
+ new CompositeName("invalid/invalid/invalid"), invalidAttrs);
+ fail("Should throw NameNotFoundException.");
+ } catch (NameNotFoundException e) {
+ // Expected.
+ }
+
+ try {
+ schema
+ .createSubcontext(new CompositeName("Classdefinition"),
+ attrs);
+ fail("Should throw SchemaViolationException.");
+ } catch (SchemaViolationException e) {
+ // Expected.
+ }
+ }
+
+ public void testSubContext_OnSubSchema() throws NamingException {
+ DirContext subSchema = (DirContext) schema.lookup("classdefinition");
+
+ // Creates the attributes.
+ Attributes attrs = new BasicAttributes(false); // Ignore case
+ attrs.put("NAME", "ListObjectClass");
+ attrs.put("SUP", "top");
+ attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.77");
+ attrs.put("DESC", "for test");
+ attrs.put("STRUCTURAL", "fds");
+
+ Attribute must = new BasicAttribute("MUST", "cn");
+ must.add("objectclass");
+ attrs.put(must);
+
+ DirContext dir = subSchema.createSubcontext(new CompositeName(
+ "ListObjectClass"), attrs);
+
+ Attributes createdAttrs = dir.getAttributes("");
+
+ NamingEnumeration<? extends Attribute> enumeration = createdAttrs
+ .getAll();
+
+ int count = 0;
+ while (enumeration.hasMore()) {
+ Attribute att = enumeration.next();
+ count++;
+ }
+ assertEquals(6, count);
+
+ subSchema.destroySubcontext("ListObjectClass");
+
+ try {
+ schema.getAttributes("ClassDefinition/ListObjectClass");
+ fail("Should throw NameNotFoundException.");
+ } catch (NameNotFoundException e) {
+ // Expected.
+ }
+ }
+
+ public void test_CreateSubcontext_LName_LAttributes()
+ throws NamingException {
+ try {
+ schema.createSubcontext((Name) null, new BasicAttributes());
+ fail("Should throw NPE");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ schema.createSubcontext(new CompositeName(""), null);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ schema.createSubcontext(new CompositeName("test"), null);
+ fail("Should throw SchemaViolationException");
+ } catch (SchemaViolationException e) {
+ // expected
+ }
+ try {
+ schema.createSubcontext(new CompositeName("test"),
+ new BasicAttributes());
+ fail("Should throw SchemaViolationException");
+ } catch (SchemaViolationException e) {
+ // expected
+ }
+ }
+
+ public void test_modifyAttributes_LString_LModificationItem()
+ throws NamingException {
+ try {
+ schema.modifyAttributes((String) null, new ModificationItem[] {});
+ fail("Should throw NPE");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ schema.modifyAttributes("AttributeDefinition/dsaquality", null);
+ fail("Should throw NPE");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void test_search_LString_LAttributes_LString()
+ throws NamingException {
+ try {
+ schema
+ .search((String) null, new BasicAttributes(),
+ new String[] {});
+ fail("Should throw NPE");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testDestroySubcontextString() throws NamingException {
+ try {
+ schema.destroySubcontext((String) null);
+ fail("Should throw NPE");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void test_getNameInNamespace() throws NamingException {
+ try {
+ schema.getNameInNamespace();
+ fail("Should throw OperationNotSupportedException");
+ } catch (OperationNotSupportedException e) {
+ // expected
+ }
+ }
+
+ public void test_getSchemaClassDefinition() throws NamingException {
+ try {
+ schema.getSchemaClassDefinition(new CompositeName(""));
+ fail("Should throw OperationNotSupportedException");
+ } catch (OperationNotSupportedException e) {
+ // expected
+ }
+ }
}