From c543bd8a63f66262b7511ba5f90962a497bf0adf Mon Sep 17 00:00:00 2001
From: sin <sin@localhost>
Date: Tue, 21 Jul 2009 04:51:11 +0000
Subject: [PATCH] issue# 4120:Provide an implementation for enumeration syntax
---
opends/tests/unit-tests-testng/src/server/org/opends/server/schema/LDAPSyntaxTest.java | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 227 insertions(+), 0 deletions(-)
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/LDAPSyntaxTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/LDAPSyntaxTest.java
index e7fabb7..62664aa 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/LDAPSyntaxTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/LDAPSyntaxTest.java
@@ -40,6 +40,7 @@
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.ByteString;
+import org.opends.server.types.DN;
import org.opends.server.types.DereferencePolicy;
import org.opends.server.types.Entry;
import org.opends.server.types.ResultCode;
@@ -361,6 +362,7 @@
try
{
addRegexSyntax();
+ TestCaseUtils.initializeTestBackend(true);
//This addition should go through.
TestCaseUtils.addEntry(
"dn: cn=test,o=test",
@@ -403,6 +405,178 @@
+ /**
+ * Tests whether it is possible to add values after an enum syntax
+ * has been added.
+ *
+ * @throws java.lang.Exception
+ */
+ @Test()
+ public void testEnumSyntaxAddValues() throws Exception
+ {
+ try
+ {
+ addEnumSyntax();
+ TestCaseUtils.initializeTestBackend(true);
+
+ //This addition should fail because it doesn't match the pattern.
+ Entry entry = TestCaseUtils.makeEntry(
+ "dn: cn=syntax-test,o=test",
+ "objectclass: person",
+ "objectclass: testOC",
+ "cn: syntax-test",
+ "sn: xyz",
+ "test-attr-enum: arbit-day");
+ InternalClientConnection conn =
+ InternalClientConnection.getRootConnection();
+
+ AddOperation addOperation = conn.processAdd(entry.getDN(),
+ entry.getObjectClasses(),
+ entry.getUserAttributes(),
+ entry.getOperationalAttributes());
+ assertEquals(addOperation.getResultCode(),
+ ResultCode.INVALID_ATTRIBUTE_SYNTAX);
+
+ //This addition should go through.
+ TestCaseUtils.addEntry(
+ "dn: cn=syntax-test,o=test",
+ "objectclass: person",
+ "objectclass: testOC",
+ "cn: syntax-test",
+ "sn: xyz",
+ "test-attr-enum: sunday");
+ }
+ finally
+ {
+ deleteEnumSyntax();
+ }
+ }
+
+
+
+ /**
+ * Tests the equality-based search using enum syntax.
+ *
+ * @throws java.lang.Exception
+ */
+ @Test()
+ public void testEnumSyntaxEqualitySearch() throws Exception
+ {
+ try
+ {
+ addEnumSyntax();
+ //This addition should go through.
+ TestCaseUtils.initializeTestBackend(true);
+ TestCaseUtils.addEntry(
+ "dn: cn=test,o=test",
+ "objectclass: person",
+ "objectclass: testOC",
+ "cn: test",
+ "sn: xyz",
+ "test-attr-enum: wednesday");
+
+ InternalClientConnection conn =
+ InternalClientConnection.getRootConnection();
+
+ InternalSearchOperation searchOperation =
+ new InternalSearchOperation(
+ conn,
+ InternalClientConnection.nextOperationID(),
+ InternalClientConnection.nextMessageID(),
+ null,
+ ByteString.valueOf("cn=test,o=test"),
+ SearchScope.WHOLE_SUBTREE,
+ DereferencePolicy.NEVER_DEREF_ALIASES,
+ Integer.MAX_VALUE,
+ Integer.MAX_VALUE,
+ false,
+ LDAPFilter.decode("test-attr-enum=wednesday"),
+ null, null);
+
+ searchOperation.run();
+ assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+ List<SearchResultEntry> entries = searchOperation.getSearchEntries();
+ SearchResultEntry e = entries.get(0);
+ //An entry must be returned.
+ assertNotNull(e);
+ }
+ finally
+ {
+ deleteEnumSyntax();
+ }
+ }
+
+
+
+ /**
+ * Tests the ordering-based search using enum syntax.
+ *
+ * @throws java.lang.Exception
+ */
+ @Test()
+ public void testEnumSyntaxOrderingSearch() throws Exception
+ {
+ try
+ {
+ addEnumSyntax();
+ TestCaseUtils.initializeTestBackend(true);
+ //This addition should go through.
+ TestCaseUtils.addEntries(
+ "dn: cn=test1,o=test",
+ "objectclass: person",
+ "objectclass: testOC",
+ "cn: test1",
+ "sn: xyz",
+ "test-attr-enum: sunday",
+ "",
+ "dn: cn=test2,o=test",
+ "objectclass: person",
+ "objectclass: testOC",
+ "cn: test2",
+ "sn: xyz",
+ "test-attr-enum: monday",
+ "",
+ "dn: cn=test3,o=test",
+ "objectclass: person",
+ "objectclass: testOC",
+ "cn: test3",
+ "sn: xyz",
+ "test-attr-enum: tuesday");
+
+ InternalClientConnection conn =
+ InternalClientConnection.getRootConnection();
+
+ InternalSearchOperation searchOperation =
+ new InternalSearchOperation(
+ conn,
+ InternalClientConnection.nextOperationID(),
+ InternalClientConnection.nextMessageID(),
+ null,
+ ByteString.valueOf("o=test"),
+ SearchScope.WHOLE_SUBTREE,
+ DereferencePolicy.NEVER_DEREF_ALIASES,
+ Integer.MAX_VALUE,
+ Integer.MAX_VALUE,
+ false,
+ LDAPFilter.decode("test-attr-enum>=tuesday"),
+ null, null);
+
+ searchOperation.run();
+ assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+ List<SearchResultEntry> entries = searchOperation.getSearchEntries();
+ SearchResultEntry e = entries.get(0);
+ //An entry must be returned.
+ assertNotNull(e);
+ assertTrue(e.getDN().equals(DN.decode("cn=test1,o=test")));
+ }
+ finally
+ {
+ deleteEnumSyntax();
+ }
+ }
+
+
+
//Parses the OID from the syntax defitions.
private String getOIDFromLdapSyntax(String valueStr)
{
@@ -515,4 +689,57 @@
assertTrue(resultCode==0);
}
+
+
+
+ //Adds an enum syntax to the schema.
+ private void addEnumSyntax() throws Exception
+ {
+ //Add the enum syntax.
+ int resultCode = TestCaseUtils.applyModifications(true,
+ "dn: cn=schema",
+ "changetype: modify",
+ "add: ldapsyntaxes",
+ "ldapSyntaxes: ( 3.3.3 DESC 'Day Of The Week' " +
+ "X-ENUM ( 'monday' 'tuesday' 'wednesday' 'thursday' 'friday' 'saturday' 'sunday') )");
+ assertTrue(resultCode==0);
+
+ resultCode = TestCaseUtils.applyModifications(true,
+ "dn: cn=schema",
+ "changetype: modify",
+ "add: attributetypes",
+ "attributetypes: ( test-attr-oid NAME 'test-attr-enum' SYNTAX 3.3.3 )",
+ "-",
+ "add: objectclasses",
+ "objectclasses: ( oc-oid NAME 'testOC' SUP top AUXILIARY MUST test-attr-enum)"
+ );
+ assertTrue(resultCode == 0);
+ }
+
+
+
+ //Deletes the enum syntax from the schema.
+ private void deleteEnumSyntax() throws Exception
+ {
+ int resultCode = TestCaseUtils.applyModifications(true,
+ "dn: cn=schema",
+ "changetype: modify",
+ "delete: objectclasses",
+ "objectclasses: ( oc-oid NAME 'testOC' SUP top AUXILIARY MUST test-attr-enum)",
+ "-",
+ "delete: attributetypes",
+ "attributetypes: ( test-attr-oid NAME 'test-attr-enum' SYNTAX 3.3.3 )"
+ );
+
+ assertTrue(resultCode==0);
+
+ resultCode = TestCaseUtils.applyModifications(true,
+ "dn: cn=schema",
+ "changetype: modify",
+ "delete: ldapsyntaxes",
+ "ldapSyntaxes: ( 3.3.3 DESC 'Day Of The Week' " +
+ "X-ENUM ( 'monday' 'tuesday' 'wednesday' 'thursday' 'friday' 'saturday' 'sunday') )");
+
+ assertTrue(resultCode==0);
+ }
}
--
Gitblit v1.10.0