From 1f348a4c7e12b6e196311463ebb47b5aa941e0dc Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Fri, 21 Jul 2006 15:39:17 +0000
Subject: [PATCH] Remove the JUnit unit tests and related Ant targets.
---
/dev/null | 391 -------------------------------------------
opends/build.xml | 131 +-------------
opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestEntryContainer.java | 4
3 files changed, 9 insertions(+), 517 deletions(-)
diff --git a/opends/build.xml b/opends/build.xml
index 1960fa0..75511d6 100644
--- a/opends/build.xml
+++ b/opends/build.xml
@@ -47,9 +47,6 @@
<property name="config.dir" location="${resource.dir}/config" />
<!-- Properties for use in unit testing. -->
- <property name="unittest.dir" location="tests/unit-tests" />
- <property name="unittest.src.dir" location="${unittest.dir}/src" />
-
<property name="unittest.testng.dir" location="tests/unit-tests-testng"/>
<property name="unittest.testng.src.dir"
location="${unittest.testng.dir}/src"/>
@@ -572,7 +569,6 @@
-
<!-- Prepare to generate a code coverage report. -->
<target name="coverage" description="Generate a code coverage report.">
@@ -590,121 +586,8 @@
-
- <!-- Prepare to execute the Directory Server unit tests. -->
- <target name="testinit" depends="compile"
- description="Prepare to execute the Directory Server unit tests.">
-
- <!-- If we are to perform coverage tests, then set that up. -->
- <path id="emma.lib">
- <pathelement location="${emma.dir}/emma.jar" />
- <pathelement location="${emma.dir}/emma_ant.jar" />
- </path>
-
- <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
-
- <emma enabled="${coverage.enabled}">
- <instr instrpathref="run.classpath" destdir="${coverage.instr.dir}"
- metadatafile="${coverage.data.dir}/metadata.emma" merge="true" />
- </emma>
-
- <!-- Compile the test cases -->
- <mkdir dir="${unittest.classes.dir}" />
- <javac srcdir="${unittest.src.dir}" destdir="${unittest.classes.dir}"
- optimize="true" debug="on" debuglevel="lines,source" source="1.5"
- target="1.5" deprecation="true" fork="true" memoryInitialSize="${MEM}"
- memoryMaximumSize="${MEM}">
- <compilerarg value="-Xlint:all" />
-
- <classpath>
- <fileset dir="${lib.dir}">
- <include name="*.jar" />
- </fileset>
-
- <fileset dir="${ext.dir}">
- <include name="*.jar" />
- </fileset>
-
- <path refid="run.classpath" />
- </classpath>
- </javac>
- </target>
-
-
-
-
- <!-- Execute the Directory Server unit tests in text mode. -->
- <target name="test" depends="testinit"
- description="Execute the Directory Server unit tests in text mode.">
- <mkdir dir="${unittest.report.dir}" />
-
- <junit printsummary="withOutAndErr" fork="yes" maxmemory="${MEM}"
- haltonfailure="on">
- <classpath>
- <pathelement location="${coverage.instr.dir}" />
-
- <path refid="run.classpath" />
- <path refid="emma.lib" />
-
- <fileset dir="${lib.dir}">
- <include name="*.jar" />
- </fileset>
-
- <fileset dir="${ext.dir}">
- <include name="*.jar" />
- </fileset>
-
- <pathelement location="${unittest.classes.dir}" />
- </classpath>
-
- <jvmarg
- value="-Demma.coverage.out.file=${coverage.data.dir}/coverage.emma" />
- <jvmarg value="-Demma.coverage.out.merge=false" />
- <formatter type="xml" />
- <test todir="${unittest.report.dir}" outfile="DirectoryServerTestSuite"
- name="org.opends.server.DirectoryServerTestSuite">
- <formatter type="plain" />
- </test>
- </junit>
-
- <!-- Generate a coverage report from these test cases -->
- <emma enabled="${coverage.enabled}">
- <report sourcepath="${src.dir}">
- <fileset dir="${coverage.data.dir}">
- <include name="*.emma" />
- </fileset>
-
- <txt outfile="${coverage.report.dir}/coverage.txt" />
- <html outfile="${coverage.report.dir}/index.html" />
- </report>
- </emma>
- </target>
-
-
-
- <!-- Execute the Directory Server unit tests using a Swing GUI. -->
- <target name="testgui" depends="testinit"
- description="Execute the Directory Server unit tests in GUI mode.">
- <java classname="junit.swingui.TestRunner" fork="true" maxmemory="${MEM}">
- <arg value="org.opends.server.DirectoryServerTestSuite" />
-
- <classpath>
- <fileset dir="${lib.dir}">
- <include name="*.jar" />
- </fileset>
-
- <fileset dir="${ext.dir}">
- <include name="*.jar" />
- </fileset>
-
- <pathelement location="${classes.dir}" />
- <pathelement location="${unittest.classes.dir}" />
- </classpath>
- </java>
- </target>
-
<!-- Prepare to execute the Directory Server TestNG unit tests. -->
- <target name="testng-testinit" depends="compile"
+ <target name="testinit" depends="compile"
description="Prepare to execute the Directory Server TestNG unit tests.">
<!-- If we are to perform coverage tests, then set that up. -->
@@ -742,9 +625,11 @@
</javac>
</target>
+
+
<!-- Execute the Directory Server TestNG unit tests in text mode. -->
- <target name="testng-test"
- depends="testng-testinit"
+ <target name="test"
+ depends="testinit"
description="Execute the Directory Server TestNG unit tests in text mode.">
<mkdir dir="${unittest.report.dir}" />
@@ -779,8 +664,10 @@
</testng>
</target>
- <target name="testng-report"
- depends="testng-test"
+
+
+ <target name="testreport"
+ depends="test"
description="Takes testng results and convert them into JUnit compatible xml">
<junitreport todir="${unittest.report.dir}">
<fileset dir="${unittest.report.dir}">
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestEntryContainer.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestEntryContainer.java
index a04d644..0b31252 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestEntryContainer.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestEntryContainer.java
@@ -26,8 +26,6 @@
*/
package org.opends.server.backends.jeb;
-import static org.opends.server.loggers.Debug.addDebugLogger;
-import static org.opends.server.loggers.Debug.removeAllDebugLoggers;
import static org.testng.AssertJUnit.assertTrue;
import java.io.ByteArrayInputStream;
@@ -36,9 +34,7 @@
import java.io.OutputStreamWriter;
import java.util.ArrayList;
-import org.opends.server.InitialDirectoryServerFixture;
import org.opends.server.SchemaFixture;
-import org.opends.server.loggers.StartupDebugLogger;
import org.opends.server.types.Entry;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.util.LDIFReader;
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/ConfigurationTestCaseDependency.java b/opends/tests/unit-tests/src/server/org/opends/server/ConfigurationTestCaseDependency.java
deleted file mode 100644
index 3347958..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/ConfigurationTestCaseDependency.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server;
-
-import static org.opends.server.TestCaseUtils.copyFile;
-import static org.opends.server.TestCaseUtils.deleteDirectory;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.opends.server.config.ConfigFileHandler;
-import org.opends.server.core.DirectoryServer;
-
-/**
- * This dependency makes sure that a directory server instance is
- * available with a configuration environment loaded from the source
- * tree's resource directory.
- * <p>
- * This dependency should be used by test cases which need a directory
- * server instance with a working configuration environment.
- * <p>
- * The dependency requires the
- * {@link org.opends.server.InitialDirectoryServerTestCaseDependency}.
- *
- * @author Matthew Swift
- */
-public final class ConfigurationTestCaseDependency extends
- TestCaseDependency {
-
- // Flag used to prevent multiple initialization.
- private boolean isInitialized = false;
-
- // The name of the temporary directory used to contain the
- // configuration.
- private File tempDirectory = null;
-
- // The initial directory server dependency (required by this
- // dependency).
- private InitialDirectoryServerTestCaseDependency dependency;
-
- /**
- * Create a dependency which will make sure that the configuration
- * file located in the source tree's resource directory is loaded.
- *
- * @param dependency
- * The initial directory server dependency which this
- * dependency requires.
- */
- public ConfigurationTestCaseDependency(
- InitialDirectoryServerTestCaseDependency dependency) {
- this.dependency = dependency;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setUp() throws Exception {
- if (isInitialized == false) {
- // Make sure that the initial server is available.
- dependency.setUp();
-
- // Create temporary config file structure.
- File tempDirectory = getTempDirectory();
-
- // Create the configuration directory.
- File configDirectory = new File(tempDirectory, "config");
- configDirectory.mkdir();
-
- // All files to be copied are taken from the resource directory.
- File resourceDirectory = new File("resource");
- File configResourceDirectory = new File("resource/config");
-
- // Copy over the configuration file.
- File configFile = new File(configDirectory, "config.ldif");
- copyFile(new File(configResourceDirectory, "config.ldif"), configFile);
-
- // Configuration is dependent on JMX to register an alert generator.
- DirectoryServer.initializeJMX();
-
- DirectoryServer directoryServer = DirectoryServer.getInstance();
- directoryServer.initializeConfiguration(ConfigFileHandler.class
- .getName(), configFile.getAbsolutePath());
-
- // Prevent multiple initialization.
- isInitialized = true;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void tearDown() throws Exception {
- if (tempDirectory != null) {
- // Clean up configuration directories.
- try {
- deleteDirectory(tempDirectory);
- } catch (IOException e) {
- // Ignore errors.
- }
-
- // Reset the dependency state.
- tempDirectory = null;
- }
-
- isInitialized = false;
- }
-
- /**
- * Create a temporary directory.
- *
- * @return The temporary directory.
- * @throws IOException
- * If the temporary directory could not be created.
- */
- public File getTempDirectory() throws IOException {
- if (tempDirectory == null) {
- tempDirectory = File.createTempFile("ds7test", null);
-
- if (!tempDirectory.delete()) {
- throw new IOException("Unable to delete temporary file: "
- + tempDirectory);
- }
-
- if (!tempDirectory.mkdir()) {
- throw new IOException("Unable to create temporary directory: "
- + tempDirectory);
- }
- }
-
- return tempDirectory;
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/DirectoryServerTestCase.java b/opends/tests/unit-tests/src/server/org/opends/server/DirectoryServerTestCase.java
deleted file mode 100644
index e04f9c0..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/DirectoryServerTestCase.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server;
-
-import java.io.PrintStream;
-import java.util.LinkedList;
-import java.util.ListIterator;
-
-import junit.framework.TestCase;
-
-/**
- * This class defines a base JUnit test case that should be subclassed
- * by all unit tests used by the Directory Server.
- * <p>
- * This class offers two major benefits over
- * {@link junit.framework.TestCase}:
- * <ul>
- * <li>It adds the ability to print error messages and automatically
- * have them include the class name
- * <li>It is possible to register dependencies which are initialized
- * during the {@link #setUp()} phase and finalized during the
- * {@link #tearDown()} phase of each test.
- * </ul>
- *
- * @see org.opends.server.DirectoryServerTestSetup
- * @author Neil A. Wilson
- */
-public abstract class DirectoryServerTestCase extends TestCase {
- // The print stream to use for printing error messages.
- private PrintStream errorStream;
-
- // List of test case dependencies required by each test.
- private LinkedList<TestCaseDependency> dependencies;
-
- /**
- * Creates a new instance of this JUnit test case with the provided
- * name.
- *
- * @param name
- * The name to use for this JUnit test case.
- */
- protected DirectoryServerTestCase(String name) {
- super(name);
-
- this.errorStream = System.err;
- this.dependencies = new LinkedList<TestCaseDependency>();
- }
-
- /**
- * Register a dependency with the test case.
- *
- * @param dependency
- * The test case dependency.
- */
- public final void registerDependency(TestCaseDependency dependency) {
- dependencies.add(dependency);
- }
-
- /**
- * Prints the provided message to the error stream, prepending the
- * fully-qualified class name.
- *
- * @param message
- * The message to be printed to the error stream.
- */
- public final void printError(String message) {
- errorStream.print(getClass().getName());
- errorStream.print(" -- ");
- errorStream.println(message);
- }
-
- /**
- * Prints the stack trace for the provided exception to the error
- * stream.
- *
- * @param exception
- * The exception to be printed to the error stream.
- */
- public final void printException(Throwable exception) {
- exception.printStackTrace(errorStream);
- }
-
- /**
- * Specifies the error stream to which messages will be printed.
- *
- * @param errorStream
- * The error stream to which messages will be printed.
- */
- public final void setErrorStream(PrintStream errorStream) {
- this.errorStream = errorStream;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void setUp() throws Exception {
- // Initialize each dependency in order (oldest first).
- for (TestCaseDependency dependency : dependencies) {
- dependency.setUp();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void tearDown() throws Exception {
- // Clean up each dependency in reverse order (newest first).
- int size = dependencies.size();
-
- if (size != 0) {
- ListIterator<TestCaseDependency> i = dependencies.listIterator(size);
- while (i.hasPrevious()) {
- i.previous().tearDown();
- }
- }
- }
-
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/DirectoryServerTestSetup.java b/opends/tests/unit-tests/src/server/org/opends/server/DirectoryServerTestSetup.java
deleted file mode 100644
index de374ba..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/DirectoryServerTestSetup.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server;
-
-import java.util.LinkedList;
-import java.util.ListIterator;
-
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-
-/**
- * This class defines a base JUnit test case that can be used to express
- * test case dependencies which must only be
- * {@link org.opends.server.TestCaseDependency#setUp()} and
- * {@link org.opends.server.TestCaseDependency#tearDown()} once per test
- * case.
- *
- * @author Matthew Swift
- */
-public final class DirectoryServerTestSetup extends TestSetup {
- // List of test case dependencies required by each test.
- private LinkedList<TestCaseDependency> dependencies;
-
- /**
- * Create a directory server test which will execute setup once for
- * all tests in the specified test.
- *
- * @param test
- * The test.
- */
- public DirectoryServerTestSetup(Test test) {
- super(test);
-
- this.dependencies = new LinkedList<TestCaseDependency>();
- }
-
- /**
- * Register a dependency with the test case. The dependency is
- * evaluated only once per test case.
- *
- * @param dependency
- * The test case dependency.
- */
- public void registerDependency(TestCaseDependency dependency) {
- dependencies.add(dependency);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void setUp() throws Exception {
- // Initialize each dependency in order (oldest first).
- for (TestCaseDependency dependency : dependencies) {
- dependency.setUp();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void tearDown() throws Exception {
- // Clean up each dependency in reverse order (newest first).
- int size = dependencies.size();
-
- if (size != 0) {
- ListIterator<TestCaseDependency> i = dependencies.listIterator(size);
- while (i.hasPrevious()) {
- i.previous().tearDown();
- }
- }
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/DirectoryServerTestSuite.java b/opends/tests/unit-tests/src/server/org/opends/server/DirectoryServerTestSuite.java
deleted file mode 100644
index 0eb0d85..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/DirectoryServerTestSuite.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server;
-
-
-
-import junit.framework.*;
-import org.opends.server.core.*;
-import org.opends.server.protocols.asn1.*;
-import org.opends.server.backends.jeb.JebTestSuite;
-
-
-
-/**
- * This class defines the base test suite for the Directory Server. Whenever a
- * new set of tests are created, then they should be added into a
- * package-specific test suite, and then that package-specific suite should be
- * added to this overall test suite.
- *
- *
- * @author Neil A. Wilson
- */
-public class DirectoryServerTestSuite
- extends TestCase
-{
- /**
- * Retrieves a test suite containing all of the Directory Server tests.
- *
- * @return A test suite containing all of the Directory Server tests.
- */
- public static Test suite()
- {
- TestSuite directorySuite = new TestSuite("DirectoryServer Unit Tests");
-
- directorySuite.addTest(ASN1TestSuite.suite());
- directorySuite.addTest(JebTestSuite.suite());
- directorySuite.addTest(CoreTestSuite.suite());
-
- return directorySuite;
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/InitialDirectoryServerTestCaseDependency.java b/opends/tests/unit-tests/src/server/org/opends/server/InitialDirectoryServerTestCaseDependency.java
deleted file mode 100644
index 4309c6a..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/InitialDirectoryServerTestCaseDependency.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server;
-
-import org.opends.server.core.DirectoryServer;
-
-/**
- * This dependency makes sure that a minimal directory server instance
- * is available. Only one initialization task is performed: the
- * directory server instance is created and has its
- * {@link org.opends.server.core.DirectoryServer#bootstrapClient()}
- * method invoked.
- *
- * @author Matthew Swift
- */
-public final class InitialDirectoryServerTestCaseDependency extends
- TestCaseDependency {
-
- // Flag used to prevent multiple initialization.
- private boolean isInitialized = false;
-
- /**
- * Create a dependency which will make sure that a minimal directory
- * server instance is available.
- */
- public InitialDirectoryServerTestCaseDependency() {
- // No implementation required.
- }
-
- /**
- * {@inheritDoc}
- */
- public void setUp() throws Exception {
- if (isInitialized == false) {
- // Make sure a new instance is created.
- //
- // This is effectively a no-op at the moment, but may do lazy
- // initialization at some point.
- DirectoryServer.getInstance();
-
- // Initialize minimal features such as key syntaxes.
- DirectoryServer.bootstrapClient();
-
- // Prevent multiple initialization.
- isInitialized = true;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void tearDown() throws Exception {
- // TODO: finalize the server instance?
-
- isInitialized = false;
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/SchemaTestCaseDependency.java b/opends/tests/unit-tests/src/server/org/opends/server/SchemaTestCaseDependency.java
deleted file mode 100644
index da0a1ed..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/SchemaTestCaseDependency.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server;
-
-import static org.opends.server.TestCaseUtils.copyDirectory;
-
-import java.io.File;
-
-import org.opends.server.core.DirectoryServer;
-
-/**
- * This dependency makes sure that a directory server instance is
- * available with the core schema files loaded from the source tree's
- * resource directory.
- * <p>
- * This dependency should be used by test cases which need a directory
- * server instance with core schema files loaded.
- * <p>
- * The dependency requires the
- * {@link org.opends.server.ConfigurationTestCaseDependency} dependency.
- *
- * @author Matthew Swift
- */
-public final class SchemaTestCaseDependency extends TestCaseDependency {
-
- // Flag used to prevent multiple initialization.
- private boolean isInitialized = false;
-
- // The configuration dependency (required by this dependency).
- private ConfigurationTestCaseDependency dependency;
-
- /**
- * Create a dependency which will make sure that the core schema files
- * are loaded.
- *
- * @param dependency
- * The configuration dependency which this dependency
- * requires.
- */
- public SchemaTestCaseDependency(ConfigurationTestCaseDependency dependency) {
- this.dependency = dependency;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setUp() throws Exception {
- if (isInitialized == false) {
- // Make sure that the core configuration is available.
- dependency.setUp();
-
- // Copy over the schema files.
- File tempDirectory = dependency.getTempDirectory();
- File configDirectory = new File(tempDirectory, "config");
- File schemaDirectory = new File(configDirectory, "schema");
- File resourceDirectory = new File("resource");
- copyDirectory(new File(resourceDirectory, "schema"), schemaDirectory);
-
- // Initialize and load the schema files.
- DirectoryServer.getInstance().initializeSchema();
-
- // Prevent multiple initialization.
- isInitialized = true;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void tearDown() throws Exception {
- // TODO: clean up the schema?
-
- isInitialized = false;
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/TestCaseDependency.java b/opends/tests/unit-tests/src/server/org/opends/server/TestCaseDependency.java
deleted file mode 100644
index 3330cb1..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/TestCaseDependency.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server;
-
-/**
- * An abstract class used to implement test case dependencies.
- * <p>
- * A test case should create dependencies and initialize them during its
- * {@link junit.framework.TestCase#setUp()} phase. Dependencies should
- * then be finalized during the
- * {@link junit.framework.TestCase#tearDown()} phase.
- *
- * @author Matthew Swift
- */
-public abstract class TestCaseDependency {
-
- /**
- * Create a new abstract test case dependency.
- */
- protected TestCaseDependency() {
- // No implementation required.
- }
-
- /**
- * Initialize the test case dependency.
- *
- * @throws Exception
- * If the dependency could not be initialized.
- */
- public abstract void setUp() throws Exception;
-
- /**
- * Clean up resources owned by the test case dependency.
- *
- * @throws Exception
- * If clean up failed for some reason.
- */
- public void tearDown() throws Exception {
- // No-op default implementation.
- }
-
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/TestCaseUtils.java b/opends/tests/unit-tests/src/server/org/opends/server/TestCaseUtils.java
deleted file mode 100644
index 39f38f2..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/TestCaseUtils.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * This class defines some utility functions which can be used by test
- * cases.
- *
- * @author Matthew Swift
- */
-public final class TestCaseUtils {
-
- /**
- * Copy a directory and its contents.
- *
- * @param src
- * The name of the directory to copy.
- * @param dst
- * The name of the destination directory.
- * @throws IOException
- * If the directory could not be copied.
- */
- public static void copyDirectory(File src, File dst) throws IOException {
- if (src.isDirectory()) {
- // Create the destination directory if it does not exist.
- if (!dst.exists()) {
- dst.mkdir();
- }
-
- // Recursively copy sub-directories and files.
- for (String child : src.list()) {
- copyDirectory(new File(src, child), new File(dst, child));
- }
- } else {
- copyFile(src, dst);
- }
- }
-
- /**
- * Delete a directory and its contents.
- *
- * @param dir
- * The name of the directory to delete.
- * @throws IOException
- * If the directory could not be deleted.
- */
- public static void deleteDirectory(File dir) throws IOException {
- if (dir.isDirectory()) {
- // Recursively delete sub-directories and files.
- for (String child : dir.list()) {
- deleteDirectory(new File(dir, child));
- }
- }
-
- dir.delete();
- }
-
- /**
- * Copy a file.
- *
- * @param src
- * The name of the source file.
- * @param dst
- * The name of the destination file.
- * @throws IOException
- * If the file could not be copied.
- */
- public static void copyFile(File src, File dst) throws IOException {
- InputStream in = new FileInputStream(src);
- OutputStream out = new FileOutputStream(dst);
-
- // Transfer bytes from in to out
- byte[] buf = new byte[8192];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- in.close();
- out.close();
- }
-
- /**
- * Prevent instantiation.
- */
- private TestCaseUtils() {
- // No implementation.
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/JebTestSuite.java b/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/JebTestSuite.java
deleted file mode 100644
index 5b29ce8..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/JebTestSuite.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.backends.jeb;
-
-import junit.framework.TestCase;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * This class defines a JUnit test suite that will launch all the tests for the
- * classes in the Jeb package. Whenever a new Jeb test class is defined,
- * this suite should be updated to include it.
- *
- */
-public class JebTestSuite
- extends TestCase
-{
- /**
- * Retrieves a test suite containing all of the Jeb tests.
- *
- * @return A test suite containing all of the Jeb tests.
- */
- public static Test suite()
- {
- TestSuite jebSuite = new TestSuite("Jeb Unit Tests");
-
- jebSuite.addTestSuite(TestJebFormat.class);
- jebSuite.addTestSuite(TestEnvManager.class);
- jebSuite.addTestSuite(TestEntryContainer.class);
- jebSuite.addTestSuite(TestBackendImpl.class);
-
- return jebSuite;
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestBackendImpl.java b/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestBackendImpl.java
deleted file mode 100644
index 7627773..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestBackendImpl.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.backends.jeb;
-
-import org.opends.server.DirectoryServerTestCase;
-import org.opends.server.api.Backend;
-import org.opends.server.util.StaticUtils;
-import org.opends.server.util.LDIFReader;
-import org.opends.server.util.Base64;
-import org.opends.server.core.*;
-import org.opends.server.config.ConfigEntry;
-import org.opends.server.types.*;
-
-import java.io.File;
-import java.io.ByteArrayInputStream;
-
-/**
- * BackendImpl Tester.
- *
- * @author Andy Coulbeck
- */
-public class TestBackendImpl extends DirectoryServerTestCase
-{
- private String homeDirName;
-
- private static final String ldifString =
- "dn: cn=JE Backend,cn=Backends,cn=config\n" +
- "objectClass: top\n" +
- "objectClass: ds-cfg-backend\n" +
- "objectClass: extensibleObject\n" +
- "cn: JE Backend\n" +
- "ds-cfg-backend-enabled: true\n" +
- "ds-cfg-backend-class: org.opends.server.backends.jeb.BackendImpl\n" +
- "ds-cfg-backend-directory: db\n";
-
- private Entry entry;
-
- public TestBackendImpl(String name)
- {
- super(name);
- }
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- DirectoryServer.bootstrapClient();
- DirectoryServer.initializeJMX();
-
- File tempFile = File.createTempFile("jebtest", "");
- tempFile.delete();
- homeDirName = tempFile.getAbsolutePath();
-
- final String s = ldifString.replaceAll("ds-cfg-backend-directory: db",
- "ds-cfg-backend-directory:: " +
- Base64.encode(homeDirName.getBytes()));
- byte[] bytes = StaticUtils.getBytes(s);
-
- LDIFReader reader = new LDIFReader(
- new LDIFImportConfig(new ByteArrayInputStream(bytes)));
-
- entry = reader.readEntry(false);
- reader.close();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- File homeDir = new File(homeDirName);
- homeDir.delete();
- }
-
- public void testFinalize() throws Exception
- {
- File homeDir = new File(homeDirName);
- homeDir.mkdir();
- ConfigEntry configEntry = new ConfigEntry(entry, null);
- DN[] baseDNs = new DN[] { DN.decode("dc=com") };
- Backend backend = new BackendImpl();
- for (int i = 0; i < 10; i++)
- {
- backend.initializeBackend(configEntry, baseDNs);
- try
- {
- backend.getEntry(DN.decode("dc=com"));
- } catch (DirectoryException e)
- {
- }
- backend.finalizeBackend();
- }
- }
-
-
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestEntryContainer.java b/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestEntryContainer.java
deleted file mode 100644
index b6defbe..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestEntryContainer.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.backends.jeb;
-
-import static org.opends.server.loggers.Debug.removeAllDebugLoggers;
-import static org.opends.server.loggers.Debug.addDebugLogger;
-import org.opends.server.DirectoryServerTestCase;
-import org.opends.server.loggers.StartupDebugLogger;
-import org.opends.server.util.LDIFReader;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.Entry;
-import org.opends.server.types.LDIFImportConfig;
-import com.sleepycat.je.EnvironmentConfig;
-import com.sleepycat.je.Environment;
-
-import java.io.File;
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.ByteArrayInputStream;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.ArrayList;
-
-/**
- * EntryContainer tester.
- *
- * @author Andy Coulbeck
- */
-public class TestEntryContainer extends DirectoryServerTestCase
-{
- private static final String ldifString =
- "dn: dc=com\n" +
- "objectClass: top\n" +
- "objectClass: domain\n" +
- "\n" +
- "dn: dc=example,dc=com\n" +
- "objectClass: top\n" +
- "objectClass: domain\n" +
- "\n" +
- "dn: ou=People,dc=example,dc=com\n" +
- "objectClass: top\n" +
- "objectClass: organizationalUnit\n" +
- "\n" +
- "dn: uid=user.1,ou=People,dc=example,dc=com\n" +
- "objectClass: top\n" +
- "objectClass: person\n" +
- "objectClass: organizationalPerson\n" +
- "objectClass: inetOrgPerson\n" +
- "uid: user.1\n" +
- "homePhone: 951-245-7634\n" +
- "description: This is the description for Aaccf Amar.\n" +
- "st: NC\n" +
- "mobile: 027-085-0537\n" +
- "postalAddress: Aaccf Amar$17984 Thirteenth Street"
- + "$Rockford, NC 85762\n" +
- "mail: user.1@example.com\n" +
- "cn: Aaccf Amar\n" +
- "l: Rockford\n" +
- "pager: 508-763-4246\n" +
- "street: 17984 Thirteenth Street\n" +
- "telephoneNumber: 216-564-6748\n" +
- "employeeNumber: 1\n" +
- "sn: Amar\n" +
- "givenName: Aaccf\n" +
- "postalCode: 85762\n" +
- "userPassword: password\n" +
- "initials: AA\n" +
- "\n" +
- "dn: o=Airius\n" +
- "objectClass: top\n" +
- "objectClass: organization\n" +
- "\n" +
- "dn:: b3U95Za25qWt6YOoLG89QWlyaXVz\n" +
- "# dn:: ou=<JapaneseOU>,o=Airius\n" +
- "objectclass: top\n" +
- "objectclass: organizationalUnit\n" +
- "ou:: 5Za25qWt6YOo\n" +
- "# ou:: <JapaneseOU>\n" +
- "ou;lang-ja:: 5Za25qWt6YOo\n" +
- "# ou;lang-ja:: <JapaneseOU>\n" +
- "ou;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2\n" +
- "# ou;lang-ja:: <JapaneseOU_in_phonetic_representation>\n" +
- "ou;lang-en: Sales\n" +
- "description: Japanese office\n" +
- "\n" +
- "dn:: dWlkPXJvZ2FzYXdhcmEsb3U95Za25qWt6YOoLG89QWlyaXVz\n" +
- "# dn:: uid=<uid>,ou=<JapaneseOU>,o=Airius\n" +
- "userpassword: {SHA}O3HSv1MusyL4kTjP+HKI5uxuNoM=\n" +
- "objectclass: top\n" +
- "objectclass: person\n" +
- "objectclass: organizationalPerson\n" +
- "objectclass: inetOrgPerson\n" +
- "uid: rogasawara\n" +
- "mail: rogasawara@airius.co.jp\n" +
- "givenname;lang-ja:: 44Ot44OJ44OL44O8\n" +
- "# givenname;lang-ja:: <JapaneseGivenname>\n" +
- "sn;lang-ja:: 5bCP56yg5Y6f\n" +
- "# sn;lang-ja:: <JapaneseSn>\n" +
- "cn;lang-ja:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n" +
- "# cn;lang-ja:: <JapaneseCn>\n" +
- "title;lang-ja:: 5Za25qWt6YOoIOmDqOmVtw==\n" +
- "# title;lang-ja:: <JapaneseTitle>\n" +
- "preferredlanguage: ja\n" +
- "givenname:: 44Ot44OJ44OL44O8\n" +
- "# givenname:: <JapaneseGivenname>\n" +
- "sn:: 5bCP56yg5Y6f\n" +
- "# sn:: <JapaneseSn>\n" +
- "cn:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n" +
- "# cn:: <JapaneseCn>\n" +
- "title:: 5Za25qWt6YOoIOmDqOmVtw==\n" +
- "# title:: <JapaneseTitle>\n" +
- "givenname;lang-ja;phonetic:: 44KN44Gp44Gr44O8\n" +
- "# givenname;lang-ja;phonetic:: " +
- "<JapaneseGivenname_in_phonetic_representation_kana>\n" +
- "sn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJ\n" +
- "# sn;lang-ja;phonetic:: " +
- "<JapaneseSn_in_phonetic_representation_kana>\n" +
- "cn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJIOOCjeOBqeOBq+ODvA==\n" +
- "# cn;lang-ja;phonetic:: " +
- "<JapaneseCn_in_phonetic_representation_kana>\n" +
- "title;lang-ja;phonetic:: " + "" +
- "44GI44GE44GO44KH44GG44G2IOOBtuOBoeOCh+OBhg==\n" +
- "# title;lang-ja;phonetic::\n" +
- "# <JapaneseTitle_in_phonetic_representation_kana>\n" +
- "givenname;lang-en: Rodney\n" +
- "sn;lang-en: Ogasawara\n" +
- "cn;lang-en: Rodney Ogasawara\n" +
- "title;lang-en: Sales, Director\n" +
- "\n" +
- ""
- ;
-
- private String homeDirName;
- private ArrayList<Entry> entryList;
- private long calculatedHighestID = 0;
-
- public TestEntryContainer(String name)
- {
- super(name);
- }
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- DirectoryServer.bootstrapClient();
- removeAllDebugLoggers(true);
- StartupDebugLogger startupDebugLogger = new StartupDebugLogger();
- startupDebugLogger.initializeDebugLogger(null);
- addDebugLogger(startupDebugLogger);
-
- File tempFile = File.createTempFile("jebtest", "");
- tempFile.delete();
- homeDirName = tempFile.getAbsolutePath();
-
- // Convert the test LDIF string to a byte array
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
- byteArrayOutputStream);
- outputStreamWriter.write(ldifString);
- outputStreamWriter.flush();
- byte[] originalLDIFBytes = byteArrayOutputStream.toByteArray();
-
- LDIFReader reader = new LDIFReader(
- new LDIFImportConfig(new ByteArrayInputStream(originalLDIFBytes)));
-
- // Create a set of entries
- entryList = new ArrayList<Entry>();
- long entryID = 0;
- Entry entry;
- while ((entry = reader.readEntry(false)) != null)
- {
- entryID++;
- entryList.add(entry);
- }
-
- // Remember the highest entryID
- calculatedHighestID = entryID;
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- File homeDir = new File(homeDirName);
- homeDir.delete();
- }
-
- public void test1() throws Exception
- {
- EnvManager.createHomeDir(homeDirName);
- EnvironmentConfig envConfig = new EnvironmentConfig();
- envConfig.setTransactional(true);
- envConfig.setAllowCreate(true);
- Environment env = new Environment(new File(homeDirName), envConfig);
- EntryContainer entryContainer = new EntryContainer(null, new Config(),
- new Container(env, null));
-
- entryContainer.open();
- EntryID actualHighestID = entryContainer.getHighestEntryID();
- assertTrue(actualHighestID.equals(new EntryID(0)));
-
- EntryID.initialize(actualHighestID);
- for (Entry entry : entryList)
- {
- entryContainer.addEntry(entry, null);
- Entry afterEntry = entryContainer.getEntry(entry.getDN());
- assertTrue(afterEntry != null);
- }
- actualHighestID = entryContainer.getHighestEntryID();
- assertTrue(actualHighestID.equals(new EntryID(calculatedHighestID)));
-
- entryContainer.close();
-
- env.close();
- EnvManager.removeFiles(homeDirName);
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestEnvManager.java b/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestEnvManager.java
deleted file mode 100644
index 2264672..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestEnvManager.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.backends.jeb;
-
-import org.opends.server.DirectoryServerTestCase;
-import com.sleepycat.je.EnvironmentConfig;
-import com.sleepycat.je.Environment;
-
-import java.io.File;
-
-import junit.framework.AssertionFailedError;
-
-/**
- * EnvManager Tester.
- *
- * @author Andy Coulbeck
- */
-public class TestEnvManager extends DirectoryServerTestCase
-{
- private String homeDirName;
-
- public TestEnvManager(String name)
- {
- super(name);
- }
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- File tempFile = File.createTempFile("jebtest", "");
- tempFile.delete();
- homeDirName = tempFile.getAbsolutePath();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- File homeDir = new File(homeDirName);
- homeDir.delete();
- }
-
- public void testValidHomeDir() throws Exception
- {
- File homeDir = new File(homeDirName);
-
- EnvManager.createHomeDir(homeDirName);
- EnvironmentConfig envConfig = new EnvironmentConfig();
- envConfig.setTransactional(true);
- envConfig.setAllowCreate(true);
- Environment env = new Environment(new File(homeDirName), envConfig);
- env.close();
-
- try
- {
- assertTrue(homeDir.list().length > 0);
- }
- catch (AssertionFailedError e)
- {
- printError("No files created in homedir " + homeDirName +
- " during environment open");
- }
-
- EnvManager.removeFiles(homeDirName);
-
- try
- {
- assertTrue(homeDir.list().length == 0);
- }
- catch (AssertionFailedError e)
- {
- printError("Files remaining in homedir " + homeDirName + " after removal");
- }
- }
-
- public void testInvalidHomeDir() throws Exception
- {
- File tempFile = File.createTempFile("jebtest", "");
- tempFile.deleteOnExit();
-
- String invalidHomeDirName = tempFile.getAbsolutePath();
-
- boolean exceptionCaught = false;
- try
- {
- EnvManager.createHomeDir(invalidHomeDirName);
- }
- catch (JebException e)
- {
- exceptionCaught = true;
- }
-
- try
- {
- assertTrue(exceptionCaught);
- }
- catch (AssertionFailedError e)
- {
- printError("Unexpected successful creation of invalid home directory");
- }
-
- }
-
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestJebFormat.java b/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestJebFormat.java
deleted file mode 100644
index 17be5c3..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/backends/jeb/TestJebFormat.java
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.backends.jeb;
-
-import org.opends.server.util.LDIFReader;
-import org.opends.server.util.StaticUtils;
-import org.opends.server.core.*;
-import org.opends.server.DirectoryServerTestCase;
-import org.opends.server.types.*;
-
-import java.io.ByteArrayInputStream;
-import java.util.List;
-import java.util.Arrays;
-
-import junit.framework.AssertionFailedError;
-
-/**
- * JebFormat Tester.
- *
- * @author Andy Coulbeck
- */
-public class TestJebFormat extends DirectoryServerTestCase
-{
- public TestJebFormat(String name)
- {
- super(name);
- }
-
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- private static final String ldifString =
- "dn: uid=user.1,ou=People,dc=example,dc=com\n" +
- "objectClass: top\n" +
- "objectClass: person\n" +
- "objectClass: organizationalPerson\n" +
- "objectClass: inetOrgPerson\n" +
- "uid: user.1\n" +
- "homePhone: 951-245-7634\n" +
- "description: This is the description for Aaccf Amar.\n" +
- "st: NC\n" +
- "mobile: 027-085-0537\n" +
- "postalAddress: Aaccf Amar$17984 Thirteenth Street"
- + "$Rockford, NC 85762\n" +
- "mail: user.1@example.com\n" +
- "cn: Aaccf Amar\n" +
- "l: Rockford\n" +
- "pager: 508-763-4246\n" +
- "street: 17984 Thirteenth Street\n" +
- "telephoneNumber: 216-564-6748\n" +
- "employeeNumber: 1\n" +
- "sn: Amar\n" +
- "givenName: Aaccf\n" +
- "postalCode: 85762\n" +
- "userPassword: password\n" +
- "initials: AA\n" +
- "\n" +
- "dn:: b3U95Za25qWt6YOoLG89QWlyaXVz\n" +
- "# dn:: ou=<JapaneseOU>,o=Airius\n" +
- "objectclass: top\n" +
- "objectclass: organizationalUnit\n" +
- "ou:: 5Za25qWt6YOo\n" +
- "# ou:: <JapaneseOU>\n" +
- "ou;lang-ja:: 5Za25qWt6YOo\n" +
- "# ou;lang-ja:: <JapaneseOU>\n" +
- "ou;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2\n" +
- "# ou;lang-ja:: <JapaneseOU_in_phonetic_representation>\n" +
- "ou;lang-en: Sales\n" +
- "description: Japanese office\n" +
- "\n" +
- "dn:: dWlkPXJvZ2FzYXdhcmEsb3U95Za25qWt6YOoLG89QWlyaXVz\n" +
- "# dn:: uid=<uid>,ou=<JapaneseOU>,o=Airius\n" +
- "userpassword: {SHA}O3HSv1MusyL4kTjP+HKI5uxuNoM=\n" +
- "objectclass: top\n" +
- "objectclass: person\n" +
- "objectclass: organizationalPerson\n" +
- "objectclass: inetOrgPerson\n" +
- "uid: rogasawara\n" +
- "mail: rogasawara@airius.co.jp\n" +
- "givenname;lang-ja:: 44Ot44OJ44OL44O8\n" +
- "# givenname;lang-ja:: <JapaneseGivenname>\n" +
- "sn;lang-ja:: 5bCP56yg5Y6f\n" +
- "# sn;lang-ja:: <JapaneseSn>\n" +
- "cn;lang-ja:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n" +
- "# cn;lang-ja:: <JapaneseCn>\n" +
- "title;lang-ja:: 5Za25qWt6YOoIOmDqOmVtw==\n" +
- "# title;lang-ja:: <JapaneseTitle>\n" +
- "preferredlanguage: ja\n" +
- "givenname:: 44Ot44OJ44OL44O8\n" +
- "# givenname:: <JapaneseGivenname>\n" +
- "sn:: 5bCP56yg5Y6f\n" +
- "# sn:: <JapaneseSn>\n" +
- "cn:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n" +
- "# cn:: <JapaneseCn>\n" +
- "title:: 5Za25qWt6YOoIOmDqOmVtw==\n" +
- "# title:: <JapaneseTitle>\n" +
- "givenname;lang-ja;phonetic:: 44KN44Gp44Gr44O8\n" +
- "# givenname;lang-ja;phonetic:: " +
- "<JapaneseGivenname_in_phonetic_representation_kana>\n" +
- "sn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJ\n" +
- "# sn;lang-ja;phonetic:: " +
- "<JapaneseSn_in_phonetic_representation_kana>\n" +
- "cn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJIOOCjeOBqeOBq+ODvA==\n" +
- "# cn;lang-ja;phonetic:: " +
- "<JapaneseCn_in_phonetic_representation_kana>\n" +
- "title;lang-ja;phonetic:: " + "" +
- "44GI44GE44GO44KH44GG44G2IOOBtuOBoeOCh+OBhg==\n" +
- "# title;lang-ja;phonetic::\n" +
- "# <JapaneseTitle_in_phonetic_representation_kana>\n" +
- "givenname;lang-en: Rodney\n" +
- "sn;lang-en: Ogasawara\n" +
- "cn;lang-en: Rodney Ogasawara\n" +
- "title;lang-en: Sales, Director\n" +
- "\n" +
- ""
- ;
-
- public void testEntryIDToAndFromDatabase() throws Exception
- {
- long[] vals = { 128, 1234567, 0, 1, -1, 2^32-1, 2^63-1 };
-
- for (long before : vals)
- {
- byte[] bytes = JebFormat.entryIDToDatabase(before);
- long after = JebFormat.entryIDFromDatabase(bytes);
- try
- {
- assertTrue(before == after);
- }
- catch (AssertionFailedError e)
- {
- printError(String.format("before=%d after=%d bytes=%s",
- new Long(before),
- new Long(after),
- StaticUtils.bytesToHex(bytes)));
- throw e;
- }
- }
- }
-
- private void entryIDListToAndFromDatabase(long[] before) throws Exception
- {
- byte[] bytes = JebFormat.entryIDListToDatabase(before);
-/*
- printError(String.format("encoded count=%d len=%d",
- before.length, bytes.length));
-*/
- long[] after = JebFormat.entryIDListFromDatabase(bytes);
-
- try
- {
- assertTrue(Arrays.equals(before, after));
- }
- catch (AssertionFailedError e)
- {
- printError("Entry ID list corrupted in conversion to and from database");
- throw e;
- }
- }
-
- public void testEntryIDListToAndFromDatabase() throws Exception
- {
- long[] array;
- array = new long[] { 1, 2, 3, 4, 5 };
- entryIDListToAndFromDatabase(array);
- array = new long[] { 999999 };
- entryIDListToAndFromDatabase(array);
- array = new long[] { 1, 128, 1234567 };
- entryIDListToAndFromDatabase(array);
- array = new long[100000];
- for (int i = 0; i < 100000; i++)
- {
- array[i] = i*2+1;
- }
- entryIDListToAndFromDatabase(array);
- }
-
- public void testEntryToAndFromDatabase() throws Exception
- {
- DirectoryServer.bootstrapClient();
-
- // Convert the test LDIF string to a byte array
- byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
-
- LDIFReader reader = new LDIFReader(
- new LDIFImportConfig(new ByteArrayInputStream(originalLDIFBytes)));
-
- Entry entryBefore, entryAfter;
- while ((entryBefore = reader.readEntry(false)) != null)
- {
- byte[] bytes = JebFormat.entryToDatabase(entryBefore);
-
- entryAfter = JebFormat.entryFromDatabase(bytes);
-
- // check DN and number of attributes
- try
- {
- assertTrue(entryBefore.getAttributes().size() ==
- entryAfter.getAttributes().size());
- }
- catch (AssertionFailedError e)
- {
- printError("Differing number of attributes in before and after entry");
- throw e;
- }
- try
- {
- assertTrue(entryBefore.getDN().equals(entryAfter.getDN()));
- }
- catch (AssertionFailedError e)
- {
- printError("DNs are not equal in before and after entry");
- throw e;
- }
-
- // check the object classes were not changed
- for (String ocBefore : entryBefore.getObjectClasses().values())
- {
- ObjectClass objectClass =
- DirectoryServer.getObjectClass(ocBefore.toLowerCase());
- if (objectClass == null)
- {
- objectClass = DirectoryServer.getDefaultObjectClass(ocBefore);
- }
- String ocAfter = entryAfter.getObjectClasses().get(objectClass);
-
- try
- {
- assertTrue(ocBefore.equals(ocAfter));
- }
- catch (AssertionFailedError e)
- {
- String message = String.format("objectClass %s != %s",
- ocBefore, ocAfter);
- printError(message);
- throw e;
- }
- }
-
- // check the user attributes were not changed
- for (AttributeType attrType : entryBefore.getUserAttributes().keySet())
- {
- List<Attribute> listBefore = entryBefore.getAttribute(attrType);
- List<Attribute> listAfter = entryAfter.getAttribute(attrType);
- try
- {
- assertTrue(listAfter != null);
- }
- catch (AssertionFailedError e)
- {
- String msg = String.format(
- "attribute type %s was lost in translation",
- attrType);
- printError(msg);
- throw e;
- }
- try
- {
- assertTrue(listBefore.size() == listAfter.size());
- }
- catch (AssertionFailedError e)
- {
- String msg = String.format("Differing number of values of type %s",
- attrType);
- printError(msg);
- throw e;
- }
- for (Attribute attrBefore : listBefore)
- {
- for (Attribute attrAfter : listAfter)
- {
- if (attrAfter.optionsEqual(attrBefore.getOptions()))
- {
- // Found the corresponding attribute
-
- String beforeAttrString = attrBefore.toString();
- String afterAttrString = attrAfter.toString();
-
- if (!beforeAttrString.equals(afterAttrString))
- {
- System.out.printf(
- "Original attr:\n%s\nRetrieved attr:\n%s\n\n",
- beforeAttrString,
- afterAttrString);
- }
-
- try
- {
- assertTrue(beforeAttrString.equals(afterAttrString));
- }
- catch (AssertionFailedError e)
- {
- String msg = String.format("attribute %s was changed",
- attrBefore);
- printError(msg);
- throw e;
- }
- }
- }
- }
- }
- }
- reader.close();
- }
-
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/core/CoreTestSuite.java b/opends/tests/unit-tests/src/server/org/opends/server/core/CoreTestSuite.java
deleted file mode 100644
index c8ef3ed..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/core/CoreTestSuite.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.core;
-
-
-
-import junit.framework.*;
-
-
-
-/**
- * This class defines a JUnit test suite that will launch all the tests for the
- * classes in the core. Whenever a new core test class is defined,
- * this suite should be updated to include it.
- *
- *
- * @author Neil A. Wilson
- */
-public class CoreTestSuite
- extends TestCase
-{
- /**
- * Retrieves a test suite containing all of the core tests.
- *
- * @return A test suite containing all of the core tests.
- */
- public static Test suite()
- {
- TestSuite coreSuite = new TestSuite("Directory Core Unit Tests");
-
- coreSuite.addTest(TestDN.getTestSuite());
- coreSuite.addTest(TestRFC3672SubtreeSpecification.getTestSuite());
- coreSuite.addTest(TestRelativeSubtreeSpecification.getTestSuite());
- coreSuite.addTest(TestAbsoluteSubtreeSpecification.getTestSuite());
- coreSuite.addTest(TestEntry.getTestSuite());
-
- return coreSuite;
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/core/TestAbsoluteSubtreeSpecification.java b/opends/tests/unit-tests/src/server/org/opends/server/core/TestAbsoluteSubtreeSpecification.java
deleted file mode 100644
index d702e31..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/core/TestAbsoluteSubtreeSpecification.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.core;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.opends.server.ConfigurationTestCaseDependency;
-import org.opends.server.DirectoryServerTestCase;
-import org.opends.server.DirectoryServerTestSetup;
-import org.opends.server.InitialDirectoryServerTestCaseDependency;
-import org.opends.server.SchemaTestCaseDependency;
-import org.opends.server.api.SubtreeSpecification;
-import org.opends.server.types.*;
-
-/**
- * This class defines a set of JUnit tests for the
- * {@link org.opends.server.core.AbsoluteSubtreeSpecification} class.
- * <p>
- * This test suite is shorter than the RFC 3672 test suite because it
- * focuses on testing only the pieces of functionality that are specific
- * to the syntax.
- *
- * @author Matthew Swift
- */
-public final class TestAbsoluteSubtreeSpecification extends
- DirectoryServerTestCase {
-
- // Cached set of entry object classes.
- private Set<ObjectClass> objectClasses;
-
- /**
- * Simple wrapper for creating entries that can be filtered.
- */
- private static class FilterableEntryImpl extends Entry {
- public static HashMap<ObjectClass, String> getObjectClasses(
- Set<ObjectClass> objectClasses) {
- HashMap<ObjectClass, String> map = new HashMap<ObjectClass, String>();
-
- for (ObjectClass oc : objectClasses) {
- if (oc != null) {
- map.put(oc, oc.getNameOrOID());
- }
- }
-
- return map;
- }
-
- /**
- * Construct a filterable entry from a DN and set of object classes.
- * It will not contain any attributes.
- *
- * @param entryDN
- * The entry's DN.
- * @param objectClasses
- * The entry's object classes.
- */
- public FilterableEntryImpl(DN entryDN, Set<ObjectClass> objectClasses) {
- super(entryDN, getObjectClasses(objectClasses), null, null);
- }
- }
-
- /**
- * Get the absolute subtree specification test suite.
- *
- * @return The test suite.
- */
- public static Test getTestSuite() {
- // Create the basic test suite.
- TestSuite suite = new TestSuite();
- suite.addTestSuite(TestAbsoluteSubtreeSpecification.class);
-
- // Wrap it up with dependencies.
- DirectoryServerTestSetup wrapper = new DirectoryServerTestSetup(suite);
-
- InitialDirectoryServerTestCaseDependency initial;
- initial = new InitialDirectoryServerTestCaseDependency();
- wrapper.registerDependency(initial);
-
- ConfigurationTestCaseDependency config;
- config = new ConfigurationTestCaseDependency(initial);
- wrapper.registerDependency(config);
-
- SchemaTestCaseDependency schema;
- schema = new SchemaTestCaseDependency(config);
- wrapper.registerDependency(schema);
-
- return wrapper;
- }
-
- /**
- * Creates a new instance of this JUnit test case with the provided
- * name.
- *
- * @param name
- * The name to use for this JUnit test case.
- */
- public TestAbsoluteSubtreeSpecification(String name) {
- super(name);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setUp() throws Exception {
- super.setUp();
-
- objectClasses = new HashSet<ObjectClass>();
-
- ObjectClass oc = DirectoryServer.getObjectClass("top");
- if (oc == null) {
- throw new RuntimeException("Unable to resolve object class top");
- }
- objectClasses.add(oc);
-
- oc = DirectoryServer.getObjectClass("person");
- if (oc == null) {
- throw new RuntimeException("Unable to resolve object class person");
- }
- objectClasses.add(oc);
- }
-
- /**
- * {@inheritDoc}
- */
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * Tests the {@link AbsoluteSubtreeSpecification#valueOf(String)}
- * method.
- */
- public void testValueOf1() throws DirectoryException {
- String input = "{}";
-
- try {
- AbsoluteSubtreeSpecification.valueOf(input);
- } catch (DirectoryException e) {
- return;
- }
-
- fail("Expected DirectoryException");
- }
-
- /**
- * Tests the {@link AbsoluteSubtreeSpecification#valueOf(String)}
- * method.
- */
- public void testValueOf2() throws DirectoryException {
- String input = " { } ";
-
- try {
- AbsoluteSubtreeSpecification.valueOf(input);
- } catch (DirectoryException e) {
- return;
- }
-
- fail("Expected DirectoryException");
- }
-
- /**
- * Tests the {@link AbsoluteSubtreeSpecification#valueOf(String)}
- * method.
- */
- public void testValueOf3() throws DirectoryException {
-
- String input = "{ absoluteBase \"dc=sun, dc=com\" }";
- String output = "{ absoluteBase \"dc=sun,dc=com\" }";
-
- SubtreeSpecification ss = AbsoluteSubtreeSpecification.valueOf(input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link AbsoluteSubtreeSpecification#valueOf(String)}
- * method.
- */
- public void testValueOf4() throws DirectoryException {
-
- String input = "{absoluteBase \"dc=sun, dc=com\"}";
- String output = "{ absoluteBase \"dc=sun,dc=com\" }";
-
- SubtreeSpecification ss = AbsoluteSubtreeSpecification.valueOf(input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link AbsoluteSubtreeSpecification#valueOf(String)}
- * method.
- */
- public void testValueOf5() throws DirectoryException {
-
- String input = "{ absoluteBase \"dc=sun, dc=com\", "
- + "specificationFilter \"(objectClass=*)\" }";
- String output = "{ absoluteBase \"dc=sun,dc=com\", "
- + "specificationFilter \"(objectClass=*)\" }";
-
- SubtreeSpecification ss = AbsoluteSubtreeSpecification.valueOf(input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link AbsoluteSubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches1() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ absoluteBase \"dc=sun, dc=com\", "
- + "specificationFilter \"(objectClass=person)\" }";
- SubtreeSpecification ss = AbsoluteSubtreeSpecification.valueOf(value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link AbsoluteSubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches2() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ absoluteBase \"dc=sun, dc=com\", "
- + "specificationFilter \"(objectClass=organization)\" }";
- SubtreeSpecification ss = AbsoluteSubtreeSpecification.valueOf(value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/core/TestDN.java b/opends/tests/unit-tests/src/server/org/opends/server/core/TestDN.java
deleted file mode 100644
index 521d1e0..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/core/TestDN.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.core;
-
-
-
-import java.util.*;
-import junit.framework.*;
-import org.opends.server.*;
-import org.opends.server.protocols.asn1.*;
-import org.opends.server.types.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the org.opends.server.core.DN \
- * class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestDN
- extends DirectoryServerTestCase
-{
- // String representations of DNs to use when testing. They will be mapped
- // from the "user-defined" form to normalized form.
- private HashMap<String,String> dnStrings;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestDN(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Get the DN test suite.
- *
- * @return The test suite.
- */
- public static Test getTestSuite() {
- // Create the basic test suite.
- TestSuite suite = new TestSuite();
- suite.addTestSuite(TestDN.class);
-
- // Wrap it up with dependencies.
- DirectoryServerTestSetup wrapper = new DirectoryServerTestSetup(suite);
-
- InitialDirectoryServerTestCaseDependency initial;
- initial = new InitialDirectoryServerTestCaseDependency();
- wrapper.registerDependency(initial);
-
- ConfigurationTestCaseDependency config;
- config = new ConfigurationTestCaseDependency(initial);
- wrapper.registerDependency(config);
-
- SchemaTestCaseDependency schema;
- schema = new SchemaTestCaseDependency(config);
- wrapper.registerDependency(schema);
-
- return wrapper;
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- // Create and populate the map of DN strings.
- dnStrings = new HashMap<String,String>();
-
- dnStrings.put("", "");
- dnStrings.put("dc=com", "dc=com");
- dnStrings.put("DC=COM", "dc=com");
- dnStrings.put("dc = com", "dc=com");
- dnStrings.put("dc=example,dc=com", "dc=example,dc=com");
- dnStrings.put("dc=example, dc=com", "dc=example,dc=com");
- dnStrings.put("dc=example ,dc=com", "dc=example,dc=com");
- dnStrings.put("dc =example , dc = com", "dc=example,dc=com");
- dnStrings.put("givenName=John+cn=Doe,ou=People,dc=example,dc=com",
- "cn=doe+givenname=john,ou=people,dc=example,dc=com");
- dnStrings.put("givenName=John\\+cn=Doe,ou=People,dc=example,dc=com",
- "givenname=john\\+cn=doe,ou=people,dc=example,dc=com");
- dnStrings.put("cn=Doe\\, John,ou=People,dc=example,dc=com",
- "cn=doe\\, john,ou=people,dc=example,dc=com");
- dnStrings.put("UID=jsmith,DC=example,DC=net",
- "uid=jsmith,dc=example,dc=net");
- dnStrings.put("OU=Sales+CN=J. Smith,DC=example,DC=net",
- "cn=j. smith+ou=sales,dc=example,dc=net");
- dnStrings.put("CN=James \\\"Jim\\\" Smith\\, III,DC=example,DC=net",
- "cn=james \\\"jim\\\" smith\\, iii,dc=example,dc=net");
- dnStrings.put("CN=Before\\0dAfter,DC=example,DC=net",
- "cn=before\\0dafter,dc=example,dc=net");
- dnStrings.put("1.3.6.1.4.1.1466.0=#04024869",
- "1.3.6.1.4.1.1466.0=\\04\\02hi");
- dnStrings.put("CN=Lu\\C4\\8Di\\C4\\87", "cn=lu\\c4\\8di\\c4\\87");
- dnStrings.put("ou=\\e5\\96\\b6\\e6\\a5\\ad\\e9\\83\\a8,o=Airius",
- "ou=\\e5\\96\\b6\\e6\\a5\\ad\\e9\\83\\a8,o=airius");
- dnStrings.put("photo=\\ john \\ ,dc=com", "photo=\\ john \\ ,dc=com");
-
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>decode</CODE> method which takes a String argument.
- */
- public void testDecodeString()
- {
- for (String rawDN : dnStrings.keySet())
- {
- String normDN = dnStrings.get(rawDN);
-
- DN dn = null;
- try
- {
- dn = DN.decode(rawDN);
- }
- catch (DirectoryException de)
- {
- String message = "DN decoding failed for raw DN '" + rawDN +
- "': " + stackTraceToString(de);
- printError(message);
- throw new AssertionFailedError(message);
- }
-
- try
- {
- assertEquals(normDN, dn.toNormalizedString());
- }
- catch (AssertionFailedError afe)
- {
- printError("DN string comparison failed for raw DN '" + rawDN +
- "': Expected normalized value was '" + normDN +
- "', calculated was '" + dn.toNormalizedString() + "'.");
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decode</CODE> method which takes a String argument.
- */
- public void testDecodeOctetString()
- {
- for (String rawDN : dnStrings.keySet())
- {
- String normDN = dnStrings.get(rawDN);
-
- ASN1OctetString octetString = new ASN1OctetString(rawDN);
-
- DN dn = null;
- try
- {
- dn = DN.decode(octetString);
- }
- catch (DirectoryException de)
- {
- String message = "DN decoding failed for raw DN '" + rawDN +
- "': " + stackTraceToString(de);
- printError(message);
- throw new AssertionFailedError(message);
- }
-
- try
- {
- assertEquals(normDN, dn.toNormalizedString());
- }
- catch (AssertionFailedError afe)
- {
- printError("DN octet string comparison failed for raw DN '" + rawDN +
- "': Expected normalized value was '" + normDN +
- "', calculated was '" + dn.toNormalizedString() + "'.");
- throw afe;
- }
- }
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/core/TestEntry.java b/opends/tests/unit-tests/src/server/org/opends/server/core/TestEntry.java
deleted file mode 100644
index c6e6224..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/core/TestEntry.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.core;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.opends.server.ConfigurationTestCaseDependency;
-import org.opends.server.DirectoryServerTestCase;
-import org.opends.server.DirectoryServerTestSetup;
-import org.opends.server.InitialDirectoryServerTestCaseDependency;
-import org.opends.server.SchemaTestCaseDependency;
-import org.opends.server.api.AttributeValueDecoder;
-import org.opends.server.api.SubtreeSpecificationSet;
-import org.opends.server.protocols.asn1.ASN1OctetString;
-import org.opends.server.schema.AttributeTypeSyntax;
-import org.opends.server.schema.BooleanSyntax;
-import org.opends.server.schema.IntegerSyntax;
-import org.opends.server.schema.RFC3672SubtreeSpecificationSyntax;
-import org.opends.server.types.*;
-
-/**
- * This class defines a set of JUnit tests for the {@link Entry} class.
- * <p>
- * At the moment this test suite only tests the
- * {@link Entry#getAttributeValue(AttributeType, AttributeValueDecoder)}
- * and
- * {@link Entry#getAttributeValues(AttributeType, AttributeValueDecoder, Collection)}
- * methods.
- *
- * @author Matthew Swift
- */
-public final class TestEntry extends DirectoryServerTestCase {
-
- /**
- * Create an entry with the specified single attribute type and value.
- *
- * @param type
- * The attribute type.
- * @param value
- * The attribute value.
- * @return The test entry.
- */
- private Entry createTestEntry(AttributeType type, String value) {
- String[] values = new String[1];
- values[0] = value;
-
- return createTestEntry(type, values);
- }
-
- /**
- * Create an entry with the specified attribute type and values.
- *
- * @param type
- * The attribute type.
- * @param values
- * The array of attribute values.
- * @return The test entry.
- */
- private Entry createTestEntry(AttributeType type, String[] values) {
- // Construct entry DN.
- DN entryDN;
- try {
- entryDN = DN.decode("dc=example, dc=com");
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
-
- // Get default object classes.
- ObjectClass top = DirectoryServer.getObjectClass("top");
- if (top == null) {
- throw new RuntimeException("Unable to resolve object class top");
- }
-
- ObjectClass extensible = DirectoryServer
- .getObjectClass("extensibleobject");
- if (extensible == null) {
- throw new RuntimeException(
- "Unable to resolve object class extensibleObject");
- }
-
- HashMap<ObjectClass, String> objectClasses = new HashMap<ObjectClass, String>();
- objectClasses.put(top, top.getNameOrOID());
- objectClasses.put(extensible, extensible.getNameOrOID());
-
- // Construct the empty entry.
- Entry testEntry = new Entry(entryDN, objectClasses, null, null);
-
- // Now add the attribute.
- LinkedHashSet<AttributeValue> attributeValues = new LinkedHashSet<AttributeValue>();
- for (String value : values) {
- AttributeValue attributeValue = new AttributeValue(type, value);
- attributeValues.add(attributeValue);
- }
- Attribute attribute = new Attribute(type, type.getNameOrOID(),
- attributeValues);
- ArrayList<Attribute> attributes = new ArrayList<Attribute>();
- attributes.add(attribute);
- testEntry.putAttribute(type, attributes);
-
- return testEntry;
- }
-
- /**
- * Get the entry test suite.
- *
- * @return The test suite.
- */
- public static Test getTestSuite() {
- // Create the basic test suite.
- TestSuite suite = new TestSuite();
- suite.addTestSuite(TestEntry.class);
-
- // Wrap it up with dependencies.
- DirectoryServerTestSetup wrapper = new DirectoryServerTestSetup(suite);
-
- InitialDirectoryServerTestCaseDependency initial;
- initial = new InitialDirectoryServerTestCaseDependency();
- wrapper.registerDependency(initial);
-
- ConfigurationTestCaseDependency config;
- config = new ConfigurationTestCaseDependency(initial);
- wrapper.registerDependency(config);
-
- SchemaTestCaseDependency schema;
- schema = new SchemaTestCaseDependency(config);
- wrapper.registerDependency(schema);
-
- return wrapper;
- }
-
- /**
- * Creates a new instance of this JUnit test case with the provided
- * name.
- *
- * @param name
- * The name to use for this JUnit test case.
- */
- public TestEntry(String name) {
- super(name);
- }
-
- /**
- * Test the
- * {@link Entry#getAttributeValue(AttributeType, AttributeValueDecoder)}
- * method.
- */
- public void testGetAttributeValueNotFound() throws DirectoryException {
- AttributeType type1 = DirectoryServer.getAttributeType("description");
- AttributeType type2 = DirectoryServer.getAttributeType("inheritable");
-
- Entry entry = createTestEntry(type1, "hello world");
-
- assertEquals(null, entry
- .getAttributeValue(type2, BooleanSyntax.DECODER));
- }
-
- /**
- * Test the
- * {@link Entry#getAttributeValue(AttributeType, AttributeValueDecoder)}
- * method.
- */
- public void testGetAttributeValueBooleanTrue() throws DirectoryException {
- AttributeType type = DirectoryServer.getAttributeType("inheritable");
-
- Entry entry = createTestEntry(type, "true");
-
- assertEquals(Boolean.TRUE, entry.getAttributeValue(type,
- BooleanSyntax.DECODER));
- }
-
- /**
- * Test the
- * {@link Entry#getAttributeValue(AttributeType, AttributeValueDecoder)}
- * method.
- */
- public void testGetAttributeValueBooleanFalse() throws DirectoryException {
- AttributeType type = DirectoryServer.getAttributeType("inheritable");
-
- Entry entry = createTestEntry(type, "false");
-
- assertEquals(Boolean.FALSE, entry.getAttributeValue(type,
- BooleanSyntax.DECODER));
- }
-
- /**
- * Test the
- * {@link Entry#getAttributeValue(AttributeType, AttributeValueDecoder)}
- * method.
- */
- public void testGetAttributeValueBooleanBad() throws DirectoryException {
- AttributeType type = DirectoryServer.getAttributeType("inheritable");
-
- Entry entry = createTestEntry(type, "bad-value");
-
- try {
- entry.getAttributeValue(type, BooleanSyntax.DECODER);
- } catch (DirectoryException e) {
- return;
- }
-
- fail("Expected DirectoryException");
- }
-
- /**
- * Test the
- * {@link Entry#getAttributeValue(AttributeType, AttributeValueDecoder)}
- * method.
- */
- public void testGetAttributeValuesInteger() throws DirectoryException {
- AttributeType type = DirectoryServer
- .getAttributeType("supportedldapversion");
- String[] values = new String[] { "-4", "-2", "0", "1", "3" };
-
- HashSet<Integer> expected = new HashSet<Integer>();
- for (String value : values) {
- expected.add(Integer.valueOf(value));
- }
-
- Entry entry = createTestEntry(type, values);
- HashSet<Integer> result = new HashSet<Integer>();
- entry.getAttributeValues(type, IntegerSyntax.DECODER, result);
-
- assertEquals(expected, result);
- }
-
- /**
- * Test the
- * {@link Entry#getAttributeValue(AttributeType, AttributeValueDecoder)}
- * method.
- */
- public void testGetAttributeValueIntegerBad() throws DirectoryException {
- AttributeType type = DirectoryServer
- .getAttributeType("supportedldapversion");
- String[] values = new String[] { "-4", "-2", "xxx", "1", "3" };
-
- Entry entry = createTestEntry(type, values);
- HashSet<Integer> result = new HashSet<Integer>();
- try {
- entry.getAttributeValues(type, IntegerSyntax.DECODER, result);
- } catch (DirectoryException e) {
- return;
- }
-
- fail("Expected DirectoryException");
- }
-
- /**
- * Test the
- * {@link Entry#getAttributeValue(AttributeType, AttributeValueDecoder)}
- * method.
- */
- public void testGetAttributeValuesRFC3672SubtreeSpecification()
- throws DirectoryException {
- // Define a dummy attribute type, in case there is not one already
- // in the core schema.
- String string = "( 2.5.18.6 NAME 'subtreeSpecification' "
- + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.45 )";
-
- AttributeType type = AttributeTypeSyntax.decodeAttributeType(
- new ASN1OctetString(string), DirectoryServer.getSchema());
-
- // Test values.
- String[] values = new String[] { "{ }",
- "{ base \"dc=example, dc=com\", minimum 1, maximum 2 }",
- "{ base \"dc=example, dc=com\", maximum 1 }",
- "{ base \"dc=example, dc=com\", maximum 2 }" };
-
- // Relative to the root DN.
- DN rootDN = new DN();
-
- SubtreeSpecificationSet expected = new SubtreeSpecificationSet();
- for (String value : values) {
- expected.add(RFC3672SubtreeSpecification.valueOf(rootDN, value));
- }
-
- Entry entry = createTestEntry(type, values);
- SubtreeSpecificationSet result = new SubtreeSpecificationSet();
- entry.getAttributeValues(type, RFC3672SubtreeSpecificationSyntax
- .createAttributeValueDecoder(rootDN), result);
-
- assertEquals(expected, result);
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/core/TestRFC3672SubtreeSpecification.java b/opends/tests/unit-tests/src/server/org/opends/server/core/TestRFC3672SubtreeSpecification.java
deleted file mode 100644
index 13c8fc5..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/core/TestRFC3672SubtreeSpecification.java
+++ /dev/null
@@ -1,745 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.core;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.opends.server.ConfigurationTestCaseDependency;
-import org.opends.server.DirectoryServerTestCase;
-import org.opends.server.DirectoryServerTestSetup;
-import org.opends.server.InitialDirectoryServerTestCaseDependency;
-import org.opends.server.SchemaTestCaseDependency;
-import org.opends.server.api.SubtreeSpecification;
-import org.opends.server.types.*;
-
-/**
- * This class defines a set of JUnit tests for the
- * {@link org.opends.server.core.RFC3672SubtreeSpecification} class.
- *
- * @author Matthew Swift
- */
-public final class TestRFC3672SubtreeSpecification extends
- DirectoryServerTestCase {
-
- // Cached root DN.
- private DN rootDN;
-
- // Cached set of entry object classes.
- private Set<ObjectClass> objectClasses;
-
- /**
- * Simple wrapper for creating entries that can be filtered.
- */
- private static class FilterableEntryImpl extends Entry {
- public static HashMap<ObjectClass, String> getObjectClasses(
- Set<ObjectClass> objectClasses) {
- HashMap<ObjectClass, String> map = new HashMap<ObjectClass, String>();
-
- for (ObjectClass oc : objectClasses) {
- if (oc != null) {
- map.put(oc, oc.getNameOrOID());
- }
- }
-
- return map;
- }
-
- /**
- * Construct a filterable entry from a DN and set of object classes.
- * It will not contain any attributes.
- *
- * @param entryDN
- * The entry's DN.
- * @param objectClasses
- * The entry's object classes.
- */
- public FilterableEntryImpl(DN entryDN, Set<ObjectClass> objectClasses) {
- super(entryDN, getObjectClasses(objectClasses), null, null);
- }
- }
-
- /**
- * Get the RFC3672 subtree specification test suite.
- *
- * @return The test suite.
- */
- public static Test getTestSuite() {
- // Create the basic test suite.
- TestSuite suite = new TestSuite();
- suite.addTestSuite(TestRFC3672SubtreeSpecification.class);
-
- // Wrap it up with dependencies.
- DirectoryServerTestSetup wrapper = new DirectoryServerTestSetup(suite);
-
- InitialDirectoryServerTestCaseDependency initial;
- initial = new InitialDirectoryServerTestCaseDependency();
- wrapper.registerDependency(initial);
-
- ConfigurationTestCaseDependency config;
- config = new ConfigurationTestCaseDependency(initial);
- wrapper.registerDependency(config);
-
- SchemaTestCaseDependency schema;
- schema = new SchemaTestCaseDependency(config);
- wrapper.registerDependency(schema);
-
- return wrapper;
- }
-
- /**
- * Creates a new instance of this JUnit test case with the provided
- * name.
- *
- * @param name
- * The name to use for this JUnit test case.
- */
- public TestRFC3672SubtreeSpecification(String name) {
- super(name);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setUp() throws Exception {
- super.setUp();
-
- try {
- rootDN = DN.decode("");
-
- objectClasses = new HashSet<ObjectClass>();
-
- ObjectClass oc = DirectoryServer.getObjectClass("top");
- if (oc == null) {
- throw new RuntimeException("Unable to resolve object class top");
- }
- objectClasses.add(oc);
-
- oc = DirectoryServer.getObjectClass("person");
- if (oc == null) {
- throw new RuntimeException("Unable to resolve object class person");
- }
- objectClasses.add(oc);
-
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf1() throws DirectoryException {
-
- String input = "{}";
- String output = "{ }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf2() throws DirectoryException {
-
- String input = " { } ";
- String output = "{ }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf3() throws DirectoryException {
-
- String input = "{ base \"dc=sun, dc=com\" }";
- String output = "{ base \"dc=sun,dc=com\" }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf4() throws DirectoryException {
-
- String input = "{base \"dc=sun, dc=com\"}";
- String output = "{ base \"dc=sun,dc=com\" }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf5() throws DirectoryException {
-
- String input = "{ base \"dc=sun, dc=com\", "
- + "specificationFilter item:ds-config-rootDN }";
- String output = "{ base \"dc=sun,dc=com\", "
- + "specificationFilter item:ds-config-rootDN }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf6() throws DirectoryException {
-
- String input = "{ base \"dc=sun, dc=com\", minimum 0 , maximum 10, "
- + "specificExclusions {chopBefore:\"o=abc\", "
- + "chopAfter:\"o=xyz\"} , specificationFilter not:not:item:foo }";
- String output = "{ base \"dc=sun,dc=com\", "
- + "specificExclusions { chopBefore:\"o=abc\", "
- + "chopAfter:\"o=xyz\" }, maximum 10, specificationFilter "
- + "not:not:item:foo }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf7() throws DirectoryException {
-
- String input = "{ base \"\", minimum 0,maximum 10,"
- + "specificExclusions {chopBefore:\"o=abc\","
- + "chopAfter:\"o=xyz\"},specificationFilter not:not:item:foo}";
- String output = "{ specificExclusions { chopBefore:\"o=abc\", "
- + "chopAfter:\"o=xyz\" }, "
- + "maximum 10, specificationFilter not:not:item:foo }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf8() throws DirectoryException {
-
- String input = "{ specificationFilter and:{item:top, item:person} }";
- String output = "{ specificationFilter and:{item:top, item:person} }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf9() throws DirectoryException {
-
- String input = "{ specificationFilter or:{item:top, item:person} }";
- String output = "{ specificationFilter or:{item:top, item:person} }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf10() throws DirectoryException {
-
- String input = "{ specificationFilter "
- + "or:{item:top, item:foo, and:{item:one, item:two}} }";
- String output = "{ specificationFilter "
- + "or:{item:top, item:foo, and:{item:one, item:two}} }";
-
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches1() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\" }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches2() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=com");
-
- String value = "{ base \"dc=sun, dc=com\" }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches3() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=foo, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\" }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches4() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=foo, dc=bar, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\" }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches5() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", minimum 1 }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches6() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", minimum 1 }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches7() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=xyz, dc=abc, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", minimum 1 }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches8() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", maximum 0 }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches9() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=foo, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", maximum 0 }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches10() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=bar, dc=foo, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", maximum 1 }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches11() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=bar, dc=foo, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", maximum 2 }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches12() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificExclusions { chopAfter:\"\" } }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches13() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=foo, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificExclusions { chopAfter:\"\" } }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches14() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=foo, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificExclusions { chopAfter:\"dc=foo\" } }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches15() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=bar, dc=foo, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificExclusions { chopAfter:\"dc=foo\" } }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches16() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=foo, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificExclusions { chopBefore:\"dc=foo\" } }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches17() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=bar, dc=foo, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificExclusions { chopBefore:\"dc=foo\" } }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches18() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificExclusions { chopBefore:\"dc=foo\" } }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches19() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificationFilter item:person }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches20() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificationFilter item:organization }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches21() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificationFilter not:item:person }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RFC3672SubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches22() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ base \"dc=sun, dc=com\", "
- + "specificationFilter not:item:organization }";
- SubtreeSpecification ss = RFC3672SubtreeSpecification.valueOf(rootDN,
- value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/core/TestRelativeSubtreeSpecification.java b/opends/tests/unit-tests/src/server/org/opends/server/core/TestRelativeSubtreeSpecification.java
deleted file mode 100644
index dd2dabb..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/core/TestRelativeSubtreeSpecification.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.core;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.opends.server.ConfigurationTestCaseDependency;
-import org.opends.server.DirectoryServerTestCase;
-import org.opends.server.DirectoryServerTestSetup;
-import org.opends.server.InitialDirectoryServerTestCaseDependency;
-import org.opends.server.SchemaTestCaseDependency;
-import org.opends.server.api.SubtreeSpecification;
-import org.opends.server.types.*;
-
-/**
- * This class defines a set of JUnit tests for the
- * {@link org.opends.server.core.RelativeSubtreeSpecification} class.
- * <p>
- * This test suite is shorter than the RFC 3672 test suite because it
- * focuses on testing only the pieces of functionality that are specific
- * to the syntax.
- *
- * @author Matthew Swift
- */
-public final class TestRelativeSubtreeSpecification extends
- DirectoryServerTestCase {
-
- // Cached root DN.
- private DN rootDN;
-
- // Cached set of entry object classes.
- private Set<ObjectClass> objectClasses;
-
- /**
- * Simple wrapper for creating entries that can be filtered.
- */
- private static class FilterableEntryImpl extends Entry {
- public static HashMap<ObjectClass, String> getObjectClasses(
- Set<ObjectClass> objectClasses) {
- HashMap<ObjectClass, String> map = new HashMap<ObjectClass, String>();
-
- for (ObjectClass oc : objectClasses) {
- if (oc != null) {
- map.put(oc, oc.getNameOrOID());
- }
- }
-
- return map;
- }
-
- /**
- * Construct a filterable entry from a DN and set of object classes.
- * It will not contain any attributes.
- *
- * @param entryDN
- * The entry's DN.
- * @param objectClasses
- * The entry's object classes.
- */
- public FilterableEntryImpl(DN entryDN, Set<ObjectClass> objectClasses) {
- super(entryDN, getObjectClasses(objectClasses), null, null);
- }
- }
-
- /**
- * Get the relative subtree specification test suite.
- *
- * @return The test suite.
- */
- public static Test getTestSuite() {
- // Create the basic test suite.
- TestSuite suite = new TestSuite();
- suite.addTestSuite(TestRelativeSubtreeSpecification.class);
-
- // Wrap it up with dependencies.
- DirectoryServerTestSetup wrapper = new DirectoryServerTestSetup(suite);
-
- InitialDirectoryServerTestCaseDependency initial;
- initial = new InitialDirectoryServerTestCaseDependency();
- wrapper.registerDependency(initial);
-
- ConfigurationTestCaseDependency config;
- config = new ConfigurationTestCaseDependency(initial);
- wrapper.registerDependency(config);
-
- SchemaTestCaseDependency schema;
- schema = new SchemaTestCaseDependency(config);
- wrapper.registerDependency(schema);
-
- return wrapper;
- }
-
- /**
- * Creates a new instance of this JUnit test case with the provided
- * name.
- *
- * @param name
- * The name to use for this JUnit test case.
- */
- public TestRelativeSubtreeSpecification(String name) {
- super(name);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setUp() throws Exception {
- super.setUp();
-
- try {
- rootDN = DN.decode("");
-
- objectClasses = new HashSet<ObjectClass>();
-
- ObjectClass oc = DirectoryServer.getObjectClass("top");
- if (oc == null) {
- throw new RuntimeException("Unable to resolve object class top");
- }
- objectClasses.add(oc);
-
- oc = DirectoryServer.getObjectClass("person");
- if (oc == null) {
- throw new RuntimeException("Unable to resolve object class person");
- }
- objectClasses.add(oc);
-
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * Tests the {@link RelativeSubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf1() throws DirectoryException {
-
- String input = "{}";
- String output = "{ }";
-
- SubtreeSpecification ss = RelativeSubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RelativeSubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf2() throws DirectoryException {
-
- String input = " { } ";
- String output = "{ }";
-
- SubtreeSpecification ss = RelativeSubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RelativeSubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf3() throws DirectoryException {
-
- String input = "{ relativeBase \"dc=sun, dc=com\" }";
- String output = "{ relativeBase \"dc=sun,dc=com\" }";
-
- SubtreeSpecification ss = RelativeSubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RelativeSubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf4() throws DirectoryException {
-
- String input = "{relativeBase \"dc=sun, dc=com\"}";
- String output = "{ relativeBase \"dc=sun,dc=com\" }";
-
- SubtreeSpecification ss = RelativeSubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RelativeSubtreeSpecification#valueOf(DN, String)}
- * method.
- */
- public void testValueOf5() throws DirectoryException {
-
- String input = "{ relativeBase \"dc=sun, dc=com\", "
- + "specificationFilter \"(objectClass=*)\" }";
- String output = "{ relativeBase \"dc=sun,dc=com\", "
- + "specificationFilter \"(objectClass=*)\" }";
-
- SubtreeSpecification ss = RelativeSubtreeSpecification.valueOf(rootDN,
- input);
- assertEquals(output, ss.toString());
- }
-
- /**
- * Tests the {@link RelativeSubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches1() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ relativeBase \"dc=sun, dc=com\", "
- + "specificationFilter \"(objectClass=person)\" }";
- SubtreeSpecification ss = RelativeSubtreeSpecification.valueOf(
- rootDN, value);
-
- assertEquals(true, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Tests the {@link RelativeSubtreeSpecification#isWithinScope(Entry)}
- * method.
- */
- public void testMatches2() throws DirectoryException {
- try {
- DN dn = DN.decode("dc=abc, dc=sun, dc=com");
-
- String value = "{ relativeBase \"dc=sun, dc=com\", "
- + "specificationFilter \"(objectClass=organization)\" }";
- SubtreeSpecification ss = RelativeSubtreeSpecification.valueOf(
- rootDN, value);
-
- assertEquals(false, ss.isWithinScope(new FilterableEntryImpl(dn,
- objectClasses)));
- } catch (DirectoryException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/ASN1TestSuite.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/ASN1TestSuite.java
deleted file mode 100644
index 93fa748..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/ASN1TestSuite.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import junit.framework.*;
-
-
-
-/**
- * This class defines a JUnit test suite that will launch all the tests for the
- * classes in the ASN.1 package. Whenever a new ASN.1 test class is defined,
- * this suite should be updated to include it.
- *
- *
- * @author Neil A. Wilson
- */
-public class ASN1TestSuite
- extends TestCase
-{
- /**
- * Retrieves a test suite containing all of the ASN.1-related tests.
- *
- * @return A test suite containing all of the ASN.1-related tests.
- */
- public static Test suite()
- {
- TestSuite asn1Suite = new TestSuite("ASN.1 Unit Tests");
-
- asn1Suite.addTestSuite(TestASN1Element.class);
- asn1Suite.addTestSuite(TestASN1Boolean.class);
- asn1Suite.addTestSuite(TestASN1Enumerated.class);
- asn1Suite.addTestSuite(TestASN1Integer.class);
- asn1Suite.addTestSuite(TestASN1Long.class);
- asn1Suite.addTestSuite(TestASN1Null.class);
- asn1Suite.addTestSuite(TestASN1OctetString.class);
- asn1Suite.addTestSuite(TestASN1Sequence.class);
- asn1Suite.addTestSuite(TestASN1Set.class);
- asn1Suite.addTestSuite(TestASN1ReaderAndWriter.class);
-
- return asn1Suite;
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Boolean.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Boolean.java
deleted file mode 100644
index 3fe687d..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Boolean.java
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1Boolean class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1Boolean
- extends DirectoryServerTestCase
-{
- // The pre-encoded value for "false" elements.
- private byte[] falseValue;
-
- // The pre-encoded value for "true" elements.
- private byte[] trueValue;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1Boolean(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- falseValue = new byte[] { (byte) 0x00 };
- trueValue = new byte[] { (byte) 0xFF };
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>booleanValue</CODE> method.
- */
- public void testBooleanValue()
- {
- try
- {
- assertTrue(new ASN1Boolean(true).booleanValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("booleanValue failed for value=true");
- throw afe;
- }
-
- try
- {
- assertFalse(new ASN1Boolean(false).booleanValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("booleanValue failed for value=false");
- throw afe;
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes a boolean argument.
- */
- public void testSetBooleanValue()
- {
- ASN1Boolean element = new ASN1Boolean(true); // Create a new true element.
-
- element.setValue(true); // Test setting the same value.
- try
- {
- assertTrue(element.booleanValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("boolean(true).setValue(true) failed");
- throw afe;
- }
-
- element.setValue(false); // Test setting the opposite value.
- try
- {
- assertFalse(element.booleanValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("boolean(true).setValue(false) failed");
- throw afe;
- }
-
-
- element = new ASN1Boolean(false); // Create a new false element.
- element.setValue(false); // Test setting the same value.
- try
- {
- assertFalse(element.booleanValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("boolean(false).setValue(false) failed");
- throw afe;
- }
-
- element.setValue(true); // Test setting the opposite value.
- try
- {
- assertTrue(element.booleanValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("boolean(false).setValue(true) failed");
- throw afe;
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes a byte array argument.
- */
- public void testSetByteValue()
- {
- ASN1Boolean element = new ASN1Boolean(true);
-
- // Test setting the value to the encoded "false" representation.
- try
- {
- element.setValue(new byte[] { 0x00 });
- assertFalse(element.booleanValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "boolean.setValue(00) threw an exception";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("boolean.setValue(00) failed");
- throw afe;
- }
-
-
- // Test setting the value to all other possible byte representations, which
- // should evaluate to "true".
- for (int i=1; i < 256; i++)
- {
- byte byteValue = (byte) (i & 0xFF);
-
- try
- {
- element.setValue(new byte[] { byteValue });
- assertTrue(element.booleanValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "boolean.setValue(" + byteToHex(byteValue) +
- ") threw an exception";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("boolean.setValue(" + byteToHex(byteValue) + ") failed");
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsBoolean</CODE> method that takes an ASN.1 element
- * argument.
- */
- public void testDecodeElementAsBoolean()
- {
- // Test a boolean element of "true".
- ASN1Boolean trueBoolean = new ASN1Boolean(true);
- try
- {
- assertTrue(ASN1Boolean.decodeAsBoolean(trueBoolean).booleanValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsBoolean(boolean(true)) threw an exception";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsBoolean(boolean(true)) failed");
- throw afe;
- }
-
-
- // Test a boolean element of "false".
- ASN1Boolean falseBoolean = new ASN1Boolean(false);
- try
- {
- assertFalse(ASN1Boolean.decodeAsBoolean(falseBoolean).booleanValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsBoolean(boolean(false)) threw an exception";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsBoolean(boolean(false)) failed");
- throw afe;
- }
-
-
- // Test the valid generic elements that may be used.
- for (int i=0; i < 256; i++)
- {
- byte byteValue = (byte) (i & 0xFF);
- boolean compareValue = (i != 0);
-
- ASN1Element element = new ASN1Element((byte) 0x00,
- new byte[] { byteValue });
-
- try
- {
- assertEquals(compareValue,
- ASN1Boolean.decodeAsBoolean(element).booleanValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsBoolean(element) threw an exception for " +
- "byteValue=" + byteToHex(byteValue);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsBoolean(element) failed for byteValue=" +
- byteToHex(byteValue));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array.
- * argument.
- */
- public void testDecodeBytesAsBoolean()
- {
- byte[] encodedElement = new byte[] { 0x00, 0x01, 0x00 };
-
- // Test all possible byte values.
- for (int i=0; i < 256; i++)
- {
- boolean compareValue = (i != 0);
-
- // Set the value.
- encodedElement[2] = (byte) (i & 0xFF);
-
- // Test with the standard Boolean type.
- encodedElement[0] = (byte) 0x01;
- try
- {
- assertEquals(compareValue,
- ASN1Boolean.decodeAsBoolean(encodedElement).booleanValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsBoolean(byte[]) threw an exception for " +
- "byteValue=" + byteToHex(encodedElement[2]);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsBoolean(byte[] failed for byteValue=" +
- byteToHex(encodedElement[2]));
- throw afe;
- }
- }
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Element.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Element.java
deleted file mode 100644
index 1643570..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Element.java
+++ /dev/null
@@ -1,1471 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import java.util.*;
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1Element class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1Element
- extends DirectoryServerTestCase
-{
- // The sets of pre-encoded ASN.1 elements that will be included in the test
- // case.
- private ArrayList<ArrayList<ASN1Element>> testElementSets;
-
- // The set of pre-encoded element sets that will be used in the test cases.
- private ArrayList<byte[]> testEncodedElementSets;
-
- // The set of pre-encoded integer values that will be included in the test
- // cases.
- private ArrayList<byte[]> testEncodedIntegers;
-
- // The set of pre-encoded lengths that will be included in the test cases.
- private ArrayList<byte[]> testEncodedLengths;
-
- // The set of BER types that will be included in the test cases.
- private ArrayList<Byte> testTypes;
-
- // The set of element values that will be included in the test cases.
- private ArrayList<byte[]> testValues;
-
- // The set of integer values that will be included in the test cases.
- private ArrayList<Integer> testIntegers;
-
- // The set of lengths that will be included in the test cases.
- private ArrayList<Integer> testLengths;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1Element(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- // Initialize the set of types. It will encapsulate the entire range of
- // possible byte values.
- testTypes = new ArrayList<Byte>();
- for (int i=0; i < 0xFF; i++)
- {
- testTypes.add((byte) (i & 0xFF));
- }
-
-
- // Initialize the set of values. Don't make these too big since they
- // consume memory.
- testValues = new ArrayList<byte[]>();
- testValues.add(null); // The null value.
- testValues.add(new byte[0x00]); // The zero-byte value.
- testValues.add(new byte[0x01]); // The single-byte value.
- testValues.add(new byte[0x7F]); // The largest 1-byte length encoding.
- testValues.add(new byte[0x80]);
- testValues.add(new byte[0xFF]); // The largest 2-byte length encoding.
- testValues.add(new byte[0x0100]);
- testValues.add(new byte[0xFFFF]); // The largest 3-byte length encoding.
- testValues.add(new byte[0x010000]);
-
-
- // Initialize the set of element lengths and their pre-encoded
- // representations. Don't make these too big since we will create arrays
- // with these lengths during testing.
- testLengths = new ArrayList<Integer>();
- testEncodedLengths = new ArrayList<byte[]>();
-
- testLengths.add(0x00); // The zero-byte length.
- testEncodedLengths.add(new byte[] { (byte) 0x00 });
-
- testLengths.add(0x01); // A common 1-byte length.
- testEncodedLengths.add(new byte[] { (byte) 0x01 });
-
- testLengths.add(0x7F); // The largest 1-byte length encoding.
- testEncodedLengths.add(new byte[] { (byte) 0x7F });
-
- testLengths.add(0x80); // The smallest length that must use 2 bytes.
- testEncodedLengths.add(new byte[] { (byte) 0x81, (byte) 0x80 });
-
-
- testLengths.add(0xFF); // The largest length that may use 2 bytes.
- testEncodedLengths.add(new byte[] { (byte) 0x81, (byte) 0xFF });
-
- testLengths.add(0x0100); // The smallest length that must use 3 bytes.
- testEncodedLengths.add(new byte[] { (byte) 0x82, (byte) 0x01,
- (byte) 0x00 });
-
- testLengths.add(0xFFFF); // The largest length that may use 3 bytes.
- testEncodedLengths.add(new byte[] { (byte) 0x82, (byte) 0xFF,
- (byte) 0xFF });
-
- testLengths.add(0x010000); // The smallest length that must use 4 bytes.
- testEncodedLengths.add(new byte[] { (byte) 0x83, (byte) 0x01,
- (byte) 0x00, (byte) 0x00 });
-
-
- // Initialize the set of integer values and their pre-encoded
- // representations. These can get big since they will not be used to create
- // arrays. Also, there is no need to test negative values since LDAP
- // doesn't make use of them.
- testIntegers = new ArrayList<Integer>();
- testEncodedIntegers = new ArrayList<byte[]>();
-
- testIntegers.add(0x00); // A common 1-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00 });
-
- testIntegers.add(0x7F); // The largest 1-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F });
-
- testIntegers.add(0x80); // The smallest 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0x80 });
-
- testIntegers.add(0xFF); // A boundary case for 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0xFF });
-
- testIntegers.add(0x0100); // A boundary case for 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x01, (byte) 0x00 });
-
- testIntegers.add(0x7FFF); // The largest 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F, (byte) 0xFF });
-
- testIntegers.add(0x8000); // The smallest 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0x80,
- (byte) 0x00 });
-
- testIntegers.add(0xFFFF); // A boundary case for 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0xFF,
- (byte) 0xFF });
-
- testIntegers.add(0x010000); // A boundary case for 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x01, (byte) 0x00,
- (byte) 0x00 });
-
- testIntegers.add(0x7FFFFF); // The largest 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F, (byte) 0xFF,
- (byte) 0xFF });
-
- testIntegers.add(0x800000); // The smallest 4-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0x80,
- (byte) 0x00, (byte) 0x00 });
-
- testIntegers.add(0xFFFFFF); // A boundary case for 4-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
-
- testIntegers.add(0x01000000); // A boundary case for 4-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x01, (byte) 0x00,
- (byte) 0x00, (byte) 0x00 });
-
- testIntegers.add(0x7FFFFFFF); // The largest value we will allow.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
-
-
- // Initialize the sets of ASN.1 elements that will be used in testing the
- // group encode/decode operations.
- testElementSets = new ArrayList<ArrayList<ASN1Element>>();
- testEncodedElementSets = new ArrayList<byte[]>();
-
- testElementSets.add(null); // The null set.
- testEncodedElementSets.add(new byte[0]);
-
- testElementSets.add(new ArrayList<ASN1Element>(0)); // The empty set.
- testEncodedElementSets.add(new byte[0]);
-
- // Sets containing from 1 to 10 elements.
- for (int i=1; i <= 10; i++)
- {
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(i);
-
- for (int j=0; j < i; j++)
- {
- elements.add(new ASN1Element((byte) 0x00));
- }
- testElementSets.add(elements);
- testEncodedElementSets.add(new byte[i*2]);
- }
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>getType</CODE> method.
- */
- public void testGetType()
- {
- for (byte type : testTypes)
- {
- ASN1Element element = new ASN1Element(type);
-
- try
- {
- assertEquals(type, element.getType());
- }
- catch (AssertionFailedError afe)
- {
- printError("getType failed for type=" + byteToHex(type));
- throw afe;
- }
-
- for (byte[] value : testValues)
- {
- element = new ASN1Element(type, value);
-
- try
- {
- assertEquals(type, element.getType());
- }
- catch (AssertionFailedError afe)
- {
- printError("getType failed for type=" + byteToHex(type) + ", value=" +
- bytesToHex(value));
- throw afe;
- }
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setType</CODE> method.
- */
- public void testSetType()
- {
- ASN1Element element = new ASN1Element((byte) 0x00);
- for (byte type : testTypes)
- {
- element.setType(type);
-
- try
- {
- assertEquals(type, element.getType());
- }
- catch (AssertionFailedError afe)
- {
- printError("setType failed for type=" + byteToHex(type));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>isUniversal</CODE> method.
- */
- public void testIsUniversal()
- {
- ASN1Element element = new ASN1Element((byte) 0x00);
- for (byte type : testTypes)
- {
- element.setType(type);
- boolean isUniversal = (((byte) (type & 0xC0)) == ((byte) 0x00));
-
- try
- {
- assertEquals(isUniversal, element.isUniversal());
- }
- catch (AssertionFailedError afe)
- {
- printError("isUniversal failed for type=" + byteToHex(type));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>isApplicationSpecific</CODE> method.
- */
- public void testIsApplicationSpecific()
- {
- ASN1Element element = new ASN1Element((byte) 0x00);
- for (byte type : testTypes)
- {
- element.setType(type);
- boolean isApplicationSpecific = (((byte) (type & 0xC0)) == ((byte) 0x40));
-
- try
- {
- assertEquals(isApplicationSpecific, element.isApplicationSpecific());
- }
- catch (AssertionFailedError afe)
- {
- printError("isApplicationSpecific failed for type=" + byteToHex(type));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>isContextSpecific</CODE> method.
- */
- public void testIsContextSpecific()
- {
- ASN1Element element = new ASN1Element((byte) 0x00);
- for (byte type : testTypes)
- {
- element.setType(type);
- boolean isContextSpecific = (((byte) (type & 0xC0)) == ((byte) 0x80));
-
- try
- {
- assertEquals(isContextSpecific, element.isContextSpecific());
- }
- catch (AssertionFailedError afe)
- {
- printError("isContextSpecific failed for type=" + byteToHex(type));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>isPrivate</CODE> method.
- */
- public void testIsPrivate()
- {
- ASN1Element element = new ASN1Element((byte) 0x00);
- for (byte type : testTypes)
- {
- element.setType(type);
- boolean isPrivate = (((byte) (type & 0xC0)) == ((byte) 0xC0));
-
- try
- {
- assertEquals(isPrivate, element.isPrivate());
- }
- catch (AssertionFailedError afe)
- {
- printError("isPrivate failed for type=" + byteToHex(type));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>isPrimitive</CODE> method.
- */
- public void testIsPrimitive()
- {
- ASN1Element element = new ASN1Element((byte) 0x00);
- for (byte type : testTypes)
- {
- element.setType(type);
- boolean isPrimitive = (((byte) (type & 0x20)) == ((byte) 0x00));
-
- try
- {
- assertEquals(isPrimitive, element.isPrimitive());
- }
- catch (AssertionFailedError afe)
- {
- printError("isPrimitive failed for type=" + byteToHex(type));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>isConstructed</CODE> method.
- */
- public void testIsConstructed()
- {
- ASN1Element element = new ASN1Element((byte) 0x00);
- for (byte type : testTypes)
- {
- element.setType(type);
- boolean isConstructed = (((byte) (type & 0x20)) == ((byte) 0x20));
-
- try
- {
- assertEquals(isConstructed, element.isConstructed());
- }
- catch (AssertionFailedError afe)
- {
- printError("isConstructed failed for type=" + byteToHex(type));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>getValue</CODE> method.
- */
- public void testGetValue()
- {
- for (byte type : testTypes)
- {
- ASN1Element element = new ASN1Element(type);
-
- try
- {
- assertTrue(Arrays.equals(new byte[0], element.value()));
- }
- catch (AssertionFailedError afe)
- {
- printError("getValue failed for type=" + byteToHex(type));
- throw afe;
- }
-
- for (byte[] value : testValues)
- {
- element = new ASN1Element(type, value);
-
- try
- {
- if (value == null)
- {
- assertTrue(Arrays.equals(new byte[0], element.value()));
- }
- else
- {
- assertTrue(Arrays.equals(value, element.value()));
- }
- }
- catch (AssertionFailedError afe)
- {
- printError("getValue failed for type=" + byteToHex(type) +
- ", value=" + bytesToHex(value));
- throw afe;
- }
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method.
- */
- public void testSetValue()
- {
- ASN1Element element = new ASN1Element((byte) 0x00);
-
- for (byte[] value : testValues)
- {
- try
- {
- element.setValue(value);
- }
- catch (Exception e)
- {
- String message = "setvalue threw an exception for value=" +
- bytesToHex(value);
- printError(message);
- printException(e);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(e));
- }
-
- try
- {
- if (value == null)
- {
- assertTrue(Arrays.equals(new byte[0], element.value()));
- }
- else
- {
- assertTrue(Arrays.equals(value, element.value()));
- }
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue failed for value=" + bytesToHex(value));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>encodeLength</CODE> method.
- */
- public void testEncodeLength()
- {
- int numLengths = testLengths.size();
- for (int i=0; i < numLengths; i++)
- {
- int length = testLengths.get(i);
- byte[] encodedLength = testEncodedLengths.get(i);
-
- try
- {
- assertTrue(Arrays.equals(encodedLength,
- ASN1Element.encodeLength(length)));
- }
- catch (AssertionFailedError afe)
- {
- printError("encodeLength failed for length=" + length);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>encode</CODE> and <CODE>decode</CODE> methods.
- */
- public void testEncodeAndDecode()
- {
- for (byte type : testTypes)
- {
- for (byte[] value : testValues)
- {
- int length;
- byte[] encodedLength;
- if (value == null)
- {
- length = 0;
- encodedLength = new byte[] { (byte) 0x00 };
- }
- else
- {
- length = value.length;
- encodedLength = ASN1Element.encodeLength(length);
- }
-
- byte[] encodedElement = new byte[1 + length + encodedLength.length];
- encodedElement[0] = type;
- System.arraycopy(encodedLength, 0, encodedElement, 1,
- encodedLength.length);
- if (value != null)
- {
- System.arraycopy(value, 0, encodedElement, 1+encodedLength.length,
- length);
- }
-
- ASN1Element element = new ASN1Element(type, value);
-
- try
- {
- assertTrue(Arrays.equals(encodedElement, element.encode()));
- }
- catch (AssertionFailedError afe)
- {
- printError("encode failed for type=" + byteToHex(type) +
- ", valueLength=" + length);
- throw afe;
- }
-
- try
- {
- assertTrue(element.equals(ASN1Element.decode(encodedElement)));
- }
- catch (ASN1Exception ae)
- {
- String message = "decode threw an exception for type=" +
- byteToHex(type) + ", valueLength=" + length;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decode failed for type=" + byteToHex(type) +
- ", valueLength=" + length);
- throw afe;
- }
- }
-
-
-
- int numLengths = testLengths.size();
- for (int i=0; i < numLengths; i++)
- {
- int length = testLengths.get(i);
- byte[] encodedLength = testEncodedLengths.get(i);
- byte[] value = new byte[length];
-
- byte[] encodedElement = new byte[1 + length + encodedLength.length];
- encodedElement[0] = type;
- System.arraycopy(encodedLength, 0, encodedElement, 1,
- encodedLength.length);
-
- ASN1Element element = new ASN1Element(type, value);
-
- try
- {
- assertTrue(Arrays.equals(encodedElement, element.encode()));
- }
- catch (AssertionFailedError afe)
- {
- printError("encode failed for type=" + byteToHex(type) + ", length=" +
- length);
- throw afe;
- }
-
- try
- {
- assertTrue(element.equals(ASN1Element.decode(encodedElement)));
- }
- catch (ASN1Exception ae)
- {
- String message = "decode threw an exception for type=" +
- byteToHex(type) + ", length=" + length;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decode failed for type=" + byteToHex(type) + ", length=" +
- length);
- throw afe;
- }
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>encodeValue</CODE> method with a single boolean argument.
- */
- public void testEncodeBooleanValue()
- {
- byte[] encodedFalse = new byte[] { (byte) 0x00 };
- byte[] encodedTrue = new byte[] { (byte) 0xFF };
-
- try
- {
- assertTrue(Arrays.equals(encodedFalse,
- ASN1Element.encodeValue(false)));
- }
- catch (AssertionFailedError afe)
- {
- printError("encodeValue failed for a boolean value of false");
- throw afe;
- }
-
- try
- {
- assertTrue(Arrays.equals(encodedTrue,
- ASN1Element.encodeValue(true)));
- }
- catch (AssertionFailedError afe)
- {
- printError("encodeValue failed for a boolean value of true");
- throw afe;
- }
- }
-
-
-
- /**
- * Tests the <CODE>encodeValue</CODE> method with a single int argument.
- */
- public void testEncodeIntValue()
- {
- int numIntValues = testIntegers.size();
- for (int i=0; i < numIntValues; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedInt = testEncodedIntegers.get(i);
-
- try
- {
- assertTrue(Arrays.equals(encodedInt,
- ASN1Element.encodeValue(intValue)));
- }
- catch (AssertionFailedError afe)
- {
- printError("encodeValue failed for an int value of " + intValue);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>encodeValue</CODE> method with a set of ASN.1 elements.
- */
- public void testEncodeAndDecodeElements()
- {
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
- byte[] encodedElementSet = testEncodedElementSets.get(i);
-
- try
- {
- assertTrue(Arrays.equals(encodedElementSet,
- ASN1Element.encodeValue(elementSet)));
- }
- catch (AssertionFailedError afe)
- {
- if (elementSet == null)
- {
- printError("encodeValue failed for a null set of elements");
- }
- else
- {
- printError("encodeValue failed for a set of " + elementSet.size() +
- " elements");
- }
-
- throw afe;
- }
-
-
- ArrayList<ASN1Element> decodedElementSet;
- try
- {
- decodedElementSet = ASN1Element.decodeElements(encodedElementSet);
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeElements threw an exception for value=" +
- bytesToHex(encodedElementSet);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
-
-
- ArrayList<ASN1Element> compareSet;
- if (elementSet == null)
- {
- compareSet = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareSet = elementSet;
- }
-
- try
- {
- assertTrue(listsAreEqual(compareSet, decodedElementSet));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeElements failed for value=" +
- bytesToHex(encodedElementSet));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsBoolean</CODE> method.
- */
- public void testDecodeAsBoolean()
- {
- for (int i=0; i < 256; i++)
- {
- byte[] valueByte = new byte[] { (byte) i };
- ASN1Element element = new ASN1Element((byte) 0x00, valueByte);
- boolean booleanValue = (i != 0);
-
- try
- {
- assertEquals(booleanValue, element.decodeAsBoolean().booleanValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsBoolean threw an exception for type=00, " +
- "value=" + bytesToHex(valueByte);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsBoolean failed for type=00, value=" +
- bytesToHex(valueByte));
- throw afe;
- }
-
-
- element = new ASN1Element((byte) 0x01, valueByte);
-
- try
- {
- assertEquals(booleanValue, element.decodeAsBoolean().booleanValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsBoolean threw an exception for type=01, " +
- "value=" + bytesToHex(valueByte);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsBoolean failed for type=01, value=" +
- bytesToHex(valueByte));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsEnumerated</CODE> method.
- */
- public void testDecodeAsEnumerated()
- {
- int numIntValues = testIntegers.size();
- for (int i=0; i < numIntValues; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedInt = testEncodedIntegers.get(i);
-
- ASN1Element element = new ASN1Element((byte) 0x00, encodedInt);
-
- try
- {
- assertEquals(intValue, element.decodeAsEnumerated().intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsEnumerated threw an exception for type=00, " +
- "intValue=" + intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsEnumerated failed for type=00, intValue=" +
- intValue);
- throw afe;
- }
-
-
- element = new ASN1Element((byte) 0x0A, encodedInt);
-
- try
- {
- assertEquals(intValue, element.decodeAsEnumerated().intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsEnumerated threw an exception for type=0A, " +
- "intValue=" + intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsEnumerated failed for type=0A, intValue=" +
- intValue);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsInteger</CODE> method.
- */
- public void testDecodeAsInteger()
- {
- int numIntValues = testIntegers.size();
- for (int i=0; i < numIntValues; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedInt = testEncodedIntegers.get(i);
-
- ASN1Element element = new ASN1Element((byte) 0x00, encodedInt);
-
- try
- {
- assertEquals(intValue, element.decodeAsInteger().intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsInteger threw an exception for type=00, " +
- "intValue=" + intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsInteger failed for type=00, intValue=" + intValue);
- throw afe;
- }
-
-
- element = new ASN1Element((byte) 0x02, encodedInt);
-
- try
- {
- assertEquals(intValue, element.decodeAsInteger().intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsInteger threw an exception for type=02, " +
- "intValue=" + intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsInteger failed for type=02, intValue=" + intValue);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsNull</CODE> method.
- */
- public void testDecodeAsNull()
- {
- for (byte type : testTypes)
- {
- ASN1Element element = new ASN1Element(type);
- ASN1Null nullElement = new ASN1Null(type);
-
- try
- {
- assertEquals(nullElement, element.decodeAsNull());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsNull threw an exception for type=" +
- byteToHex(type);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsNull failed for type=" + byteToHex(type));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsOctetString</CODE> method.
- */
- public void testDecodeAsOctetString()
- {
- for (byte[] value : testValues)
- {
- ASN1Element element = new ASN1Element((byte) 0x00, value);
-
- byte[] compareValue;
- if (value == null)
- {
- compareValue = new byte[0];
- }
- else
- {
- compareValue = value;
- }
-
- try
- {
- assertTrue(Arrays.equals(compareValue,
- element.decodeAsOctetString().value()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsOctetString threw an exception for " +
- "type=00, value=" + bytesToHex(value);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsOctetString failed for type=00, value=" +
- bytesToHex(value));
- throw afe;
- }
-
-
- element = new ASN1Element((byte) 0x04, value);
-
- try
- {
- assertTrue(Arrays.equals(compareValue,
- element.decodeAsOctetString().value()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsOctetString threw an exception for " +
- "type=04, value=" + bytesToHex(value);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsOctetString failed for type=04, value=" +
- bytesToHex(value));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsSequence</CODE> method.
- */
- public void testDecodeAsSequence()
- {
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
- byte[] encodedElementSet = testEncodedElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
-
- ASN1Element element = new ASN1Element((byte) 0x00, encodedElementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList,
- element.decodeAsSequence().elements()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsSequence threw an exception for type=00, " +
- "value=" + bytesToHex(encodedElementSet);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsSequence failed for type=00, value=" +
- bytesToHex(encodedElementSet));
- throw afe;
- }
-
-
- element = new ASN1Element((byte) 0x30, encodedElementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList,
- element.decodeAsSequence().elements()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsSequence threw an exception for type=30, " +
- "value=" + bytesToHex(encodedElementSet);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsSequence failed for type=30, value=" +
- bytesToHex(encodedElementSet));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsSet</CODE> method.
- */
- public void testDecodeAsSet()
- {
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
- byte[] encodedElementSet = testEncodedElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
-
- ASN1Element element = new ASN1Element((byte) 0x00, encodedElementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList,
- element.decodeAsSet().elements()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsSet threw an exception for type=00, " +
- "value=" + bytesToHex(encodedElementSet);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsSet failed for type=00, value=" +
- bytesToHex(encodedElementSet));
- throw afe;
- }
-
-
- element = new ASN1Element((byte) 0x31, encodedElementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList,
- element.decodeAsSet().elements()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsSet threw an exception for type=31, " +
- "value=" + bytesToHex(encodedElementSet);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsSet failed for type=31, value=" +
- bytesToHex(encodedElementSet));
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>equals</CODE> and <CODE>hashCode</CODE> methods.
- */
- public void testEqualsAndHashCode()
- {
- // Perform simple tests for two basic elements that should be the same, one
- // that should differ in type, one that should differ in value, and one that
- // should differ in both.
- ASN1Element e1 = new ASN1Element((byte) 0x00);
- ASN1Element e2 = new ASN1Element((byte) 0x00, new byte[0]);
- ASN1Element e3 = new ASN1Element((byte) 0x01);
- ASN1Element e4 = new ASN1Element((byte) 0x00, new byte[] { (byte) 0x00 });
- ASN1Element e5 = new ASN1Element((byte) 0x01, new byte[] { (byte) 0x00 });
- ASN1Element e6 = new ASN1Element((byte) 0x00, new byte[] { (byte) 0x01 });
-
- try
- {
- assertTrue(e1.equals(e2)); // Basic equality test.
- }
- catch (AssertionFailedError afe)
- {
- printError("e1.equals(e2) failed");
- throw afe;
- }
-
- try
- {
- assertTrue(e2.equals(e1));
- }
- catch (AssertionFailedError afe) // Reflexive equality test.
- {
- printError("e2.equals(e1) failed");
- throw afe;
- }
-
- try
- {
- assertFalse(e1.equals(e3)); // Difference in type.
- }
- catch (AssertionFailedError afe)
- {
- printError("e1.equals(e3) failed");
- throw afe;
- }
-
- try
- {
- assertFalse(e1.equals(e4)); // Difference in value.
- }
- catch (AssertionFailedError afe)
- {
- printError("e1.equals(e4) failed");
- throw afe;
- }
-
- try
- {
- assertFalse(e1.equals(e5)); // Differences in type and value.
- }
- catch (AssertionFailedError afe)
- {
- printError("e1.equals(e5) failed");
- throw afe;
- }
-
- try
- {
- assertFalse(e4.equals(e6)); // Difference in values with the same length.
- }
- catch (AssertionFailedError afe)
- {
- printError("e4.equals(e6) failed");
- throw afe;
- }
-
-
- // Make sure that equal elements have equal hash codes.
- try
- {
- assertEquals(e1.hashCode(), e2.hashCode()); // Hash code equality test.
- }
- catch (AssertionFailedError afe)
- {
- printError("hashCode failed");
- throw afe;
- }
-
-
- // Test equals against a null element.
- try
- {
- assertFalse(e1.equals(null));
- }
- catch (AssertionFailedError afe)
- {
- printError("e1.equals(null) failed for type=00");
- throw afe;
- }
-
-
- // Test boolean elements against equivalent generic elements.
- ASN1Element trueElement = new ASN1Element((byte) 0x01,
- new byte[] { (byte) 0xFF });
- ASN1Element falseElement = new ASN1Element((byte) 0x01,
- new byte[] { (byte) 0x00 });
- ASN1Boolean trueBoolean = new ASN1Boolean(true);
- ASN1Boolean falseBoolean = new ASN1Boolean(false);
-
- try
- {
- assertTrue(trueElement.equals(trueBoolean));
- }
- catch (AssertionFailedError afe)
- {
- printError("genericElement.equals(booleanElement) failed for " +
- "booleanValue=true");
- throw afe;
- }
-
- try
- {
- assertTrue(trueBoolean.equals(trueElement));
- }
- catch (AssertionFailedError afe)
- {
- printError("booleanElement.equals(genericElement) failed for " +
- "booleanValue=true");
- throw afe;
- }
-
- try
- {
- assertEquals(trueElement.hashCode(), trueBoolean.hashCode());
- }
- catch (AssertionFailedError afe)
- {
- printError("genericElement.hashCode != booleanElement.hashCode " +
- "for booleanValue=true");
- throw afe;
- }
-
- try
- {
- assertTrue(falseElement.equals(falseBoolean));
- }
- catch (AssertionFailedError afe)
- {
- printError("genericElement.equals(booleanElement) failed for " +
- "booleanValue=false");
- throw afe;
- }
-
- try
- {
- assertTrue(falseBoolean.equals(falseElement));
- }
- catch (AssertionFailedError afe)
- {
- printError("booleanElement.equals(genericElement) failed for " +
- "booleanValue=false");
- throw afe;
- }
-
- try
- {
- assertEquals(falseElement.hashCode(), falseBoolean.hashCode());
- }
- catch (AssertionFailedError afe)
- {
- printError("genericElement.hashCode != booleanElement.hashCode " +
- "for booleanValue=false");
- throw afe;
- }
-
-
- // Test integer elements against equivalent generic elements.
- int numIntegers = testIntegers.size();
- for (int i=0; i < numIntegers; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedIntValue = testEncodedIntegers.get(i);
-
- ASN1Element genericElement = new ASN1Element((byte) 0x02,
- encodedIntValue);
- ASN1Integer integerElement = new ASN1Integer(intValue);
-
- try
- {
- assertTrue(genericElement.equals(integerElement));
- }
- catch (AssertionFailedError afe)
- {
- printError("genericElement.equals(integerElement) failed for " +
- "intValue=" + intValue);
- throw afe;
- }
-
- try
- {
- assertTrue(integerElement.equals(genericElement)); // Reflexive test.
- }
- catch (AssertionFailedError afe)
- {
- printError("integerElement.equals(genericElement) failed for " +
- "intValue=" + intValue);
- throw afe;
- }
-
- try
- {
- // Test for matching hash codes.
- assertEquals(genericElement.hashCode(), integerElement.hashCode());
- }
- catch (AssertionFailedError afe)
- {
- printError("genericElement.hashCode != integerElement.hashCode for " +
- "intValue=" + intValue);
- throw afe;
- }
- }
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Enumerated.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Enumerated.java
deleted file mode 100644
index 762144c..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Enumerated.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import java.util.*;
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1Enumerated class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1Enumerated
- extends DirectoryServerTestCase
-{
- // The set of encoded values for the test integers.
- private ArrayList<byte[]> testEncodedIntegers;
-
- // The set of integer values to use in test cases.
- private ArrayList<Integer> testIntegers;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1Enumerated(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- testIntegers = new ArrayList<Integer>();
- testEncodedIntegers = new ArrayList<byte[]>();
-
- // Add all values that can be encoded using a single byte.
- for (int i=0; i < 128; i++)
- {
- testIntegers.add(i);
- testEncodedIntegers.add(new byte[] { (byte) (i & 0xFF) });
- }
-
- testIntegers.add(0x80); // The smallest 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0x80 });
-
- testIntegers.add(0xFF); // A boundary case for 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0xFF });
-
- testIntegers.add(0x0100); // A boundary case for 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x01, (byte) 0x00 });
-
- testIntegers.add(0x7FFF); // The largest 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F, (byte) 0xFF });
-
- testIntegers.add(0x8000); // The smallest 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0x80,
- (byte) 0x00 });
-
- testIntegers.add(0xFFFF); // A boundary case for 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0xFF,
- (byte) 0xFF });
-
- testIntegers.add(0x010000); // A boundary case for 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x01, (byte) 0x00,
- (byte) 0x00 });
-
- testIntegers.add(0x7FFFFF); // The largest 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F, (byte) 0xFF,
- (byte) 0xFF });
-
- testIntegers.add(0x800000); // The smallest 4-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0x80,
- (byte) 0x00, (byte) 0x00 });
-
- testIntegers.add(0xFFFFFF); // A boundary case for 4-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
-
- testIntegers.add(0x01000000); // A boundary case for 4-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x01, (byte) 0x00,
- (byte) 0x00, (byte) 0x00 });
-
- testIntegers.add(0x7FFFFFFF); // The largest value we will allow.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>intValue</CODE> method.
- */
- public void testIntValue()
- {
- for (int i : testIntegers)
- {
- ASN1Integer element = new ASN1Integer(i);
-
- try
- {
- assertEquals(i, element.intValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("intValue failed for intValue=" + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes an int argument.
- */
- public void testSetIntValue()
- {
- ASN1Integer element = new ASN1Integer(0);
-
- int numIntegers = testIntegers.size();
- for (int i=0; i < numIntegers; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedIntValue = testEncodedIntegers.get(i);
-
- element.setValue(intValue);
- try
- {
- assertEquals(intValue, element.intValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(" + intValue + ") failed in intValue");
- throw afe;
- }
-
- try
- {
- assertTrue(Arrays.equals(encodedIntValue, element.value()));
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(" + intValue + ") failed in value");
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes a byte array argument.
- */
- public void testSetByteValue()
- {
- ASN1Integer element = new ASN1Integer(0);
-
- int numIntegers = testIntegers.size();
- for (int i=0; i < numIntegers; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedIntValue = testEncodedIntegers.get(i);
-
- try
- {
- element.setValue(encodedIntValue);
- }
- catch (ASN1Exception ae)
- {
- String message = "setValue(byte[]) threw an exception for intValue=" +
- intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
-
- try
- {
- assertEquals(intValue, element.intValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(byte[]) failed for intValue=" + intValue);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsEnumerated</CODE> method that takes an ASN.1
- * element argument.
- */
- public void testDecodeElementAsEnumerated()
- {
- int numIntegers = testIntegers.size();
- for (int i=0; i < numIntegers; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedIntValue = testEncodedIntegers.get(i);
-
- ASN1Element element = new ASN1Element((byte) 0x00, encodedIntValue);
-
- try
- {
- assertEquals(intValue,
- ASN1Enumerated.decodeAsEnumerated(element).intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsEnumerated(element(" + intValue +
- ")) threw an exception for type=00";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsEnumerated(element(" + intValue +
- ")) failed for type=00");
- throw afe;
- }
-
-
- element = new ASN1Element((byte) 0x0A, encodedIntValue);
-
- try
- {
- assertEquals(intValue,
- ASN1Enumerated.decodeAsEnumerated(element).intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsEnumerated(element(" + intValue +
- ")) threw an exception for type=0A";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsEnumerated(element(" + intValue +
- ")) failed for type=0A");
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsEnumerated</CODE> method that takes a byte array
- * argument.
- */
- public void testDecodeBytesAsEnumerated()
- {
- int numIntegers = testIntegers.size();
- for (int i=0; i < numIntegers; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedIntValue = testEncodedIntegers.get(i);
- byte[] encodedLength = ASN1Element.encodeLength(encodedIntValue.length);
- byte[] encodedElement = new byte[1 + encodedLength.length +
- encodedIntValue.length];
-
- encodedElement[0] = (byte) 0x00;
- System.arraycopy(encodedLength, 0, encodedElement, 1,
- encodedLength.length);
- System.arraycopy(encodedIntValue, 0, encodedElement,
- 1+encodedLength.length, encodedIntValue.length);
-
- try
- {
- assertEquals(intValue,
- ASN1Enumerated.decodeAsEnumerated(encodedElement).intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsEnumerated(byte[]) threw an exception for " +
- "type=00, intValue=" + intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsEnumerated(byte[]) failed for type=00, " +
- "intValue=" + intValue);
- throw afe;
- }
-
-
- encodedElement[0] = (byte) 0x0A;
- try
- {
- assertEquals(intValue,
- ASN1Enumerated.decodeAsEnumerated(encodedElement).intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsEnumerated(byte[]) threw an exception for " +
- "type=0A, intValue=" + intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsEnumerated(byte[]) failed for type=0A, " +
- "intValue=" + intValue);
- throw afe;
- }
- }
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Integer.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Integer.java
deleted file mode 100644
index ba063a5..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Integer.java
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import java.util.*;
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1Integer class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1Integer
- extends DirectoryServerTestCase
-{
- // The set of encoded values for the test integers.
- private ArrayList<byte[]> testEncodedIntegers;
-
- // The set of integer values to use in test cases.
- private ArrayList<Integer> testIntegers;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1Integer(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- testIntegers = new ArrayList<Integer>();
- testEncodedIntegers = new ArrayList<byte[]>();
-
- // Add all values that can be encoded using a single byte.
- for (int i=0; i < 128; i++)
- {
- testIntegers.add(i);
- testEncodedIntegers.add(new byte[] { (byte) (i & 0xFF) });
- }
-
- testIntegers.add(0x80); // The smallest 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0x80 });
-
- testIntegers.add(0xFF); // A boundary case for 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0xFF });
-
- testIntegers.add(0x0100); // A boundary case for 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x01, (byte) 0x00 });
-
- testIntegers.add(0x7FFF); // The largest 2-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F, (byte) 0xFF });
-
- testIntegers.add(0x8000); // The smallest 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0x80,
- (byte) 0x00 });
-
- testIntegers.add(0xFFFF); // A boundary case for 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0xFF,
- (byte) 0xFF });
-
- testIntegers.add(0x010000); // A boundary case for 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x01, (byte) 0x00,
- (byte) 0x00 });
-
- testIntegers.add(0x7FFFFF); // The largest 3-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F, (byte) 0xFF,
- (byte) 0xFF });
-
- testIntegers.add(0x800000); // The smallest 4-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0x80,
- (byte) 0x00, (byte) 0x00 });
-
- testIntegers.add(0xFFFFFF); // A boundary case for 4-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x00, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
-
- testIntegers.add(0x01000000); // A boundary case for 4-byte encoding.
- testEncodedIntegers.add(new byte[] { (byte) 0x01, (byte) 0x00,
- (byte) 0x00, (byte) 0x00 });
-
- testIntegers.add(0x7FFFFFFF); // The largest value we will allow.
- testEncodedIntegers.add(new byte[] { (byte) 0x7F, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>intValue</CODE> method.
- */
- public void testIntValue()
- {
- for (int i : testIntegers)
- {
- ASN1Integer element = new ASN1Integer(i);
-
- try
- {
- assertEquals(i, element.intValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("intValue failed for intValue=" + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes an int argument.
- */
- public void testSetIntValue()
- {
- ASN1Integer element = new ASN1Integer(0);
-
- int numIntegers = testIntegers.size();
- for (int i=0; i < numIntegers; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedIntValue = testEncodedIntegers.get(i);
-
- element.setValue(intValue);
- try
- {
- assertEquals(intValue, element.intValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(" + intValue + ") failed in intValue");
- throw afe;
- }
-
- try
- {
- assertTrue(Arrays.equals(encodedIntValue, element.value()));
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(" + intValue + ") failed in value");
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes a byte array argument.
- */
- public void testSetByteValue()
- {
- ASN1Integer element = new ASN1Integer(0);
-
- int numIntegers = testIntegers.size();
- for (int i=0; i < numIntegers; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedIntValue = testEncodedIntegers.get(i);
-
- try
- {
- element.setValue(encodedIntValue);
- }
- catch (ASN1Exception ae)
- {
- String message = "setValue(byte[]) threw an exception for intValue=" +
- intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
-
- try
- {
- assertEquals(intValue, element.intValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(byte[]) failed for intValue=" + intValue);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsInteger</CODE> method that takes an ASN.1 element
- * argument.
- */
- public void testDecodeElementAsInteger()
- {
- int numIntegers = testIntegers.size();
- for (int i=0; i < numIntegers; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedIntValue = testEncodedIntegers.get(i);
-
- ASN1Element element = new ASN1Element((byte) 0x00, encodedIntValue);
-
- try
- {
- assertEquals(intValue, ASN1Integer.decodeAsInteger(element).intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsInteger(element(" + intValue +
- ")) threw an exception for type=00";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsInteger(element(" + intValue +
- ")) failed for type=00");
- throw afe;
- }
-
-
- element = new ASN1Element((byte) 0x02, encodedIntValue);
-
- try
- {
- assertEquals(intValue, ASN1Integer.decodeAsInteger(element).intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsInteger(element(" + intValue +
- ")) threw an exception for type=02";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsInteger(element(" + intValue +
- ")) failed for type=02");
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array
- * argument.
- */
- public void testDecodeBytesAsInteger()
- {
- int numIntegers = testIntegers.size();
- for (int i=0; i < numIntegers; i++)
- {
- int intValue = testIntegers.get(i);
- byte[] encodedIntValue = testEncodedIntegers.get(i);
- byte[] encodedLength = ASN1Element.encodeLength(encodedIntValue.length);
- byte[] encodedElement = new byte[1 + encodedLength.length +
- encodedIntValue.length];
-
- encodedElement[0] = (byte) 0x00;
- System.arraycopy(encodedLength, 0, encodedElement, 1,
- encodedLength.length);
- System.arraycopy(encodedIntValue, 0, encodedElement,
- 1+encodedLength.length, encodedIntValue.length);
-
- try
- {
- assertEquals(intValue,
- ASN1Integer.decodeAsInteger(encodedElement).intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsInteger(byte[]) threw an exception for " +
- "type=00, intValue=" + intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsInteger(byte[]) failed for type=00, " +
- "intValue=" + intValue);
- throw afe;
- }
-
-
- encodedElement[0] = (byte) 0x02;
- try
- {
- assertEquals(intValue,
- ASN1Integer.decodeAsInteger(encodedElement).intValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsInteger(byte[]) threw an exception for " +
- "type=02, intValue=" + intValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsInteger(byte[]) failed for type=02, " +
- "intValue=" + intValue);
- throw afe;
- }
- }
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Long.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Long.java
deleted file mode 100644
index 10b3c81..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Long.java
+++ /dev/null
@@ -1,440 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import java.util.*;
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1Long class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1Long
- extends DirectoryServerTestCase
-{
- // The set of encoded values for the test longs.
- private ArrayList<byte[]> testEncodedLongs;
-
- // The set of long values to use in test cases.
- private ArrayList<Long> testLongs;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1Long(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- testLongs = new ArrayList<Long>();
- testEncodedLongs = new ArrayList<byte[]>();
-
- // Add all values that can be encoded using a single byte.
- for (int i=0; i < 128; i++)
- {
- testLongs.add(new Long(i));
- testEncodedLongs.add(new byte[] { (byte) (i & 0xFF) });
- }
-
- testLongs.add(new Long(0x80)); // The smallest 2-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0x80 });
-
- testLongs.add(new Long(0xFF)); // A boundary case for 2-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0xFF });
-
- testLongs.add(new Long(0x0100)); // A boundary case for 2-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x01, (byte) 0x00 });
-
- testLongs.add(new Long(0x7FFF)); // The largest 2-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x7F, (byte) 0xFF });
-
- testLongs.add(new Long(0x8000)); // The smallest 3-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0x80, (byte) 0x00 });
-
- testLongs.add(new Long(0xFFFF)); // A boundary case for 3-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0xFF, (byte) 0xFF });
-
- testLongs.add(new Long(0x010000)); // A boundary case for 3-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 });
-
- testLongs.add(new Long(0x7FFFFF)); // The largest 3-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF });
-
- testLongs.add(new Long(0x800000)); // The smallest 4-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0x80, (byte) 0x00,
- (byte) 0x00 });
-
- testLongs.add(new Long(0xFFFFFF)); // A boundary case for 4-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF });
-
- testLongs.add(new Long(0x01000000)); // A boundary case for 4-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00,
- (byte) 0x00 });
-
- testLongs.add(new Long(0x7FFFFFFF)); // The largest 4-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF });
-
- testLongs.add(0x80000000L); // The smallest 5-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0x80, (byte) 0x00,
- (byte) 0x00, (byte) 0x00 });
-
- testLongs.add(0xFFFFFFFFL); // A boundary case for 5-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
-
- testLongs.add(0x0100000000L); // A boundary case for 5-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00 });
-
- testLongs.add(0x07FFFFFFFFL); // The largest 5-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x07, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
-
- testLongs.add(0x8000000000L); // The smallest 6-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0x80, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00 });
-
- testLongs.add(0xFFFFFFFFFFL); // A boundary case for 6-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF });
-
- testLongs.add(0x010000000000L); // A boundary case for 6-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00 });
-
- testLongs.add(0x07FFFFFFFFFFL); // The largest 6-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x07, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF });
-
- testLongs.add(0x800000000000L); // The smallest 7-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0x80, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00 });
-
- testLongs.add(0xFFFFFFFFFFFFL); // A boundary case for 7-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF });
-
- testLongs.add(0x01000000000000L); // A boundary case for 7-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00 });
-
- testLongs.add(0x07FFFFFFFFFFFFL); // The largest 7-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x07, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF });
-
- testLongs.add(0x80000000000000L); // The smallest 8-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0x80, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00 });
-
- testLongs.add(0xFFFFFFFFFFFFFFL); // A boundary case for 8-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x00, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
-
- testLongs.add(0x0100000000000000L); // A boundary case for 8-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00 });
-
- testLongs.add(0x07FFFFFFFFFFFFFFL); // The largest 8-byte encoding.
- testEncodedLongs.add(new byte[] { (byte) 0x07, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF });
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>longValue</CODE> method.
- */
- public void testLongValue()
- {
- for (long l : testLongs)
- {
- ASN1Long element = new ASN1Long(l);
-
- try
- {
- assertEquals(l, element.longValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("longValue failed for longValue=" + l);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes a long argument.
- */
- public void testSetLongValue()
- {
- ASN1Long element = new ASN1Long(0);
-
- int numLongs = testLongs.size();
- for (int i=0; i < numLongs; i++)
- {
- long longValue = testLongs.get(i);
- byte[] encodedLongValue = testEncodedLongs.get(i);
-
- element.setValue(longValue);
- try
- {
- assertEquals(longValue, element.longValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(" + longValue + ") failed in longValue");
- throw afe;
- }
-
- try
- {
- assertTrue(Arrays.equals(encodedLongValue, element.value()));
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(" + longValue + ") failed in value");
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes a byte array argument.
- */
- public void testSetByteValue()
- {
- ASN1Long element = new ASN1Long(0);
-
- int numLongs = testLongs.size();
- for (int i=0; i < numLongs; i++)
- {
- long longValue = testLongs.get(i);
- byte[] encodedLongValue = testEncodedLongs.get(i);
-
- try
- {
- element.setValue(encodedLongValue);
- }
- catch (ASN1Exception ae)
- {
- String message = "setValue(byte[]) threw an exception for longValue=" +
- longValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
-
- try
- {
- assertEquals(longValue, element.longValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(byte[]) failed for longValue=" + longValue);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsLong</CODE> method that takes an ASN.1 element
- * argument.
- */
- public void testDecodeElementAsLong()
- {
- int numLongs = testLongs.size();
- for (int i=0; i < numLongs; i++)
- {
- long longValue = testLongs.get(i);
- byte[] encodedLongValue = testEncodedLongs.get(i);
-
- ASN1Element element = new ASN1Element((byte) 0x00, encodedLongValue);
-
- try
- {
- assertEquals(longValue, ASN1Long.decodeAsLong(element).longValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsLong(element(" + longValue +
- ")) threw an exception for type=00";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsLong(element(" + longValue +
- ")) failed for type=00");
- throw afe;
- }
-
-
- element = new ASN1Element((byte) 0x02, encodedLongValue);
-
- try
- {
- assertEquals(longValue, ASN1Long.decodeAsLong(element).longValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsLong(element(" + longValue +
- ")) threw an exception for type=02";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsLong(element(" + longValue +
- ")) failed for type=02");
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsLong</CODE> method that takes a byte array
- * argument.
- */
- public void testDecodeBytesAsLong()
- {
- int numLongs = testLongs.size();
- for (int i=0; i < numLongs; i++)
- {
- long longValue = testLongs.get(i);
- byte[] encodedLongValue = testEncodedLongs.get(i);
- byte[] encodedLength = ASN1Element.encodeLength(
- encodedLongValue.length);
- byte[] encodedElement = new byte[1 + encodedLength.length +
- encodedLongValue.length];
-
- encodedElement[0] = (byte) 0x00;
- System.arraycopy(encodedLength, 0, encodedElement, 1,
- encodedLength.length);
- System.arraycopy(encodedLongValue, 0, encodedElement,
- 1+encodedLength.length, encodedLongValue.length);
-
- try
- {
- assertEquals(longValue,
- ASN1Long.decodeAsLong(encodedElement).longValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsLong(byte[]) threw an exception for " +
- "type=00, longValue=" + longValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsLong(byte[]) failed for type=00, " +
- "longValue=" + longValue);
- throw afe;
- }
-
-
- encodedElement[0] = (byte) 0x02;
- try
- {
- assertEquals(longValue,
- ASN1Long.decodeAsLong(encodedElement).longValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsLong(byte[]) threw an exception for " +
- "type=02, longValue=" + longValue;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsLong(byte[]) failed for type=02, " +
- "longValue=" + longValue);
- throw afe;
- }
- }
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Null.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Null.java
deleted file mode 100644
index a38be96..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Null.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1Null class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1Null
- extends DirectoryServerTestCase
-{
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1Null(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method.
- */
- public void testSetValue()
- {
- ASN1Null element = new ASN1Null();
-
- // Test with a null array.
- try
- {
- element.setValue(null);
- }
- catch (ASN1Exception ae)
- {
- String message = "setValue(null) threw an exception";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
-
-
- // Test with an empty array.
- try
- {
- element.setValue(new byte[0]);
- }
- catch (ASN1Exception ae)
- {
- String message = "setValue(bye[0]) threw an exception";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsNull</CODE> method that takes an ASN.1 element
- * argument.
- */
- public void testDecodeElementAsNull()
- {
- // Test with a type of 0x00.
- ASN1Element element = new ASN1Element((byte) 0x00);
-
- try
- {
- ASN1Null.decodeAsNull(element);
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsNull(element) threw an exception for type=00";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
-
-
- // Test with a type of 0x05.
- element = new ASN1Element((byte) 0x05);
- try
- {
- ASN1Null.decodeAsNull(element);
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsNull(element) threw an exception for type=05";
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsNull</CODE> method that takes a byte array
- * argument.
- */
- public void testDecodeBytesAsNull()
- {
- byte[] encodedElement = new byte[] { (byte) 0x00, (byte) 0x00 };
-
- // Test with all possible type representations.
- for (int i=0; i < 256; i++)
- {
- byte type = (byte) (i & 0xFF);
- encodedElement[0] = type;
-
- try
- {
- ASN1Null.decodeAsNull(encodedElement);
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsNull(byte[]) threw an exception for type=" +
- byteToHex(type);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- }
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1OctetString.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1OctetString.java
deleted file mode 100644
index 11c51a3..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1OctetString.java
+++ /dev/null
@@ -1,588 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import java.util.*;
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1OctetString class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1OctetString
- extends DirectoryServerTestCase
-{
- // The set of binary values that should be used in test cases.
- private ArrayList<byte[]> testByteValues;
-
- // The set of encoded versions of the provided string values.
- private ArrayList<byte[]> testEncodedStrings;
-
- // The set of string values that should be used in test cases.
- private ArrayList<String> testStrings;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1OctetString(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- // Initialize the set of binary values. Don't make these too big since they
- // consume memory.
- testByteValues = new ArrayList<byte[]>();
- testByteValues.add(null); // The null value.
- testByteValues.add(new byte[0x00]); // The zero-byte value.
- testByteValues.add(new byte[0x01]); // The single-byte value.
- testByteValues.add(new byte[0x7F]); // The largest 1-byte length encoding.
- testByteValues.add(new byte[0x80]);
- testByteValues.add(new byte[0xFF]); // The largest 2-byte length encoding.
- testByteValues.add(new byte[0x0100]);
- testByteValues.add(new byte[0xFFFF]); // The largest 3-byte length encoding.
- testByteValues.add(new byte[0x010000]);
-
-
- // Initialize the set of string values.
- testStrings = new ArrayList<String>();
- testEncodedStrings = new ArrayList<byte[]>();
-
- testStrings.add(null);
- testEncodedStrings.add(new byte[0]);
-
- testStrings.add("");
- testEncodedStrings.add(new byte[0]);
-
- String lastString = "";
- for (int i=0; i <= 256; i++)
- {
- String newString = lastString + "a";
- testStrings.add(newString);
- testEncodedStrings.add(getBytes(newString));
-
- lastString = newString;
- }
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>stringValue</CODE> method.
- */
- public void testStringValue()
- {
- for (String s : testStrings)
- {
- try
- {
- if (s == null)
- {
- assertEquals("", new ASN1OctetString(s).stringValue());
- }
- else
- {
- assertEquals(s, new ASN1OctetString(s).stringValue());
- }
- }
- catch (AssertionFailedError afe)
- {
- printError("stringValue failed for string=" + s);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes a string argument.
- */
- public void testSetStringValue()
- {
- ASN1OctetString element = new ASN1OctetString();
-
- int numStrings = testStrings.size();
- for (int i=0; i < numStrings; i++)
- {
- String s = testStrings.get(i);
- byte[] b = testEncodedStrings.get(i);
-
- String compareValue;
- if (s == null)
- {
- compareValue = "";
- }
- else
- {
- compareValue = s;
- }
-
- element.setValue(s);
- try
- {
- assertEquals(compareValue, element.stringValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(" + s + ") failed stringValue test");
- throw afe;
- }
-
- try
- {
- assertTrue(Arrays.equals(b, element.value()));
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(" + s + ") failed byte[] value test");
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method that takes a byte array argument.
- */
- public void testSetByteValue()
- {
- ASN1OctetString element = new ASN1OctetString();
-
- // Test the binary representations.
- for (byte[] value : testByteValues)
- {
- byte[] compareValue;
- if (value == null)
- {
- compareValue = new byte[0];
- }
- else
- {
- compareValue = value;
- }
-
-
- try
- {
- element.setValue(value);
- }
- catch (Exception e)
- {
- String message = "setValue(byte[]) threw an exception for value=" +
- bytesToHex(value);
- printError(message);
- printException(e);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(e));
- }
-
- try
- {
- assertTrue(Arrays.equals(compareValue, element.value()));
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(byte[]) failed for value=" + bytesToHex(value));
- throw afe;
- }
- }
-
-
- // Test the string representations.
- int numStrings = testStrings.size();
- for (int i=0; i < numStrings; i++)
- {
- String s = testStrings.get(i);
- byte[] b = testEncodedStrings.get(i);
-
- String compareString;
- if (s == null)
- {
- compareString = "";
- }
- else
- {
- compareString = s;
- }
-
- try
- {
- element.setValue(b);
- }
- catch (Exception e)
- {
- String message = "setValue(byte[]) threw an exception for string=" + s;
- printError(message);
- printException(e);
- throw new AssertionFailedError(message = " -- " +
- stackTraceToSingleLineString(e));
- }
-
- try
- {
- assertEquals(compareString, element.stringValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(byte[]) failed stringValue test for string=" + s);
- throw afe;
- }
-
- try
- {
- assertTrue(Arrays.equals(b, element.value()));
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue(byte[]) failed byte[] value test for string=" + s);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsOctetString</CODE> method that takes an ASN.1
- * element argument.
- */
- public void testDecodeElementAsOctetString()
- {
- // Run tests with the binary values.
- for (byte[] value : testByteValues)
- {
- ASN1Element element = new ASN1Element((byte) 0x00, value);
-
- byte[] compareValue;
- if (value == null)
- {
- compareValue = new byte[0];
- }
- else
- {
- compareValue = value;
- }
-
- try
- {
- assertTrue(Arrays.equals(compareValue,
- ASN1OctetString.decodeAsOctetString(element).value()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsOctetString(element) threw an exception " +
- "for bytes=" + bytesToHex(value);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsOctetString(element) failed for bytes=" +
- bytesToHex(value));
- throw afe;
- }
- }
-
-
- // Run tests with the string values.
- int numStrings = testStrings.size();
- for (int i=0; i < numStrings; i++)
- {
- String s = testStrings.get(i);
- byte[] b = testEncodedStrings.get(i);
-
- String compareString;
- if (s == null)
- {
- compareString = "";
- }
- else
- {
- compareString = s;
- }
-
-
- ASN1Element element = new ASN1Element((byte) 0x00, b);
-
- try
- {
- assertEquals(compareString,
- ASN1OctetString.decodeAsOctetString(element).stringValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsOctetString(element) threw an exception " +
- "for string=" + s;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsOctetString(element) failed for string=" + s);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsOctetString</CODE> method that takes a byte array
- * argument.
- */
- public void testDecodeBytesAsOctetString()
- {
- // Run tests with the binary values.
- for (byte[] value : testByteValues)
- {
- byte[] encodedLength;
- byte[] encodedElement;
- if (value == null)
- {
- encodedLength = ASN1Element.encodeLength(0);
- encodedElement = new byte[1 + encodedLength.length];
- }
- else
- {
- encodedLength = ASN1Element.encodeLength(value.length);
- encodedElement = new byte[1 + encodedLength.length + value.length];
- }
-
- encodedElement[0] = (byte) 0x00;
- System.arraycopy(encodedLength, 0, encodedElement, 1,
- encodedLength.length);
-
- if (value != null)
- {
- System.arraycopy(value, 0, encodedElement, 1+encodedLength.length,
- value.length);
- }
-
- byte[] compareValue;
- if (value == null)
- {
- compareValue = new byte[0];
- }
- else
- {
- compareValue = value;
- }
-
- try
- {
- assertTrue(Arrays.equals(compareValue,
- ASN1OctetString.decodeAsOctetString(encodedElement).value()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsOctetString(byte[]) threw an exception " +
- "for bytes=" + bytesToHex(value);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsOctetString(byte[]) failed for bytes=" +
- bytesToHex(value));
- throw afe;
- }
- }
-
-
- // Run tests with the string values.
- int numStrings = testStrings.size();
- for (int i=0; i < numStrings; i++)
- {
- String s = testStrings.get(i);
- byte[] b = testEncodedStrings.get(i);
-
- String compareString;
- if (s == null)
- {
- compareString = "";
- }
- else
- {
- compareString = s;
- }
-
-
- byte[] encodedLength = ASN1Element.encodeLength(b.length);
- byte[] encodedElement = new byte[1 + encodedLength.length + b.length];
-
- encodedElement[0] = (byte) 0x00;
- System.arraycopy(encodedLength, 0, encodedElement, 1,
- encodedLength.length);
- System.arraycopy(b, 0, encodedElement, 1+encodedLength.length, b.length);
-
- try
- {
- assertEquals(compareString,
- ASN1OctetString.decodeAsOctetString(encodedElement).stringValue());
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsOctetString(byte[]) threw an exception " +
- "for string=" + s;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsOctetString(byte[]) failed for string=" + s);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>duplicate</CODE> method.
- */
- public void testDuplicate()
- {
- // Run tests with the binary values.
- for (byte[] value : testByteValues)
- {
- ASN1OctetString os1 = new ASN1OctetString(value);
- ASN1OctetString os2 = os1.duplicate();
- try
- {
- assertEquals(os1, os2);
- }
- catch (AssertionFailedError afe)
- {
- printError("duplicate() failed equals test for value=" +
- bytesToHex(value));
- throw afe;
- }
-
- try
- {
- assertEquals(os1.hashCode(), os2.hashCode());
- }
- catch (AssertionFailedError afe)
- {
- printError("duplicate() failed hashCode test for value=" +
- bytesToHex(value));
- throw afe;
- }
- }
-
-
- // Run tests with the string values.
- int numStrings = testStrings.size();
- for (int i=0; i < numStrings; i++)
- {
- String s = testStrings.get(i);
-
- String compareString;
- if (s == null)
- {
- compareString = "";
- }
- else
- {
- compareString = s;
- }
-
- ASN1OctetString os1 = new ASN1OctetString(s);
- ASN1OctetString os2 = os1.duplicate();
- try
- {
- assertEquals(os1, os2);
- }
- catch (AssertionFailedError afe)
- {
- printError("duplicate(" + s + ") failed object equals test");
- throw afe;
- }
-
- try
- {
- assertEquals(compareString, os2.stringValue());
- }
- catch (AssertionFailedError afe)
- {
- printError("duplicate(" + s + ") failed string equals test");
- throw afe;
- }
-
- try
- {
- assertEquals(os1.hashCode(), os2.hashCode());
- }
- catch (AssertionFailedError afe)
- {
- printError("duplicate(" + s + ") failed hashCode test");
- throw afe;
- }
- }
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1ReaderAndWriter.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1ReaderAndWriter.java
deleted file mode 100644
index b575e07..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1ReaderAndWriter.java
+++ /dev/null
@@ -1,706 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import java.io.*;
-import java.util.*;
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1Reader and
- * org.opends.server.protocols.asn1.ASN1Writer classes.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1ReaderAndWriter
- extends DirectoryServerTestCase
-{
- // The set of ASN.1 Boolean elements that will be written and read.
- private ArrayList<ASN1Boolean> booleanElements;
-
- // The set of ASN.1 enumerated elements that will be written and read.
- private ArrayList<ASN1Enumerated> enumeratedElements;
-
- // The set of generic ASN.1 elements that will be written and read.
- private ArrayList<ASN1Element> genericElements;
-
- // The set of ASN.1 integer elements that will be written and read.
- private ArrayList<ASN1Integer> integerElements;
-
- // The set of ASN.1 null elements that will be written and read.
- private ArrayList<ASN1Null> nullElements;
-
- // The set of ASN.1 octet string elements that will be written and read.
- private ArrayList<ASN1OctetString> octetStringElements;
-
- // The set of ASN.1 sequence elements that will be written and read.
- private ArrayList<ASN1Sequence> sequenceElements;
-
- // The set of ASN.1 enumerated elements that will be written and read.
- private ArrayList<ASN1Set> setElements;
-
- // The data file to which data will be written and read back.
- private File dataFile;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1ReaderAndWriter(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- *
- * @throws Exception If a problem occurs during initialization.
- */
- public void setUp()
- throws Exception
- {
- // Create the temporary file that we will write to and read from.
- dataFile = File.createTempFile("TestASN1ReaderAndWriter-", ".data");
-
-
- // Create the set of generic elements that will be written and read.
- genericElements = new ArrayList<ASN1Element>();
- genericElements.add(new ASN1Element((byte) 0x00));
- genericElements.add(new ASN1Element((byte) 0x00, null));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[0]));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[1]));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[127]));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[128]));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[255]));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[256]));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[32767]));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[32768]));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[65535]));
- genericElements.add(new ASN1Element((byte) 0x00, new byte[65536]));
-
-
- // Create the set of Boolean elements that will be written and read.
- booleanElements = new ArrayList<ASN1Boolean>();
- booleanElements.add(new ASN1Boolean(false));
- booleanElements.add(new ASN1Boolean(true));
- booleanElements.add(new ASN1Boolean((byte) 0x00, false));
- booleanElements.add(new ASN1Boolean((byte) 0x00, true));
-
-
- // Create the set of enumerated elements that will be written and read.
- enumeratedElements = new ArrayList<ASN1Enumerated>();
- enumeratedElements.add(new ASN1Enumerated(0));
- enumeratedElements.add(new ASN1Enumerated(1));
- enumeratedElements.add(new ASN1Enumerated(127));
- enumeratedElements.add(new ASN1Enumerated(128));
- enumeratedElements.add(new ASN1Enumerated(255));
- enumeratedElements.add(new ASN1Enumerated(256));
- enumeratedElements.add(new ASN1Enumerated(32767));
- enumeratedElements.add(new ASN1Enumerated(32768));
- enumeratedElements.add(new ASN1Enumerated(65535));
- enumeratedElements.add(new ASN1Enumerated(65536));
-
-
- // Create the set of integer elements that will be written and read.
- integerElements = new ArrayList<ASN1Integer>();
- integerElements.add(new ASN1Integer(0));
- integerElements.add(new ASN1Integer(1));
- integerElements.add(new ASN1Integer(127));
- integerElements.add(new ASN1Integer(128));
- integerElements.add(new ASN1Integer(255));
- integerElements.add(new ASN1Integer(256));
- integerElements.add(new ASN1Integer(32767));
- integerElements.add(new ASN1Integer(32768));
- integerElements.add(new ASN1Integer(65535));
- integerElements.add(new ASN1Integer(65536));
-
-
- // Create the set of null elements that will be written and read.
- nullElements = new ArrayList<ASN1Null>();
- nullElements.add(new ASN1Null());
- for (int i=0; i < 256; i++)
- {
- byte type = (byte) (i & 0xFF);
- nullElements.add(new ASN1Null(type));
- }
-
-
- // Create the set of octet string elements that will be written and read.
- octetStringElements = new ArrayList<ASN1OctetString>();
- octetStringElements.add(new ASN1OctetString());
- octetStringElements.add(new ASN1OctetString((byte[]) null));
- octetStringElements.add(new ASN1OctetString((String) null));
- octetStringElements.add(new ASN1OctetString(new byte[0]));
- octetStringElements.add(new ASN1OctetString(new byte[1]));
- octetStringElements.add(new ASN1OctetString(new byte[127]));
- octetStringElements.add(new ASN1OctetString(new byte[128]));
- octetStringElements.add(new ASN1OctetString(new byte[255]));
- octetStringElements.add(new ASN1OctetString(new byte[256]));
- octetStringElements.add(new ASN1OctetString(new byte[32767]));
- octetStringElements.add(new ASN1OctetString(new byte[32768]));
- octetStringElements.add(new ASN1OctetString(new byte[65535]));
- octetStringElements.add(new ASN1OctetString(new byte[65536]));
- octetStringElements.add(new ASN1OctetString(""));
- octetStringElements.add(new ASN1OctetString("a"));
-
- char[] chars127 = new char[127];
- Arrays.fill(chars127, 'a');
- octetStringElements.add(new ASN1OctetString(new String(chars127)));
-
- char[] chars128 = new char[128];
- Arrays.fill(chars128, 'a');
- octetStringElements.add(new ASN1OctetString(new String(chars128)));
-
-
- // Create the set of sequence elements that will be written and read.
- sequenceElements = new ArrayList<ASN1Sequence>();
- sequenceElements.add(new ASN1Sequence());
- sequenceElements.add(new ASN1Sequence(null));
- sequenceElements.add(new ASN1Sequence(new ArrayList<ASN1Element>(0)));
- sequenceElements.add(new ASN1Sequence(genericElements));
- sequenceElements.add(new ASN1Sequence(
- new ArrayList<ASN1Element>(booleanElements)));
- sequenceElements.add(new ASN1Sequence(
- new ArrayList<ASN1Element>(enumeratedElements)));
- sequenceElements.add(new ASN1Sequence(
- new ArrayList<ASN1Element>(integerElements)));
- sequenceElements.add(new ASN1Sequence(
- new ArrayList<ASN1Element>(nullElements)));
- sequenceElements.add(new ASN1Sequence(
- new ArrayList<ASN1Element>(octetStringElements)));
-
-
- // Create the set of set elements that will be written and read.
- setElements = new ArrayList<ASN1Set>();
- setElements.add(new ASN1Set());
- setElements.add(new ASN1Set(null));
- setElements.add(new ASN1Set(new ArrayList<ASN1Element>(0)));
- setElements.add(new ASN1Set(genericElements));
- setElements.add(new ASN1Set(new ArrayList<ASN1Element>(booleanElements)));
- setElements.add(new ASN1Set(
- new ArrayList<ASN1Element>(enumeratedElements)));
- setElements.add(new ASN1Set(new ArrayList<ASN1Element>(integerElements)));
- setElements.add(new ASN1Set(new ArrayList<ASN1Element>(nullElements)));
- setElements.add(new ASN1Set(
- new ArrayList<ASN1Element>(octetStringElements)));
- setElements.add(new ASN1Set(new ArrayList<ASN1Element>(sequenceElements)));
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- *
- * @throws Exception If a problem occurs during cleanup.
- */
- public void tearDown()
- throws Exception
- {
- // Delete the temporary data file.
- dataFile.delete();
- }
-
-
-
- /**
- * Tests the <CODE>ASN1Writer.writeElement</CODE> and the
- * <CODE>ASN1Reader.readElement</CODE> methods.
- */
- public void testWriteAndRead()
- {
- // Create the ASN.1 writer that will be used to write the elements.
- ASN1Writer asn1Writer;
- try
- {
- asn1Writer = new ASN1Writer(new FileOutputStream(dataFile, false));
- }
- catch (IOException ioe)
- {
- String message = "Unable to create output file " +
- dataFile.getAbsolutePath() + " for writing";
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
-
-
- // Write the set of generic elements.
- for (ASN1Element element : genericElements)
- {
- try
- {
- asn1Writer.writeElement(element);
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to write generic ASN.1 " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- }
-
- // Write the set of Boolean elements.
- for (ASN1Boolean element : booleanElements)
- {
- try
- {
- asn1Writer.writeElement(element);
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to write ASN.1 Boolean " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- }
-
- // Write the set of enumerated elements.
- for (ASN1Enumerated element : enumeratedElements)
- {
- try
- {
- asn1Writer.writeElement(element);
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to write ASN.1 enumerated " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- }
-
- // Write the set of integer elements.
- for (ASN1Integer element : integerElements)
- {
- try
- {
- asn1Writer.writeElement(element);
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to write ASN.1 integer " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- }
-
- // Write the set of null elements.
- for (ASN1Null element : nullElements)
- {
- try
- {
- asn1Writer.writeElement(element);
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to write ASN.1 null " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- }
-
- // Write the set of octet string elements.
- for (ASN1OctetString element : octetStringElements)
- {
- try
- {
- asn1Writer.writeElement(element);
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to write ASN.1 octet " +
- "string element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- }
-
- // Write the set of sequence elements.
- for (ASN1Sequence element : sequenceElements)
- {
- try
- {
- asn1Writer.writeElement(element);
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to write ASN.1 sequence " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- }
-
- // Write the set of set elements.
- for (ASN1Set element : setElements)
- {
- try
- {
- asn1Writer.writeElement(element);
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to write ASN.1 set " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- }
-
-
- // Always remember to close the output file.
- asn1Writer.close();
-
-
- // Create the ASN.1 reader that will be used to read the elements back.
- ASN1Reader asn1Reader;
- try
- {
- asn1Reader = new ASN1Reader(new FileInputStream(dataFile));
- }
- catch (IOException ioe)
- {
- String message = "Unable to open data file " +
- dataFile.getAbsolutePath() + " for reading";
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
-
-
- // Read back the set of generic elements.
- for (ASN1Element element : genericElements)
- {
- try
- {
- assertEquals(element, asn1Reader.readElement());
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to read generic element " +
- String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- catch (ASN1Exception ae)
- {
- String message = "ASN.1 exception attempting to decode generic " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("readElement failed to read generic element equal to " +
- String.valueOf(element));
- throw afe;
- }
- }
-
- // Read back the set of Boolean elements.
- for (ASN1Boolean element : booleanElements)
- {
- try
- {
- assertEquals(element.booleanValue(),
- asn1Reader.readElement().decodeAsBoolean().booleanValue());
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to read Boolean element " +
- String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- catch (ASN1Exception ae)
- {
- String message = "ASN.1 exception attempting to decode Boolean " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("readElement failed to read Boolean element equal to " +
- String.valueOf(element));
- throw afe;
- }
- }
-
- // Read back the set of enumerated elements.
- for (ASN1Enumerated element : enumeratedElements)
- {
- try
- {
- assertEquals(element.intValue(),
- asn1Reader.readElement().decodeAsEnumerated().intValue());
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to read enumerated " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- catch (ASN1Exception ae)
- {
- String message = "ASN.1 exception attempting to decode enumerated " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("readElement failed to read enumerated element equal to " +
- String.valueOf(element));
- throw afe;
- }
- }
-
- // Read back the set of integer elements.
- for (ASN1Integer element : integerElements)
- {
- try
- {
- assertEquals(element.intValue(),
- asn1Reader.readElement().decodeAsInteger().intValue());
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to read integer element " +
- String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- catch (ASN1Exception ae)
- {
- String message = "ASN.1 exception attempting to decode integer " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("readElement failed to read integer element equal to " +
- String.valueOf(element));
- throw afe;
- }
- }
-
- // Read back the set of null elements.
- for (ASN1Null element : nullElements)
- {
- try
- {
- assertEquals(element, asn1Reader.readElement().decodeAsNull());
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to read null element " +
- String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- catch (ASN1Exception ae)
- {
- String message = "ASN.1 exception attempting to decode null " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("readElement failed to read null element equal to " +
- String.valueOf(element));
- throw afe;
- }
- }
-
- // Read back the set of octet string elements.
- for (ASN1OctetString element : octetStringElements)
- {
- try
- {
- assertEquals(element, asn1Reader.readElement().decodeAsOctetString());
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to read octet string " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- catch (ASN1Exception ae)
- {
- String message = "ASN.1 exception attempting to decode octet string " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("readElement failed to read octet string element equal to " +
- String.valueOf(element));
- throw afe;
- }
- }
-
- // Read back the set of sequence elements.
- for (ASN1Sequence element : sequenceElements)
- {
- try
- {
- assertTrue(listsAreEqual(element.elements(),
- asn1Reader.readElement().decodeAsSequence().elements()));
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to read sequence element " +
- String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- catch (ASN1Exception ae)
- {
- String message = "ASN.1 exception attempting to decode sequence " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("readElement failed to read sequence element equal to " +
- String.valueOf(element));
- throw afe;
- }
- }
-
- // Read back the set of set elements.
- for (ASN1Set element : setElements)
- {
- try
- {
- assertTrue(listsAreEqual(element.elements(),
- asn1Reader.readElement().decodeAsSet().elements()));
- }
- catch (IOException ioe)
- {
- String message = "I/O exception attempting to read set element " +
- String.valueOf(element);
- printError(message);
- printException(ioe);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ioe));
- }
- catch (ASN1Exception ae)
- {
- String message = "ASN.1 exception attempting to decode set " +
- "element " + String.valueOf(element);
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("readElement failed to read set element equal to " +
- String.valueOf(element));
- throw afe;
- }
- }
-
-
- // Always remember to close the input file.
- asn1Reader.close();
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Sequence.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Sequence.java
deleted file mode 100644
index d348b6f..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Sequence.java
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import java.util.*;
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1Sequence class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1Sequence
- extends DirectoryServerTestCase
-{
- // The sets of pre-encoded ASN.1 elements that will be included in the test
- // case.
- private ArrayList<ArrayList<ASN1Element>> testElementSets;
-
- // The set of pre-encoded element sets that will be used in the test cases.
- private ArrayList<byte[]> testEncodedElementSets;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1Sequence(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- // Initialize the sets of ASN.1 elements that will be used in testing the
- // group encode/decode operations.
- testElementSets = new ArrayList<ArrayList<ASN1Element>>();
- testEncodedElementSets = new ArrayList<byte[]>();
-
- testElementSets.add(null); // The null set.
- testEncodedElementSets.add(new byte[0]);
-
- testElementSets.add(new ArrayList<ASN1Element>(0)); // The empty set.
- testEncodedElementSets.add(new byte[0]);
-
-
- // Sets containing from 1 to 10 zero-length elements.
- for (int i=1; i <= 10; i++)
- {
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(i);
-
- for (int j=0; j < i; j++)
- {
- elements.add(new ASN1Element((byte) 0x00));
- }
- testElementSets.add(elements);
- testEncodedElementSets.add(new byte[i*2]);
- }
-
-
- // Sets containing from 1 to 10 1-byte-length elements.
- for (int i=1; i <= 10; i++)
- {
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(i);
-
- byte[] encodedElements = new byte[i*3];
- for (int j=0; j < i; j++)
- {
- elements.add(new ASN1Element((byte) 0x00, new byte[1]));
- encodedElements[(j*3)+1] = (byte) 0x01;
- }
-
- testElementSets.add(elements);
- testEncodedElementSets.add(encodedElements);
- }
-
-
- // Sets containing from 1 to 10 127-byte-length elements.
- for (int i=1; i <= 10; i++)
- {
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(i);
-
- byte[] encodedElements = new byte[i*129];
- for (int j=0; j < i; j++)
- {
- elements.add(new ASN1Element((byte) 0x00, new byte[127]));
- encodedElements[(j*129)+1] = (byte) 0x7F;
- }
-
- testElementSets.add(elements);
- testEncodedElementSets.add(encodedElements);
- }
-
-
- // Sets containing from 1 to 10 128-byte-length elements.
- for (int i=1; i <= 10; i++)
- {
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(i);
-
- byte[] encodedElements = new byte[i*131];
- for (int j=0; j < i; j++)
- {
- elements.add(new ASN1Element((byte) 0x00, new byte[128]));
- encodedElements[(j*131)+1] = (byte) 0x81;
- encodedElements[(j*131)+2] = (byte) 0x80;
- }
-
- testElementSets.add(elements);
- testEncodedElementSets.add(encodedElements);
- }
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>elements</CODE> method.
- */
- public void testElements()
- {
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- ASN1Sequence element = new ASN1Sequence(elementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList, element.elements()));
- }
- catch (AssertionFailedError afe)
- {
- printError("elements failed for list set " + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setElements</CODE> method.
- */
- public void testSetElements()
- {
- ASN1Sequence element = new ASN1Sequence();
-
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- element.setElements(elementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList, element.elements()));
- }
- catch (AssertionFailedError afe)
- {
- printError("elements failed for list set " + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method.
- */
- public void testSetValue()
- {
- ASN1Sequence element = new ASN1Sequence();
-
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
- byte[] encodedElementSet = testEncodedElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- try
- {
- element.setValue(encodedElementSet);
- }
- catch (ASN1Exception ae)
- {
- String message = "setValue threw an exception for list set " + i;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
-
- try
- {
- assertTrue(listsAreEqual(compareList, element.elements()));
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue failed for list set " + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsSequence</CODE> method that takes an ASN.1 element
- * argument.
- */
- public void testDecodeElementAsSequence()
- {
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
- byte[] encodedElementSet = testEncodedElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- ASN1Element element = new ASN1Element((byte) 0x00, encodedElementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList,
- ASN1Sequence.decodeAsSequence(element).elements()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsSequence(element) threw an exception for " +
- "list set " + i;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsSequence(element) failed for list set " + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsSequence</CODE> method that takes a byte array
- * argument.
- */
- public void testDecodeBytesAsSequence()
- {
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
- byte[] encodedElementSet = testEncodedElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- byte[] encodedLength = ASN1Element.encodeLength(encodedElementSet.length);
- byte[] encodedElement = new byte[1 + encodedLength.length +
- encodedElementSet.length];
-
- encodedElement[0] = 0x00;
- System.arraycopy(encodedLength, 0, encodedElement, 1,
- encodedLength.length);
- System.arraycopy(encodedElementSet, 0, encodedElement,
- 1+encodedLength.length, encodedElementSet.length);
-
- try
- {
- assertTrue(listsAreEqual(compareList,
- ASN1Sequence.decodeAsSequence(encodedElement).elements()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsSequence(byte[]) threw an exception for " +
- "list set " + i;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsSequence(byte[]) failed for list set " + i);
- throw afe;
- }
- }
- }
-}
-
diff --git a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Set.java b/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Set.java
deleted file mode 100644
index 4662cb0..0000000
--- a/opends/tests/unit-tests/src/server/org/opends/server/protocols/asn1/TestASN1Set.java
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.protocols.asn1;
-
-
-
-import java.util.*;
-import junit.framework.*;
-import org.opends.server.*;
-
-import static org.opends.server.util.StaticUtils.*;
-
-
-
-/**
- * This class defines a set of JUnit tests for the
- * org.opends.server.protocols.asn1.ASN1Set class.
- *
- *
- * @author Neil A. Wilson
- */
-public class TestASN1Set
- extends DirectoryServerTestCase
-{
- // The sets of pre-encoded ASN.1 elements that will be included in the test
- // case.
- private ArrayList<ArrayList<ASN1Element>> testElementSets;
-
- // The set of pre-encoded element sets that will be used in the test cases.
- private ArrayList<byte[]> testEncodedElementSets;
-
-
-
- /**
- * Creates a new instance of this JUnit test case with the provided name.
- *
- * @param name The name to use for this JUnit test case.
- */
- public TestASN1Set(String name)
- {
- super(name);
- }
-
-
-
- /**
- * Performs any necessary initialization for this test case.
- */
- public void setUp()
- {
- // Initialize the sets of ASN.1 elements that will be used in testing the
- // group encode/decode operations.
- testElementSets = new ArrayList<ArrayList<ASN1Element>>();
- testEncodedElementSets = new ArrayList<byte[]>();
-
- testElementSets.add(null); // The null set.
- testEncodedElementSets.add(new byte[0]);
-
- testElementSets.add(new ArrayList<ASN1Element>(0)); // The empty set.
- testEncodedElementSets.add(new byte[0]);
-
-
- // Sets containing from 1 to 10 zero-length elements.
- for (int i=1; i <= 10; i++)
- {
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(i);
-
- for (int j=0; j < i; j++)
- {
- elements.add(new ASN1Element((byte) 0x00));
- }
- testElementSets.add(elements);
- testEncodedElementSets.add(new byte[i*2]);
- }
-
-
- // Sets containing from 1 to 10 1-byte-length elements.
- for (int i=1; i <= 10; i++)
- {
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(i);
-
- byte[] encodedElements = new byte[i*3];
- for (int j=0; j < i; j++)
- {
- elements.add(new ASN1Element((byte) 0x00, new byte[1]));
- encodedElements[(j*3)+1] = (byte) 0x01;
- }
-
- testElementSets.add(elements);
- testEncodedElementSets.add(encodedElements);
- }
-
-
- // Sets containing from 1 to 10 127-byte-length elements.
- for (int i=1; i <= 10; i++)
- {
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(i);
-
- byte[] encodedElements = new byte[i*129];
- for (int j=0; j < i; j++)
- {
- elements.add(new ASN1Element((byte) 0x00, new byte[127]));
- encodedElements[(j*129)+1] = (byte) 0x7F;
- }
-
- testElementSets.add(elements);
- testEncodedElementSets.add(encodedElements);
- }
-
-
- // Sets containing from 1 to 10 128-byte-length elements.
- for (int i=1; i <= 10; i++)
- {
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(i);
-
- byte[] encodedElements = new byte[i*131];
- for (int j=0; j < i; j++)
- {
- elements.add(new ASN1Element((byte) 0x00, new byte[128]));
- encodedElements[(j*131)+1] = (byte) 0x81;
- encodedElements[(j*131)+2] = (byte) 0x80;
- }
-
- testElementSets.add(elements);
- testEncodedElementSets.add(encodedElements);
- }
- }
-
-
-
- /**
- * Performs any necessary cleanup for this test case.
- */
- public void tearDown()
- {
- // No implementation required.
- }
-
-
-
- /**
- * Tests the <CODE>elements</CODE> method.
- */
- public void testElements()
- {
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- ASN1Set element = new ASN1Set(elementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList, element.elements()));
- }
- catch (AssertionFailedError afe)
- {
- printError("elements failed for list set " + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setElements</CODE> method.
- */
- public void testSetElements()
- {
- ASN1Set element = new ASN1Set();
-
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- element.setElements(elementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList, element.elements()));
- }
- catch (AssertionFailedError afe)
- {
- printError("elements failed for list set " + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>setValue</CODE> method.
- */
- public void testSetValue()
- {
- ASN1Set element = new ASN1Set();
-
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
- byte[] encodedElementSet = testEncodedElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- try
- {
- element.setValue(encodedElementSet);
- }
- catch (ASN1Exception ae)
- {
- String message = "setValue threw an exception for list set " + i;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
-
- try
- {
- assertTrue(listsAreEqual(compareList, element.elements()));
- }
- catch (AssertionFailedError afe)
- {
- printError("setValue failed for list set " + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsSet</CODE> method that takes an ASN.1 element
- * argument.
- */
- public void testDecodeElementAsSet()
- {
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
- byte[] encodedElementSet = testEncodedElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- ASN1Element element = new ASN1Element((byte) 0x00, encodedElementSet);
-
- try
- {
- assertTrue(listsAreEqual(compareList,
- ASN1Set.decodeAsSet(element).elements()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsSet(element) threw an exception for " +
- "list set " + i;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsSet(element) failed for list set " + i);
- throw afe;
- }
- }
- }
-
-
-
- /**
- * Tests the <CODE>decodeAsSet</CODE> method that takes a byte array
- * argument.
- */
- public void testDecodeBytesAsSet()
- {
- int numElementSets = testElementSets.size();
- for (int i=0; i < numElementSets; i++)
- {
- ArrayList<ASN1Element> elementSet = testElementSets.get(i);
- byte[] encodedElementSet = testEncodedElementSets.get(i);
-
- ArrayList<ASN1Element> compareList;
- if (elementSet == null)
- {
- compareList = new ArrayList<ASN1Element>(0);
- }
- else
- {
- compareList = elementSet;
- }
-
- byte[] encodedLength = ASN1Element.encodeLength(encodedElementSet.length);
- byte[] encodedElement = new byte[1 + encodedLength.length +
- encodedElementSet.length];
-
- encodedElement[0] = 0x00;
- System.arraycopy(encodedLength, 0, encodedElement, 1,
- encodedLength.length);
- System.arraycopy(encodedElementSet, 0, encodedElement,
- 1+encodedLength.length, encodedElementSet.length);
-
- try
- {
- assertTrue(listsAreEqual(compareList,
- ASN1Set.decodeAsSet(encodedElement).elements()));
- }
- catch (ASN1Exception ae)
- {
- String message = "decodeAsSet(byte[]) threw an exception for " +
- "list set " + i;
- printError(message);
- printException(ae);
- throw new AssertionFailedError(message + " -- " +
- stackTraceToSingleLineString(ae));
- }
- catch (AssertionFailedError afe)
- {
- printError("decodeAsSet(byte[]) failed for list set " + i);
- throw afe;
- }
- }
- }
-}
-
--
Gitblit v1.10.0