harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Wu" <wuyue...@gmail.com>
Subject Re: svn commit: r512830 [1/2] - in /harmony/enhanced/classlib/trunk/modules/jndi: make/ src/main/java/javax/naming/ldap/ src/main/java/org/apache/harmony/jndi/internal/tls/config/ src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ src/tes
Date Thu, 01 Mar 2007 03:13:26 GMT
I got following error after this commit. seems the removed ClassFinder
is still referenced by JarFinder and DirFinder.

    [javac] 1. ERROR in
/home/clear/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/tls/config/DirFinder.java
    [javac]  (at line 47)
    [javac]     if (element.getAbsolutePath().endsWith(ClassFinder.cFile)) {
    [javac]                                            ^^^^^^^^^^^
    [javac] ClassFinder cannot be resolved
    [javac] ----------
    [javac] ----------
    [javac] 2. ERROR in
/home/clear/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/tls/config/JarFinder.java
    [javac]  (at line 72)
    [javac]     .getJarEntry(ClassFinder.cFile);
    [javac]                  ^^^^^^^^^^^
    [javac] ClassFinder cannot be resolved
    [javac] ----------
    [javac] 3. ERROR in
/home/clear/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/tls/config/JarFinder.java
    [javac]  (at line 79)
    [javac]     ClassFinder.cFile + Messages.getString("ldap.23")
    [javac]     ^^^^^^^^^^^
    [javac] ClassFinder cannot be resolved
    [javac] ----------
    [javac] 3 problems (3 errors)



On 3/1/07, mloenko@apache.org <mloenko@apache.org> wrote:
> Author: mloenko
> Date: Wed Feb 28 08:20:15 2007
> New Revision: 512830
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=512830
> Log:
> fixed StartTlsRequest and related tests
>
> Added:
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java
>       - copied, changed from r512603, harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestSortControl.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsRequestTest.java
>       - copied, changed from r512603, harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsRequest.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsResponseTest.java
>       - copied, changed from r512603, harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsResponse.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/resources/META-INF/services/javax.naming.ldap.StartTlsResponse
> Removed:
>     harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/tls/config/ClassFinder.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/tls/config/MergePath.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestControlFactory.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestSortControl.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestSortKey.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsRequest.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsResponse.java
> Modified:
>     harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common
>     harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/StartTlsRequest.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortKeyTest.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestInitialLdapContext.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestUnsolicitedNotificationEvent.java
>     harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/mock/ldap/MockStartTlsResponse.java
>
> Modified: harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common?view=diff&rev=512830&r1=512829&r2=512830
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common (original)
> +++ harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common Wed Feb 28 08:20:15 2007
> @@ -2,6 +2,4 @@
>  org/apache/harmony/jndi/provider/dns/TestMgr.java
>
>  # fail for unklnown reason
> -org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsRequest.java
> -org/apache/harmony/jndi/tests/javax/naming/ldap/TestUnsolicitedNotificationEvent.java
>  org/apache/harmony/jndi/tests/javax/naming/ldap/whitebox/TestRdnWhiteBoxDevelopment.java
>
> Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/StartTlsRequest.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/StartTlsRequest.java?view=diff&rev=512830&r1=512829&r2=512830
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/StartTlsRequest.java (original)
> +++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/StartTlsRequest.java Wed Feb 28 08:20:15 2007
> @@ -17,12 +17,15 @@
>
>  package javax.naming.ldap;
>
> +import java.io.BufferedReader;
> +import java.io.IOException;
> +import java.io.InputStreamReader;
> +import java.net.URL;
> +import java.util.Enumeration;
> +
>  import javax.naming.NamingException;
>
>  import org.apache.harmony.jndi.internal.nls.Messages;
> -import org.apache.harmony.jndi.internal.tls.config.ClassFinder;
> -import org.apache.harmony.jndi.internal.tls.config.ConfigFileNotFound;
> -import org.apache.harmony.jndi.internal.tls.config.MergePath;
>
>  /**
>   *
> @@ -45,15 +48,15 @@
>      /**
>       * @ar.org.fitc.spec_ref
>       */
> -    public StartTlsRequest() {
> -
> +    public byte[] getEncodedValue() {
> +        return null;
>      }
>
>      /**
>       * @ar.org.fitc.spec_ref
>       */
> -    public byte[] getEncodedValue() {
> -        return null;
> +    public String getID() {
> +        return OID;
>      }
>
>      /**
> @@ -61,44 +64,56 @@
>       */
>      public ExtendedResponse createExtendedResponse(String id, byte[] berValue,
>              int offset, int length) throws NamingException {
> -        if (!id.equals("1.3.6.1.4.1.1466.20037")) {
> +
> +        if (id != null && !OID.equals(id)) {
>              throw new NamingException(
>                      Messages.getString("ldap.07") +" "+ id);
>          }
> -        MergePath p = new MergePath(new String[] {
> -                System.getProperty("user.dir"),
> -                System.getProperty("java.home"),
> -                System.getProperty("org.apache.harmony.boot.class.path") });
> -        ClassFinder cf = new ClassFinder(p.getPathNames());
> -        String[] classList;
> -        Class retClass;
> +
> +        ClassLoader cl = Thread.currentThread().getContextClassLoader();
> +
>          try {
> -            classList = cf.getClassList();
> -            for (int i = 0; i < classList.length; i++) {
> +            Enumeration<URL> en = cl
> +                    .getResources("META-INF/services/javax.naming.ldap.StartTlsResponse");
> +            while (en.hasMoreElements()) {
> +                URL confFile = en.nextElement();
> +                BufferedReader reader = null;
>                  try {
> -                    retClass = Class.forName(classList[i], true, Thread
> -                            .currentThread().getContextClassLoader());
> -                    try {
> -                        return (StartTlsResponse) retClass.newInstance();
> -                    } catch (InstantiationException e) {
> -                    } catch (IllegalAccessException e) {
> -                    } catch (ClassCastException e) {
> +                    reader = new BufferedReader(new InputStreamReader(confFile
> +                            .openStream()));
> +
> +                    String line;
> +                    while ((line = reader.readLine()) != null) {
> +                        // remove comments, spaces, and tabs
> +                        String className = line.split("#")[0].trim();
> +
> +                        // try to load class
> +                        if (!(className.equals(""))) {
> +                            try {
> +                                // TODO: the spec requires to return an instanse
> +                                // of the first class that might be successfully
> +                                // instantiated, RI breaks on the first
> +                                // unsuccessful attempt. We follow the spec here
> +                                return (StartTlsResponse) Class.forName(
> +                                        className, true, cl).newInstance();
> +                            } catch (Exception ignore) {
> +                                // ignore
> +                            }
> +                        }
> +                    }
> +                } catch (IOException e) {
> +                    // ignore
> +                } finally {
> +                    if (reader != null) {
> +                        reader.close();
>                      }
> -                } catch (ClassNotFoundException e) {
>                  }
>              }
> -            throw new NamingException(Messages.getString("ldap.08")+" "+ classList);
> -        } catch (ConfigFileNotFound e) {
> -            throw new NamingException(Messages.getString("ldap.09"));
> -            // return new TlsResponseImpl(); TODO This should return a provider
> -            // default implementation
> +        } catch (IOException e) {
> +            // ignore
>          }
> -    }
>
> -    /**
> -     * @ar.org.fitc.spec_ref
> -     */
> -    public String getID() {
> -        return OID;
> +        // TODO: return a provider default implementation
> +        throw new NamingException(Messages.getString("ldap.09"));
>      }
>  }
>
> Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java?view=diff&rev=512830&r1=512829&r2=512830
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java (original)
> +++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java Wed Feb 28 08:20:15 2007
> @@ -14,269 +14,82 @@
>   * See the License for the specific language governing permissions and
>   * limitations under the License.
>   */
> -
>  package org.apache.harmony.jndi.tests.javax.naming.ldap;
>
>  import java.util.Hashtable;
>
>  import javax.naming.Context;
> -import javax.naming.InitialContext;
> -import javax.naming.NamingException;
> -import javax.naming.ldap.Control;
>  import javax.naming.ldap.ControlFactory;
> +import javax.naming.ldap.InitialLdapContext;
>  import javax.naming.ldap.LdapContext;
>
>  import junit.framework.TestCase;
>
> -public class ControlFactoryTest extends TestCase {
> -       @Override
> -    protected void setUp() {
> -
> -       }
> -
> -       @Override
> -    protected void tearDown() {
> -
> -       }
> -
> -       /*
> -        * 1. No factories in Hashtable
> -        * 2. No resource files
> -        * 3. Normal input Control
> -        * 4. Normal input Context Expected: return value == input control
> -        */
> -       public void testGetControlInstance_NoFactory() throws NamingException {
> -               Control control = new MockControl("Original control", new byte[] { 1,
> -                               2, 3, 4 }, true);
> -               Hashtable<String, String> env = new Hashtable<String, String>();
> -               env.put(Context.INITIAL_CONTEXT_FACTORY,
> -                               "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
> -               Context context = new InitialContext(env);
> -
> -               Control newControl = ControlFactory.getControlInstance(control,
> -                               context, new Hashtable<Object, Object>());
> -
> -               assertEquals(control, newControl);
> -               assertSame(control, newControl);
> -       }
> -
> -       /*
> -        * 1. Hashtable == null
> -        * 2. No resource files
> -        * 3. Normal input Control
> -        * 4. Normal input Context Expected: return value == input control
> -        */
> -       public void testGetControlInstance_HashtableNull() throws NamingException {
> -               Control control = new MockControl("Original control", new byte[] { 1,
> -                               2, 3, 4 }, true);
> -               Hashtable<String, String> env = new Hashtable<String, String>();
> -               env.put(Context.INITIAL_CONTEXT_FACTORY,
> -                               "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
> -               Context context = new InitialContext(env);
> -
> -               Control newControl = ControlFactory.getControlInstance(control,
> -                               context, null);
> -               assertEquals(control, newControl);
> -               assertSame(control, newControl);
> -       }
> -
> -       /*
> -        * 1. No factories in Hashtable
> -        * 2. No resource files
> -        * 3. Normal input Control
> -        * 4. Input Context == null Expected: return value == input control
> -        */
> -       public void testGetControlInstance_ContextNull() throws NamingException {
> -               Control control = new MockControl("Original control", new byte[] { 1,
> -                               2, 3, 4 }, true);
> -               Hashtable<String, String> env = new Hashtable<String, String>();
> -               env.put(Context.INITIAL_CONTEXT_FACTORY,
> -                               "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
> -
> -               Control newControl = ControlFactory.getControlInstance(control, null,
> -                               new Hashtable<Object, Object>());
> -
> -               assertEquals(control, newControl);
> -               assertSame(control, newControl);
> -       }
> -
> -       /*
> -        * 1. No factories in Hashtable
> -        * 2. No resource files
> -        * 3. Normal input Control
> -        * 4. Input Context == null Expected: return value == input control
> -        */
> -       public void testGetControlInstance_ControlNull() throws NamingException {
> -               Hashtable<String, String> env = new Hashtable<String, String>();
> -               env.put(Context.INITIAL_CONTEXT_FACTORY,
> -                               "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
> -
> -               Context context = new InitialContext(env);
> -               Control newControl = ControlFactory.getControlInstance(null, context,
> -                               new Hashtable<Object, Object>());
> -
> -               assertNull(newControl);
> -               assertSame(null, newControl);
> -       }
> -
> -       /*
> -        * 1. Set a factory in Hashtable
> -        * 2. No resource files
> -        * 3. Normal input Control
> -        * 4. Input Context == null Expected: return value == input control
> -        */
> -       public void testGetControlInstance_Hashtable_factory()
> -                       throws NamingException {
> -               MockControl control = new MockControl("Original control", new byte[] {
> -                               1, 2, 3, 4 }, true);
> -               Hashtable<String, String> env = new Hashtable<String, String>();
> -               env.put(Context.INITIAL_CONTEXT_FACTORY,
> -                               "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
> -               Context context = new InitialContext(env);
> -
> -               Hashtable<String, String> controlEnv = new Hashtable<String, String>();
> -               controlEnv.put(LdapContext.CONTROL_FACTORIES,
> -                               "org.apache.harmony.jndi.tests.javax.naming.ldap.MockControlFactory");
> -               Control newControl = ControlFactory.getControlInstance(control,
> -                               context, controlEnv);
> -
> -               control.setID(MockControlFactory.ID_PREFIX + control.getID());
> -               assertEquals(control, newControl);
> -               assertNotSame(control, newControl);
> -       }
> -
> -       /*
> -        * 1. Set a factory which will throw exception.
> -        * 2. No resource files
> -        * 3. Normal input Control
> -        * 4. Input Context == null Expected: return value == input control
> -        */
> -       public void testGetControlInstance_factory_throwException()
> -                       throws NamingException {
> -               MockControl control = new MockControl("Original control", new byte[] {
> -                               1, 2, 3, 4 }, true);
> -               Hashtable<String, String> env = new Hashtable<String, String>();
> -               env.put(Context.INITIAL_CONTEXT_FACTORY,
> -                               "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
> -               Context context = new InitialContext(env);
> -
> -               Hashtable<String, String> controlEnv = new Hashtable<String, String>();
> -               controlEnv
> -                               .put(LdapContext.CONTROL_FACTORIES,
> -                                               "org.apache.harmony.jndi.tests.javax.naming.ldap.ControlFactoryTest$MockInvalidControlFactory");
> -               try {
> -                       ControlFactory.getControlInstance(control,
> -                                       context, controlEnv);
> -                       fail("Should throw a exception as designed.");
> -               } catch (NamingException e) {
> -               }
> -
> -       }
> -
> -       /*
> -        * 1. Set LdapContext.CONTROL_FACTORIES as a invalid value (not refer to a
> -        * ControlFactory).
> -        * 2. No resource files
> -        * 3. Normal input Control
> -        * 4. Input Context == null Expected: return value == input control
> -        */
> -       public void testGetControlInstance_InvalidFactory() throws NamingException {
> -               MockControl control = new MockControl("Original control", new byte[] {
> -                               1, 2, 3, 4 }, true);
> -               Hashtable<String, String> env = new Hashtable<String, String>();
> -               env.put(Context.INITIAL_CONTEXT_FACTORY,
> -                               "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
> -               Context context = new InitialContext(env);
> -
> -               Hashtable<String, String> controlEnv = new Hashtable<String, String>();
> -               controlEnv.put(LdapContext.CONTROL_FACTORIES, "");
> -               Control newControl = ControlFactory.getControlInstance(control,
> -                               context, controlEnv);
> -
> -               assertEquals(control, newControl);
> -               assertSame(control, newControl);
> -       }
> +import org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockControl;
>
> -       /*
> -        * 1. Set LdapContext.CONTROL_FACTORIES = multiple factories
> -        * 2. No resource files
> -        * 3. Normal input Control
> -        * 4. Input Context == null Expected: return value == input control
> -        */
> -       public void testGetControlInstance_Multiple_Factory()
> -                       throws NamingException {
> -               MockControl control = new MockControl("Original control", new byte[] {
> -                               1, 2, 3, 4 }, true);
> -               Hashtable<String, String> env = new Hashtable<String, String>();
> -               env.put(Context.INITIAL_CONTEXT_FACTORY,
> -                               "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
> -               Context context = new InitialContext(env);
> -
> -               Hashtable<Object, Object> controlEnv = new Hashtable<Object, Object>();
> -               controlEnv
> -                               .put(
> -                                               LdapContext.CONTROL_FACTORIES,
> -                                               "null;javax.naming.ldap.MockControlFactory"
> -                                                               + ";javax.naming.ldap.TestControlFactory$MockInvalidControlFactory");
> -               Control newControl = ControlFactory.getControlInstance(control,
> -                               context, controlEnv);
> -
> -               control.setID(MockControlFactory.ID_PREFIX + control.getID());
> -               assertEquals(control, newControl);
> -               assertSame(control, newControl);
> -       }
> -
> -       /*
> -        * 1. No factories in Hashtable
> -        * 2. Set factory in Service provider file
> -        * 3. Normal input Control
> -        * 4. Normal input Context Expected: return value == input control
> -        */
> -       public void testGetControlInstance_Spi1() throws NamingException {
> -               //Comment this test case out because this test case
> -               //needs complex configuration about jndi properties.
> +/**
> + * <p>This Test class is testing the class ControlFactory in the javax.naming.ldap package.</p>
> + * <p>Here in the next tables we are gonna find all methods to be tested:</p>
> + * <table>
> +       <tbody><th>Method Summary:</th>
> +       <tr><TD>Return</TD><TD>Method</TD></tr>
> +       <tr>
> +               <td class="c0" id="c00"><input class="a0" size="30" name="sas9nt11" readonly="readonly" value="static Control" id="f00"></TD>
> +               <td class="c0" id="c10"><input class="a0" size="65" name="sas9nt21" readonly="readonly" value="getControlInstance(Control ctl, Context ctx, Hashtable env)" id="f10"></td>
>
> -//             MockControl control = new MockControl("Original control", new byte[] {
> -//                             1, 2, 3, 4 }, true);
> -//             Context context = new MockContextOne();
> -//
> -//             Control newControl = ControlFactory.getControlInstance(control,
> -//                             context, new Hashtable());
> -//             control.setID(MockControlFactory.ID_PREFIX_SPI1 + control.getID());
> -//
> -//             assertEquals(control, newControl);
> -//             assertNotSame(control, newControl);
> -       }
> -
> -       /*
> -        * 1. No factories in Hashtable
> -        * 2. Set factory in Service provider file
> -        * 3. Normal input Control
> -        * 4. Normal input Context Expected: return value == input control
> -        */
> -       public void testGetControlInstance_Spi2() throws NamingException {
> -               //Comment this test case out because this test case
> -               //needs complex configuration about jndi properties.
> -
> -//             MockControl control = new MockControl("Original control", new byte[] {
> -//                             1, 2, 3, 4 }, true);
> -//             Context context = new MockContextTwo();
> -//
> -//             Control newControl = ControlFactory.getControlInstance(control,
> -//                             context, new Hashtable());
> -//             control.setID(MockControlFactory.ID_PREFIX_SPI2 + control.getID());
> -//
> -//             assertEquals(control, newControl);
> -//             assertNotSame(control, newControl);
> -       }
> -
> -       public static class MockInvalidControlFactory extends ControlFactory {
> +       </tr>
> +       </tbody>
> +       </table>
> + */
> +public class ControlFactoryTest extends TestCase {
>
> -               @Override
> -        public Control getControlInstance(Control c) throws NamingException {
> -                       throw new NamingException(
> -                                       "Throw Exception as designed for test ControlFactory.");
> -               }
> +       /**
> +        * <p>Test method for 'javax.naming.ldap.ControlFactory.getControlInstance(Control, Context, Hashtable<?, ?>)'</p>
> +        * <p>Here we are testing the static method of the class ControlFactory</p>
> +        * <p>The expected result is null.</p>
> +        */
> +       public void testGetControlInstanceControlContextHashtableOfQQ001() throws Exception {
> +               ControlFactory.getControlInstance(null,null,null);
> +       }
> +
> +    /**
> +        * <p>Test method for 'javax.naming.ldap.ControlFactory.getControlInstance(Control, Context, Hashtable<?, ?>)'</p>
> +        * <p>Here we are testing the static method of the class ControlFactory</p>
> +        * <p>The expected result is the control sended.</p>
> +        */
> +       public void testGetControlInstanceControlContextHashtableOfQQ002() throws Exception {
> +               MockControl cs =  new MockControl("c1", false, new byte[] { 1, 2, 3, 4 });
> +               assertEquals(cs,ControlFactory.getControlInstance(cs,null,null));
> +       }
> +
> +       /**
> +        * <p>Test method for 'javax.naming.ldap.ControlFactory.getControlInstance(Control, Context, Hashtable<?, ?>)'</p>
> +        * <p>Here we are testing the static method of the class ControlFactory</p>
> +        * <p>The expected result is the control sended.</p>
> +        */
> +       public void testGetControlInstanceControlContextHashtableOfQQ003() throws Exception {
> +               Hashtable env = new Hashtable();
> +               env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
> +               MockControl[] cs = { new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),
> +                               new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
> +               MockControl cs2 =  new MockControl("c1", false, new byte[] { 1, 2, 3, 4 });
> +               InitialLdapContext ilc=new InitialLdapContext(env, cs);
> +               assertEquals(cs2,ControlFactory.getControlInstance(cs2,ilc,env));
> +       }
> +
> +       /**
> +        * <p>Test method for 'javax.naming.ldap.ControlFactory.getControlInstance(Control, Context, Hashtable<?, ?>)'</p>
> +        * <p>Here we are testing the static method of the class ControlFactory</p>
> +        * <p>The expected result is the control sended.</p>
> +        */
> +       public void testGetControlInstanceControlContextHashtableOfQQ004() throws Exception {
> +               Hashtable env = new Hashtable();
> +               env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
> +               env.put(LdapContext.CONTROL_FACTORIES,"org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockControlFactory");
> +               MockControl[] cs = { new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
> +               MockControl cs2 =  new MockControl("c1", false, new byte[] { 1, 2, 3, 4 });
> +               InitialLdapContext ilc=new InitialLdapContext(env, cs);
>
> +               assertEquals(cs2,ControlFactory.getControlInstance(cs2,ilc,env));
>         }
>  }
>
> Copied: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java (from r512603, harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestSortControl.java)
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java?view=diff&rev=512830&p1=harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestSortControl.java&r1=512603&p2=harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java&r2=512830
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestSortControl.java (original)
> +++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java Wed Feb 28 08:20:15 2007
> @@ -22,510 +22,164 @@
>   */
>  package org.apache.harmony.jndi.tests.javax.naming.ldap;
>
> -import java.io.IOException;
>  import java.math.BigInteger;
> +
>  import javax.naming.ldap.SortControl;
>  import javax.naming.ldap.SortKey;
> +
>  import junit.framework.TestCase;
>
> -/**
> - * <p>This Test class is testing the SortControl class.</p>
> - * <p>In the next tables we are gonna see the methods that we test in this class:</p>
> - * <table class="t" cellspacing="0">
> -       <tbody><th>Constructors:</th>
> -               <tr>
> -                       <td class="c0" id="c00"><input class="a0" size="30" name="sas9nt11" readonly="readonly" value="" id="f00"></td>
> -                       <td class="c0" id="c10"><input class="a0" size="60" name="sas9nt21" readonly="readonly" value="SortControl(SortKey[] sortBy, boolean criticality)" id="f10"></td>
> -
> -               </tr>
> -               <tr>
> -                       <td class="c0" id="c00"><input class="a0" size="30" name="sas9nt11" readonly="readonly" value="" id="f00"></td>
> -                       <td class="c0" id="c10"><input class="a0" size="60" name="sas9nt21" readonly="readonly" value="SortControl(String[] sortBy, boolean criticality)" id="f10"></td>
> -
> -               </tr>
> -               <tr>
> -                       <td class="c0" id="c00"><input class="a0" size="30" name="sas9nt11" readonly="readonly" value="" id="f00"></td>
> -                       <td class="c0" id="c10"><input class="a0" size="60" name="sas9nt21" readonly="readonly" value="SortControl(String sortBy, boolean criticality)" id="f10"></td>
> -
> -               </tr>
> -
> -       </tbody></table>
> - *
> +/**
> + * This Test class is testing the SortControl class
>   */
> -public class TestSortControl extends TestCase {
> +public class SortControlTest extends TestCase {
>
> -       /**
> -        * <p>This method is not implemted.</p>
> -        * @param args Possible parameter to help us initiate all tests.
> -        */
> -       public static void main(String[] args) {
> -       }
> -
> -       protected void setUp() throws Exception {
> -               super.setUp();
> -       }
> -
> -       protected void tearDown() throws Exception {
> -               super.tearDown();
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.SortControl(String, boolean)'</p>
> -        * <p>Here we are testing if this method constructs a control to sort on a list of sort keys.</p>
> -        * <p>The expected result is a null pointer exception.</p>
> -        */
> -       public void testSortControlSortKeyArrayBoolean001() {
> -
> -               SortKey[] t=null;
> -               try {
> -                       SortControl x=new SortControl(t,false);
> -                       fail("The sort keys should not be null.");
> -               } catch (NullPointerException e) {
> -
> -               } catch (Throwable e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.SortControl(String, boolean)'</p>
> -        * <p>Here we are testing if this method constructs a control to sort on a list of sort keys.</p>
> -        * <p>The expected result is a not null Sort Control.</p>
> -        */
> -       public void testSortControlSortKeyArrayBoolean002() {
> -
> -               SortKey[] t={(SortKey)new SortKey("1"),(SortKey)new SortKey("2")};
> -               try {
> -                       SortControl x=new SortControl(t,false);
> -                       assertNotNull(x);
> -                       assertFalse(x.isCritical());
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.SortControl(String[], boolean)'</p>
> -        * <p>Here we are testing if this method constructs a control to sort on a list of attributes in ascending order.</p>
> -        * <p>The expected result is a null pointer exception.</p>
> -        */
> -       public void testSortControlStringArrayBoolean001() {
> -
> -               try {
> -                       String[] x=null;
> -                       SortControl sc=new SortControl(x,false);
> -                       fail("The list of attributes should not be null.");
> -               } catch (NullPointerException e) {
> -
> -               } catch (Throwable e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.SortControl(String[], boolean)'</p>
> -        * <p>Here we are testing if this method constructs a control to sort on a list of attributes in ascending order.</p>
> -        * <p>The expected result is a not null sort control.</p>
> -        */
> -       public void testSortControlStringArrayBoolean002() {
> -
> -               try {
> -                       String[] x={"1","2"};
> -                       SortControl sc=new SortControl(x,false);
> -                       assertNotNull(sc);
> -                       assertFalse(sc.isCritical());
> -               }   catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.SortControl(String[], boolean)'</p>
> -        * <p>Here we are testing if this method constructs a control to sort on a list of attributes in ascending order.</p>
> -        * <p>The expected result is a not null sort control.</p>
> -        */
> -       public void testSortControlStringArrayBoolean003() {
> -
> -               try {
> -                       String[] x={"1","2"};
> -                       SortControl sc=new SortControl(x,true);
> -                       assertNotNull(sc);
> -                       assertTrue(sc.isCritical());
> -               }   catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.SortControl(String[], boolean)'</p>
> -        * <p>Here we are testing if this method constructs a control to sort on a list of attributes in ascending order.</p>
> -        * <p>The expected result is a not null sort control.</p>
> -        */
> -       public void testSortControlStringArrayBoolean004() {
> -
> -               try {
> -                       String[] x={"",""};
> -                       SortControl sc=new SortControl(x,true);
> -                       assertNotNull(sc);
> -                       assertTrue(sc.isCritical());
> -               }   catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.SortControl(SortKey[], boolean)'</p>
> -        * <p>Here we are testing if this metho constructs a control to sort on a single attrib.</p>
> -        * <p>The expected result is a null pointer exception.</p>
> -        */
> -       public void testSortControlStringBoolean001() {
> -
> -               try{
> -                       String t=null;
> -                       SortControl sc=new SortControl(t,false);
> -                       assertNotNull(sc);
> -                       assertFalse(sc.isCritical());
> -               } catch (NullPointerException e) {
> -                       fail("The attrib can be null."+e);
> -               } catch (Throwable e) {
> -                       fail("Failed with:"+e);
> -               }
> -
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.SortControl(SortKey[], boolean)'</p>
> -        * <p>Here we are testing if this metho constructs a control to sort on a single attrib.</p>
> -        * <p>The expected result is a not null sort control.</p>
> -        */
> -       public void testSortControlStringBoolean002() {
> -
> -               try{
> -                       String t="anything";
> -                       SortControl sc=new SortControl(t,false);
> -                       assertNotNull(sc);
> -                       assertFalse(sc.isCritical());
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.SortControl(SortKey[], boolean)'</p>
> -        * <p>Here we are testing if this metho constructs a control to sort on a single attrib.</p>
> -        * <p>The expected result is a not null sort control.</p>
> -        */
> -       public void testSortControlStringBoolean003() {
> -
> -               try{
> -                       String t="anything";
> -                       SortControl sc=new SortControl(t,true);
> -                       assertNotNull(sc);
> -                       assertTrue(sc.isCritical());
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of sortkey.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl001(){
> -               SortKey[] sk=null;
> -               sk=new SortKey[1];
> -               sk[0]=new SortKey("pepe",false,"leo");
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 10 30 0e 04 04 70 65 70 65 80 03 6c 65 6f 81 01 ff",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of sortkey.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl002(){
> -               SortKey[] sk=null;
> -               sk=new SortKey[1];
> -               sk[0]=new SortKey("",false,"");
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 09 30 07 04 00 80 00 81 01 ff",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of sortkey.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl003(){
> -               SortKey[] sk=null;
> -               sk=new SortKey[1];
> -               sk[0]=new SortKey("",true,"");
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 06 30 04 04 00 80 00",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of sortkey.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl004(){
> -               SortKey[] sk=null;
> -               sk=new SortKey[1];
> -               sk[0]=new SortKey("pepe",true,"laura");
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 0f 30 0d 04 04 70 65 70 65 80 05 6c 61 75 72 61",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of sortkey.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl005(){
> -               SortKey[] sk=null;
> -               sk=new SortKey[1];
> -               sk[0]=new SortKey("pepe",true,null);
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 08 30 06 04 04 70 65 70 65",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of strings.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl006(){
> -               String[] sk={""};
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 04 30 02 04 00",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of strings.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl007(){
> -               String[] sk={""};
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,false);
> -                       assertEquals("30 04 30 02 04 00",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of strings.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl008(){
> -               String[] sk={"pepe"};
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,false);
> -                       assertEquals("30 08 30 06 04 04 70 65 70 65",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of strings.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl009(){
> -               String[] sk={"pepe"};
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 08 30 06 04 04 70 65 70 65",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of strings.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl010(){
> -               String[] sk={"pepe","","toto"};
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 14 30 06 04 04 70 65 70 65 30 02 04 00 30 06 04 04 74 6f 74 6f",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using an array of strings.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl011(){
> -               String[] sk={"pepe","","toto"};
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,false);
> -                       assertEquals("30 14 30 06 04 04 70 65 70 65 30 02 04 00 30 06 04 04 74 6f 74 6f",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using a string.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl012(){
> -               String sk=null;
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,false);
> -                       assertEquals("30 04 30 02 04 00",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using a string.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl013(){
> -               String sk=null;
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 04 30 02 04 00",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using a string.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl014(){
> -               String sk="";
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,true);
> -                       assertEquals("30 04 30 02 04 00",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using a string.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl015(){
> -               String sk="";
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,false);
> -                       assertEquals("30 04 30 02 04 00",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the control's ASN.1 BER encoded value. In this case we create a sort
> -        * control using a string.</p>
> -        * <p>The expecting result is the control's ASN.1 BER encoded value.</p>
> -        */
> -       public void testEncodedValueOfSortControl016(){
> -               String sk="pepe";
> -
> -               try {
> -                       SortControl sc=new SortControl(sk,false);
> -                       assertEquals("30 08 30 06 04 04 70 65 70 65",toHexString(sc.getEncodedValue()));
> -                       sc=new SortControl(sk,true);
> -                       assertEquals("30 08 30 06 04 04 70 65 70 65",toHexString(sc.getEncodedValue()));
> -               } catch (IOException e) {
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /*
> -        * Method to get the string of a byte array.
> -        */
> -       private static String toHexString(byte[] data) {
> -               BigInteger bi = new BigInteger(data);
> -               String s = bi.toString(16);
> -               StringBuffer hex = new StringBuffer();
> -               if (s.length() % 2 != 0) {
> -                       s = "0" + s;
> -               }
> -               for (int i = 0; i < s.length(); i++) {
> -                       hex.append(s.charAt(i));
> -                       if (i % 2 != 0 && i < s.length() - 1) {
> -                               hex.append(" ");
> -                       }
> -               }
> -               return hex.toString();
> -       }
> +    /**
> +     * tests how constructors with arrayas process null
> +     */
> +    public void testSortControl() throws Exception {
> +        try {
> +            new SortControl((String[]) null, false);
> +            fail("NullPointerException expected");
> +        } catch (NullPointerException e) {}
> +
> +        try {
> +            new SortControl((SortKey[]) null, false);
> +            fail("NullPointerException expected");
> +        } catch (NullPointerException e) {}
> +    }
> +
> +    /**
> +     * @tests isCritical()
> +     */
> +    public void testSortControlStringArrayBoolean002() throws Exception {
> +        assertTrue(new SortControl("", true).isCritical());
> +        assertFalse(new SortControl("", false).isCritical());
> +
> +        assertTrue(new SortControl(new String[0], true).isCritical());
> +        assertFalse(new SortControl(new String[0], false).isCritical());
> +
> +        assertTrue(new SortControl(new SortKey[0], true).isCritical());
> +        assertFalse(new SortControl(new SortKey[0], false).isCritical());
> +
> +    }
> +
> +    /**
> +     * <p>
> +     * Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'
> +     * </p>
> +     * <p>
> +     * Here we are testing if this method retrieves the control's ASN.1 BER
> +     * encoded value. In this case we create a sort control using an array of
> +     * sortkey.
> +     * </p>
> +     * <p>
> +     * The expecting result is the control's ASN.1 BER encoded value.
> +     * </p>
> +     */
> +    public void testEncodedValueOfSortControl001() throws Exception {
> +        SortKey[] sk = { new SortKey("pepe", false, "leo") };
> +
> +        SortControl sc = new SortControl(sk, true);
> +        assertEquals("30 10 30 0e 04 04 70 65 70 65 80 03 6c 65 6f 81 01 ff",
> +                toHexString(sc.getEncodedValue()));
> +    }
> +
> +    /**
> +     * <p>
> +     * Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'
> +     * </p>
> +     * <p>
> +     * Here we are testing if this method retrieves the control's ASN.1 BER
> +     * encoded value. In this case we create a sort control using an array of
> +     * sortkey.
> +     * </p>
> +     * <p>
> +     * The expecting result is the control's ASN.1 BER encoded value.
> +     * </p>
> +     */
> +    public void testEncodedValueOfSortControl003() throws Exception {
> +        SortKey[] sk = { new SortKey("", true, "") };
> +
> +        SortControl sc = new SortControl(sk, true);
> +        assertEquals("30 06 30 04 04 00 80 00", toHexString(sc
> +                .getEncodedValue()));
> +
> +        SortKey[] sk1 = { new SortKey("pepe", true, "laura") };
> +
> +        sc = new SortControl(sk1, true);
> +        assertEquals("30 0f 30 0d 04 04 70 65 70 65 80 05 6c 61 75 72 61",
> +                toHexString(sc.getEncodedValue()));
> +    }
> +
> +    /**
> +     * <p>
> +     * Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'
> +     * </p>
> +     * <p>
> +     * Here we are testing if this method retrieves the control's ASN.1 BER
> +     * encoded value. In this case we create a sort control using an array of
> +     * strings.
> +     * </p>
> +     * <p>
> +     * The expecting result is the control's ASN.1 BER encoded value.
> +     * </p>
> +     */
> +    public void testEncodedValueOfSortControl006() throws Exception {
> +        String[] sk = { "" };
> +        SortControl sc = new SortControl(sk, true);
> +        assertEquals("30 04 30 02 04 00", toHexString(sc.getEncodedValue()));
> +
> +        String[] sk1 = { "pepe", "", "toto" };
> +        sc = new SortControl(sk1, true);
> +        assertEquals(
> +                "30 14 30 06 04 04 70 65 70 65 30 02 04 00 30 06 04 04 74 6f 74 6f",
> +                toHexString(sc.getEncodedValue()));
> +    }
> +
> +    /**
> +     * <p>
> +     * Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'
> +     * </p>
> +     * <p>
> +     * Here we are testing if this method retrieves the control's ASN.1 BER
> +     * encoded value. In this case we create a sort control using a string.
> +     * </p>
> +     * <p>
> +     * The expecting result is the control's ASN.1 BER encoded value.
> +     * </p>
> +     */
> +    public void testEncodedValueOfSortControl014() throws Exception {
> +        SortControl sc;
> +
> +        sc = new SortControl((String) null, false);
> +        assertEquals("30 04 30 02 04 00", toHexString(sc.getEncodedValue()));
> +
> +        sc = new SortControl("", true);
> +        assertEquals("30 04 30 02 04 00", toHexString(sc.getEncodedValue()));
> +
> +        sc = new SortControl("pepe", false);
> +        assertEquals("30 08 30 06 04 04 70 65 70 65", toHexString(sc
> +                .getEncodedValue()));
> +    }
> +
> +    /*
> +     * Method to get the string of a byte array.
> +     */
> +    private static String toHexString(byte[] data) {
> +        BigInteger bi = new BigInteger(data);
> +        String s = bi.toString(16);
> +        StringBuffer hex = new StringBuffer();
> +        if (s.length() % 2 != 0) {
> +            s = "0" + s;
> +        }
> +        for (int i = 0; i < s.length(); i++) {
> +            hex.append(s.charAt(i));
> +            if (i % 2 != 0 && i < s.length() - 1) {
> +                hex.append(" ");
> +            }
> +        }
> +        return hex.toString();
> +    }
>
>  }
>
> Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortKeyTest.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortKeyTest.java?view=diff&rev=512830&r1=512829&r2=512830
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortKeyTest.java (original)
> +++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortKeyTest.java Wed Feb 28 08:20:15 2007
> @@ -29,7 +29,7 @@
>          assertNull(sk.getMatchingRuleID());
>
>          try {
> -            sk = new SortKey(null);
> +            new SortKey(null);
>              fail("Should throw NullPointerException.");
>          } catch (NullPointerException e) {
>              //expected
> @@ -43,7 +43,7 @@
>          assertEquals("matchingRuleId", sk.getMatchingRuleID());
>
>          try {
> -            sk = new SortKey(null, true, null);
> +            new SortKey(null, true, null);
>              fail("Should throw NullPointerException.");
>          } catch (NullPointerException e) {
>              //expected
>
> Copied: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsRequestTest.java (from r512603, harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsRequest.java)
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsRequestTest.java?view=diff&rev=512830&p1=harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsRequest.java&r1=512603&p2=harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsRequestTest.java&r2=512830
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsRequest.java (original)
> +++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsRequestTest.java Wed Feb 28 08:20:15 2007
> @@ -26,7 +26,7 @@
>  import javax.naming.ldap.StartTlsRequest;
>  import javax.naming.ldap.StartTlsResponse;
>  import junit.framework.TestCase;
> -
> +import org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockStartTlsResponse;
>  /**
>   * <p>This Test class is testing the class StartTlsRequest in the javax.naming.ldap package.</p>
>   * <p>Here in the next tables we are gonna find all methods to be tested:</p>
> @@ -64,37 +64,7 @@
>   * <hr>
>   *
>   */
> -public class TestStartTlsRequest extends TestCase {
> -
> -       /**
> -        * <p>This method is not implemted.</p>
> -        * @param args Possible parameter to help us initiate all tests.
> -        */
> -       public static void main(String[] args) {
> -       }
> -
> -       /**
> -        * <p>Constructor method of the test class.</p>
> -        * <p>Here in this case we do not do anything else of initiate the inherited constructor.</p>
> -        */
> -       protected void setUp() throws Exception {
> -               super.setUp();
> -       }
> -
> -       protected void tearDown() throws Exception {
> -               super.tearDown();
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.StartTlsRequest.StartTlsRequest()'</p>
> -        * <p>Here we are testing if this method constructs a StartTLS extended request.</p>
> -        * <p>The expected return is an object Tls.</p>
> -        */
> -       public void testStartTlsRequest() {
> -
> -               assertNotNull(new StartTlsRequest());
> -
> -       }
> +public class StartTlsRequestTest extends TestCase {
>
>         /**
>          * <p>Test method for 'javax.naming.ldap.StartTlsRequest.getID()'</p>
> @@ -102,9 +72,9 @@
>          * <p>The expected result is a string : "1.3.6.1.4.1.1466.20037".</p>
>          */
>         public void testGetID() {
> -               StartTlsRequest str = new StartTlsRequest();
> -               assertEquals("1.3.6.1.4.1.1466.20037",str.getID());
> -       }
> +        assertEquals("1.3.6.1.4.1.1466.20037", StartTlsRequest.OID);
> +        assertSame(StartTlsRequest.OID, new StartTlsRequest().getID());
> +    }
>
>         /**
>          * <p>Test method for 'javax.naming.ldap.StartTlsRequest.getEncodedValue()'</p>
> @@ -112,129 +82,53 @@
>          * <p>The expected result is a null value.</p>
>          */
>         public void testGetEncodedValue() {
> -
> -               StartTlsRequest str = new StartTlsRequest();
> -               assertNull(str.getEncodedValue());
> -
> -       }
> +        assertNull(new StartTlsRequest().getEncodedValue());
> +    }
>
>         /**
>          * <p>Test method for 'javax.naming.ldap.StartTlsRequest.createExtendedResponse(String, byte[], int, int)'</p>
> -        * <p>Here we are testing if this method creates an extended response object that corresponds to the LDAP StartTLS extended request.</p>
> -        * <p>The expected result is NamingException.</p>
> -        */
> -       public void testCreateExtendedResponse001() {
> -               StartTlsRequest str = new StartTlsRequest();
> -               String ID="";
> -               int t1=0,t2=0;
> -               byte[] t0=new byte[] {0,0,0};
> -               try {
> -                       str.createExtendedResponse(ID,t0,t1,t2);
> -               } catch (NamingException e) {
> -               } catch (Throwable e){
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.StartTlsRequest.createExtendedResponse(String, byte[], int, int)'</p>
> -        * <p>Here we are testing if this method creates an extended response object that corresponds to the LDAP StartTLS extended request.
> -        * In this case we are testing the extended response with the argument ID="1.3.6.1.4.1.1466.20037". In this particular case does
> -     * not exist an implentation.</p>
> -     * <p>Notice here that this package does not have a provider so an implementation does not exist, so this test must fail with a provider
> -     * and not fail with no provider.</p>
> -        * <p>The expected result is an exception because here does not exist an implemntation.</p>
> -        */
> -       public void testCreateExtendedResponse002() {
> -               StartTlsRequest str = new StartTlsRequest();
> -               String ID="1.3.6.1.4.1.1466.20037";
> -               int t1=0,t2=0;
> -               byte[] t0=null;
> -               try {
> -                       str.createExtendedResponse(ID,t0,t1,t2);
> -            fail("Here does not exist an implementation.");
> -               } catch (NamingException e) {
> -
> -               } catch (Throwable e){
> -            e.printStackTrace();
> -                       fail("Failed with:"+e);
> -               }
> -
> -
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.StartTlsRequest.createExtendedResponse(String, byte[], int, int)'</p>
> -        * <p>Here we are testing if this method creates an extended response object that corresponds to the LDAP StartTLS extended request.
> -        * In this case we are testing the extended response with the argument ID="", and the byte array.</p>
> -        * <p>Notice here this test is ok because first the class must check the arguments and then search for the implementation.</p>
> -        * <p>The expected result is a Naming exception.</p>
> -        */
> -       public void testCreateExtendedResponse003() {
> -
> -               StartTlsRequest str = new StartTlsRequest();
> -               String ID="";
> -               int t1=0,t2=0;
> -               byte[] t0=null;
> -               try {
> -                       StartTlsResponse x=(StartTlsResponse) str.createExtendedResponse(ID,t0,t1,t2);
> -                       fail("Should not be posible use an id distinct of \"1.3.6.1.4.1.1466.20037\"");
> -               } catch (NamingException e) {
> -
> -               } catch (Throwable e){
> -            e.printStackTrace();
> -                       fail("Failed with:"+e);
> -               }
> -
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.StartTlsRequest.createExtendedResponse(String, byte[], int, int)'</p>
> -        * <p>Here we are testing if this method creates an extended response object that corresponds to the LDAP StartTLS extended request.
> -        * In this case we are testing the extended response with the argument ID="1.3.6.1.4.1.1466.20037" and the others arguments should be ignored.</p>
> -        * <p>Notice here that this package does not have a provider so an implementation does not exist, so this test must not fail with a provider
> -     * and fail with no provider.</p>
> -        * <p>The expected result is a Tls response.</p>
> -        */
> -       public void testCreateExtendedResponse004() {
> -
> -               StartTlsRequest str = new StartTlsRequest();
> -               String ID="1.3.6.1.4.1.1466.20037";
> -               int t1=210,t2=650;
> -               byte[] t0=ID.getBytes();
> -               try {
> -                       StartTlsResponse x=(StartTlsResponse) str.createExtendedResponse(ID,t0,t1,t2);
> -                       assertNotNull(x);
> -                       assertEquals("1.3.6.1.4.1.1466.20037",x.getID());
> -                       assertEquals(null,x.getEncodedValue());
> -               } catch (NamingException e) {
> -                       fail("Failed with:"+e);
> -               } catch (Throwable e){
> -            e.printStackTrace();
> -                       fail("Failed with:"+e);
> -               }
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.StartTlsRequest.createExtendedResponse(String, byte[], int, int)'</p>
>          * <p>Here we are testing if this method creates an extended response object that corresponds to the LDAP StartTLS extended request.
>          * In this case we are testing the extended response with the argument ID=""</p>
>          * <p>The expected result is an exception.</p>
>          */
>         public void testCreateExtendedResponse005() {
> -
> -               StartTlsRequest str = new StartTlsRequest();
> -               String ID="1.a.2.b.3.d.4";
> -               int t1=0,t2=0;
> -               byte[] t0=null;
> -               try {
> -                       StartTlsResponse tls = (StartTlsResponse) str.createExtendedResponse(ID,t0,t1,t2);
> -                       fail("Should not be posible use an id distinc of \"1.3.6.1.4.1.1466.20037\"");
> -               } catch (NamingException e) {
> -               } catch (Throwable e){
> -                       fail("Failed with:"+e);
> -               }
> +        StartTlsRequest str = new StartTlsRequest();
> +        try {
> +            str.createExtendedResponse("", null, 1, 2);
> +            fail("NamingException expected");
> +        } catch (NamingException e) {}
> +    }
> +
> +    /**
> +     * <p>Test method for 'javax.naming.ldap.StartTlsRequest.createExtendedResponse(String, byte[], int, int)'</p>
> +     * <p>Here we are testing if this method creates an extended response object that corresponds to the LDAP StartTLS extended request.
> +     * In this case we are testing the extended response with the argument ID="1.3.6.1.4.1.1466.20037" and the others arguments should be ignored.</p>
> +     * <p>Notice here that this package does not have a provider so an implementation does not exist, so this test must not fail with a provider
> +     * and fail with no provider.</p>
> +     * <p>The expected result is a Tls response.</p>
> +     */
> +    public void testCreateExtendedResponse004() throws Exception {
> +        StartTlsRequest str = new StartTlsRequest();
> +        String ID = "1.3.6.1.4.1.1466.20037";
> +        int t1 = 210, t2 = 650;
> +        byte[] t0 = ID.getBytes();
> +
> +        StartTlsResponse x = (StartTlsResponse) str.createExtendedResponse(ID,
> +                t0, t1, t2);
> +        assertEquals(MockStartTlsResponse.class, x.getClass());
> +    }
> +
> +    public static class MockStartTlsResponse1 extends MockStartTlsResponse {
> +
> +        public MockStartTlsResponse1() throws Exception {
> +            throw new Exception();
> +        }
> +    }
> +
> +    public static class MockStartTlsResponse2 extends MockStartTlsResponse {
> +
> +        protected MockStartTlsResponse2() {}
> +    }
>
> -       }
> -
> +    static class MockStartTlsResponse3 extends MockStartTlsResponse {}
>  }
>
> Copied: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsResponseTest.java (from r512603, harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsResponse.java)
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsResponseTest.java?view=diff&rev=512830&p1=harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsResponse.java&r1=512603&p2=harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsResponseTest.java&r2=512830
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestStartTlsResponse.java (original)
> +++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/StartTlsResponseTest.java Wed Feb 28 08:20:15 2007
> @@ -22,73 +22,20 @@
>   */
>  package org.apache.harmony.jndi.tests.javax.naming.ldap;
>
> -import org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockStartTlsResponse;
> +import javax.naming.ldap.StartTlsResponse;
> +
>  import junit.framework.TestCase;
>
> -/**
> - * <p>This class has all test for the class TestStartTlsResponse.</p>
> - * <p>Here we are gonna test all its methods as we see in the next table:</p>
> - * <table>
> -       <tbody><th>Method Summary:</th>
> -               <tr><TD>Return</TD><TD>Method</TD></tr>
> -               <tr>
> -                       <td class="c0" id="c00"><input class="a0" size="30" name="sas9nt11" readonly="readonly" value="byte[]" id="f00"></TD>
> -                       <td class="c0" id="c10"><input class="a0" size="80" name="sas9nt21" readonly="readonly" value="getEncodedValue()" id="f10"></td>
> -
> -               </tr>
> -               <tr>
> -                       <td class="c0" id="c00"><input class="a0" size="30" name="sas9nt11" readonly="readonly" value=" String" id="f00"></td>
> -                       <td class="c0" id="c10"><input class="a0" size="80" name="sas9nt21" readonly="readonly" value="getID()" id="f10"></td>
> -
> -               </tr>
> -
> -       </tbody>
> -       </table>
> - *
> - */
> -public class TestStartTlsResponse extends TestCase {
> -
> -
> -       /**
> -        * <p>This method is not implemted.</p>
> -        * @param args Possible parameter to help us initiate all tests.
> -        */
> -       public static void main(String[] args) {
> -       }
> -
> -       /**
> -        * <p>Constructor method of the test class.</p>
> -        * <p>Here in this case we do not do anything else of initiate the inherited constructor.</p>
> -        */
> -       protected void setUp() throws Exception {
> -               super.setUp();
> -       }
> -
> -       protected void tearDown() throws Exception {
> -               super.tearDown();
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.StartTlsResponse.getID()'</p>
> -        * <p>Here we are testing if this method retrieves the StartTLS response's object identifier string.</p>
> -        * <p>The expected result is "1.3.6.1.4.1.1466.20037".</p>
> -        */
> -       public void testGetID() {
> -
> -               MockStartTlsResponse x=new MockStartTlsResponse();
> -               assertEquals("1.3.6.1.4.1.1466.20037",x.getID());
> -       }
> -
> -       /**
> -        * <p>Test method for 'javax.naming.ldap.StartTlsResponse.getEncodedValue()'</p>
> -        * <p>Here we are testing if this method retrieves the StartTLS response's ASN.1 BER encoded value.</p>
> -        * <p>The expected result is a null value.</p>
> -        */
> -       public void testGetEncodedValue() {
> -
> -               MockStartTlsResponse x=new MockStartTlsResponse();
> -               assertNull(x.getEncodedValue());
> -       }
> -
> -
> +import org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockStartTlsResponse;
> +
> +public class StartTlsResponseTest extends TestCase {
> +
> +    public void testAll() {
> +        assertEquals("1.3.6.1.4.1.1466.20037", StartTlsResponse.OID);
> +
> +        StartTlsResponse str = new MockStartTlsResponse();
> +
> +        assertEquals(StartTlsResponse.OID, str.getID());
> +        assertNull(str.getEncodedValue());
> +    }
>  }
>
>
>


-- 
Tony Wu
China Software Development Lab, IBM

Mime
View raw message