directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r592023 [11/25] - in /directory/sandbox/felixk/studio-dsml-parser: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ src/ma...
Date Mon, 05 Nov 2007 14:53:11 GMT
Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNRequest/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNRequest/ModifyDNRequestTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNRequest/ModifyDNRequestTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNRequest/ModifyDNRequestTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,414 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.modDNRequest;
+
+
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
+
+
+/**
+ * Tests for the Modify DN Request parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ModifyDNRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 456, modifyDNRequest.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute equals to 0
+     */
+    public void testRequestWithRequestIdEquals0()
+    {
+        testParsingFail( ModifyDNRequestTest.class, "request_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element
+     */
+    public void testRequestWith1Control()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyDNRequest.getCurrentControl();
+
+        assertEquals( 1, modifyDNRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with Base64 Value
+     */
+    public void testRequestWith1ControlBase64Value()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyDNRequest.getCurrentControl();
+
+        assertEquals( 1, modifyDNRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( "DSMLv2.0 rocks!!", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with empty value
+     */
+    public void testRequestWith1ControlEmptyValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyDNRequest.getCurrentControl();
+
+        assertEquals( 1, modifyDNRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 (optional) Control elements
+     */
+    public void testRequestWith2Controls()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyDNRequest.getCurrentControl();
+
+        assertEquals( 2, modifyDNRequest.getControls().size() );
+        assertFalse( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
+        assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with 3 (optional) Control elements without value
+     */
+    public void testRequestWith3ControlsWithoutValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyDNRequest.getCurrentControl();
+
+        assertEquals( 3, modifyDNRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request without dn attribute
+     */
+    public void testRequestWithoutDnAttribute()
+    {
+        testParsingFail( ModifyDNRequestTest.class, "request_without_dn_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request without newrdn attribute
+     */
+    public void testRequestWithoutNewRdnAttribute()
+    {
+        testParsingFail( ModifyDNRequestTest.class, "request_without_newrdn_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request without dn and newrdn attributes
+     */
+    public void testRequestWithDnAndNewRdnAttributes()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_dn_and_newrdn_attributes.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", modifyDNRequest.getEntry().toString() );
+
+        assertEquals( "cn=Steve Jobs", modifyDNRequest.getNewRDN().toString() );
+    }
+
+
+    /**
+     * Test parsing of a request with deleteoldrdn to true
+     */
+    public void testRequestWithDeleteOldRdnTrue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_true.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertTrue( modifyDNRequest.isDeleteOldRDN() );
+    }
+
+
+    /**
+     * Test parsing of a request with deleteoldrdn to 1
+     */
+    public void testRequestWithDeleteOldRdn1()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_1.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertTrue( modifyDNRequest.isDeleteOldRDN() );
+    }
+
+
+    /**
+     * Test parsing of a request with deleteoldrdn to false
+     */
+    public void testRequestWithDeleteOldRdnFalse()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_false.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertFalse( modifyDNRequest.isDeleteOldRDN() );
+    }
+
+
+    /**
+     * Test parsing of a request with deleteoldrdn to 0
+     */
+    public void testRequestWithDeleteOldRdn0()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_0.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertFalse( modifyDNRequest.isDeleteOldRDN() );
+    }
+
+
+    /**
+     * Test parsing of a request with deleteoldrdn to an error value
+     */
+    public void testRequestWithDeleteOldRdnError()
+    {
+        testParsingFail( ModifyDNRequestTest.class, "request_with_deleteoldrdn_error.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with newSuperior attribute
+     */
+    public void testRequestWithNewSuperior()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_newSuperior_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "cn=Steve Jobs,ou=Dev,dc=apple,dc=com", modifyDNRequest.getNewSuperior().toString() );
+    }
+
+
+    /**
+     * Test parsing of a request with a needed requestID attribute
+     * 
+     * DIRSTUDIO-1
+     */
+    public void testRequestWithNeededRequestId()
+    {
+        testParsingFail( ModifyDNRequestTest.class, "request_with_needed_requestID.xml" );
+    }
+}

Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNRequest/ModifyDNRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNResponse/ModifyDNResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNResponse/ModifyDNResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNResponse/ModifyDNResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNResponse/ModifyDNResponseTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,514 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.modDNResponse;
+
+
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.LdapResult;
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNResponse;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2ResponseParser;
+
+import com.sun.jndi.ldap.LdapURL;
+
+
+/**
+ * Tests for the Modify DN Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ModifyDNResponseTest extends AbstractResponseTest
+{
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 456, modifyDNResponse.getMessageId() );
+    }
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute equals 0
+     */
+    public void testResponseWithRequestIdEquals0()
+    {
+        testParsingFail( ModifyDNResponseTest.class, "response_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with a (optional) Control element
+     */
+    public void testResponseWith1Control()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 1, modifyDNResponse.getControls().size() );
+
+        Control control = modifyDNResponse.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+    
+    /**
+     * Test parsing of a response with a (optional) Control element with empty value
+     */
+    public void testResponseWith1ControlEmptyValue()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_1_control_empty_value.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+        Control control = modifyDNResponse.getCurrentControl();
+        
+        assertEquals( 1, modifyDNResponse.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, ( byte[] ) control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a response with 2 (optional) Control elements
+     */
+    public void testResponseWith2Controls()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 2, modifyDNResponse.getControls().size() );
+
+        Control control = modifyDNResponse.getCurrentControl();
+
+        assertFalse( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
+
+        assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a response with 3 (optional) Control elements without value
+     */
+    public void testResponseWith3ControlsWithoutValue()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 3, modifyDNResponse.getControls().size() );
+
+        Control control = modifyDNResponse.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a response without Result Code element
+     */
+    public void testResponseWithoutResultCode()
+    {
+        testParsingFail( ModifyDNResponseTest.class, "response_without_result_code.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( ModifyDNResponseTest.class, "response_with_result_code_not_integer.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code 
+     */
+    public void testResponseWithResultCode()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyDNResponse.getLdapResult();
+
+        assertEquals( ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode() );
+    }
+
+
+    /**
+     * Test parsing of a response with Error Message
+     */
+    public void testResponseWithErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyDNResponse.getLdapResult();
+
+        assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
+            .getErrorMessage() );
+    }
+    
+    /**
+     * Test parsing of a response with empty Error Message
+     */
+    public void testResponseWithEmptyErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_empty_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyDNResponse.getLdapResult();
+
+        assertNull( ldapResult.getErrorMessage() );
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral
+     */
+    public void testResponseWith1Referral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyDNResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 1, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a response with an empty Referral
+     */
+    public void testResponseWith1EmptyReferral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyDNResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 0, referrals.size() );
+    }
+
+
+    /**
+     * Test parsing of a response with 2 Referral elements
+     */
+    public void testResponseWith2Referrals()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyDNResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 2, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+
+        Object referral2 = referrals.get( 1 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apple.com/" ).toString(), referral2.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral and an Error Message
+     */
+    public void testResponseWith1ReferralAndAnErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource(
+                "response_with_1_referral_and_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyDNResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 1, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a response with MatchedDN attribute
+     */
+    public void testResponseWithMatchedDNAttribute()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyDNResponse.getLdapResult();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", ldapResult.getMatchedDN() );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong matched DN
+     */
+    public void testResponseWithWrongMatchedDN()
+    {
+        testParsingFail( ModifyDNResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+        testParsingFail( ModifyDNResponseTest.class, "response_with_wrong_descr.xml" );
+    }
+}

Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modDNResponse/ModifyDNResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,586 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.modifyRequest;
+
+
+import java.util.List;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.ModificationItem;
+
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.LdapConstants;
+import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
+
+
+/**
+ * Tests for the Modify Request parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ModifyRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 456, modifyRequest.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute equals to 0
+     */
+    public void testRequestWithRequestIdEquals0()
+    {
+        testParsingFail( ModifyRequestTest.class, "request_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element
+     */
+    public void testRequestWith1Control()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyRequest.getCurrentControl();
+
+        assertEquals( 1, modifyRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with Base64 Value
+     */
+    public void testRequestWith1ControlBase64Value()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyRequest.getCurrentControl();
+
+        assertEquals( 1, modifyRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( "DSMLv2.0 rocks!!", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with empty value
+     */
+    public void testRequestWith1ControlEmptyValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyRequest.getCurrentControl();
+
+        assertEquals( 1, modifyRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 (optional) Control elements
+     */
+    public void testRequestWith2Controls()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyRequest.getCurrentControl();
+
+        assertEquals( 2, modifyRequest.getControls().size() );
+        assertFalse( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
+        assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with 3 (optional) Control elements without value
+     */
+    public void testRequestWith3ControlsWithoutValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = modifyRequest.getCurrentControl();
+
+        assertEquals( 3, modifyRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request without dn attribute
+     */
+    public void testRequestWithoutDnAttribute()
+    {
+        testParsingFail( ModifyRequestTest.class, "request_without_dn_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with a Modification element
+     * @throws NamingException 
+     */
+    public void testRequestWith1Modification() throws NamingException
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_1_modification.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
+
+        assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
+
+        List<ModificationItemImpl> modifications = modifyRequest.getModifications();
+
+        assertEquals( 1, modifications.size() );
+
+        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+
+        Attribute attribute = modification.getAttribute();
+
+        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a Modification element with Base64 Value
+     * @throws NamingException 
+     */
+    public void testRequestWith1ModificationBase64Value() throws NamingException
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_1_modification_base64_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
+
+        assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
+
+        List<ModificationItemImpl> modifications = modifyRequest.getModifications();
+
+        assertEquals( 1, modifications.size() );
+
+        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+
+        Attribute attribute = modification.getAttribute();
+
+        assertEquals( "cn=Emmanuel Lécharny, ou=people, dc=example, dc=com", new String( ( byte[] ) attribute.get( 0 ) ) );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 Modification elements
+     * @throws NamingException 
+     */
+    public void testRequestWith2Modifications() throws NamingException
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_2_modifications.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( LdapConstants.OPERATION_REPLACE, modifyRequest.getCurrentOperation() );
+
+        assertEquals( "sn", modifyRequest.getCurrentAttributeType() );
+
+        List<ModificationItemImpl> modifications = modifyRequest.getModifications();
+
+        assertEquals( 2, modifications.size() );
+
+        ModificationItem modification = ( ModificationItem ) modifications.get( 1 );
+
+        Attribute attribute = modification.getAttribute();
+
+        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 0 ) );
+    }
+
+
+    /**
+     * Test parsing of a request without name attribute to the Modification element
+     */
+    public void testRequestWithoutNameAttribute()
+    {
+        testParsingFail( ModifyRequestTest.class, "request_without_name_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request without operation attribute to the Modification element
+     */
+    public void testRequestWithoutOperationAttribute()
+    {
+        testParsingFail( ModifyRequestTest.class, "request_without_operation_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with operation attribute to Add value
+     * @throws NamingException 
+     */
+    public void testRequestWithOperationAdd() throws NamingException
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_operation_add.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
+    }
+
+
+    /**
+     * Test parsing of a request with operation attribute to Delete value
+     * @throws NamingException 
+     */
+    public void testRequestWithOperationDelete() throws NamingException
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_operation_delete.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( LdapConstants.OPERATION_DELETE, modifyRequest.getCurrentOperation() );
+    }
+
+
+    /**
+     * Test parsing of a request with operation attribute to Replace value
+     * @throws NamingException 
+     */
+    public void testRequestWithOperationReplace() throws NamingException
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_operation_replace.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( LdapConstants.OPERATION_REPLACE, modifyRequest.getCurrentOperation() );
+    }
+
+
+    /**
+     * Test parsing of a request without operation attribute to the Modification element
+     */
+    public void testRequestWithOperationError()
+    {
+        testParsingFail( ModifyRequestTest.class, "request_with_operation_error.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with a Modification element without Value element
+     * @throws NamingException 
+     */
+    public void testRequestWithModificationWithoutValue() throws NamingException
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_modification_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
+
+        assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
+
+        List<ModificationItemImpl> modifications = modifyRequest.getModifications();
+
+        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+
+        Attribute attribute = modification.getAttribute();
+
+        assertEquals( 0, attribute.size() );
+    }
+
+
+    /**
+     * Test parsing of a request with a Modification element
+     * @throws NamingException 
+     */
+    public void testRequestWithModificationWith2Values() throws NamingException
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_modification_with_2_values.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
+
+        assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
+
+        List<ModificationItemImpl> modifications = modifyRequest.getModifications();
+
+        assertEquals( 1, modifications.size() );
+
+        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+
+        Attribute attribute = modification.getAttribute();
+
+        assertEquals( 2, attribute.size() );
+        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ) );
+        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 1 ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a Modification element with an empty value
+     * @throws NamingException 
+     */
+    public void testRequestWithModificationWithEmptyValue() throws NamingException
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_modification_with_empty_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
+
+        assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
+
+        List<ModificationItemImpl> modifications = modifyRequest.getModifications();
+
+        assertEquals( 1, modifications.size() );
+
+        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+
+        Attribute attribute = modification.getAttribute();
+
+        assertEquals( 1, attribute.size() );
+        assertEquals( "", attribute.get( 0 ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a needed requestID attribute
+     * 
+     * DIRSTUDIO-1
+     */
+    public void testRequestWithNeededRequestId()
+    {
+        testParsingFail( ModifyRequestTest.class, "request_with_needed_requestID.xml" );
+    }
+}

Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyResponse/ModifyResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyResponse/ModifyResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyResponse/ModifyResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyResponse/ModifyResponseTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,514 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.modifyResponse;
+
+
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.LdapResult;
+import org.apache.directory.shared.ldap.codec.modify.ModifyResponse;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2ResponseParser;
+
+import com.sun.jndi.ldap.LdapURL;
+
+
+/**
+ * Tests for the Modify Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ModifyResponseTest extends AbstractResponseTest
+{
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 456, modifyResponse.getMessageId() );
+    }
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute equals 0
+     */
+    public void testResponseWithRequestIdEquals0()
+    {
+        testParsingFail( ModifyResponseTest.class, "response_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with a (optional) Control element
+     */
+    public void testResponseWith1Control()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 1, modifyResponse.getControls().size() );
+
+        Control control = modifyResponse.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+    
+    /**
+     * Test parsing of a response with a (optional) Control element with empty value
+     */
+    public void testResponseWith1ControlEmptyValue()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_1_control_empty_value.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+        Control control = modifyResponse.getCurrentControl();
+        
+        assertEquals( 1, modifyResponse.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, ( byte[] ) control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a response with 2 (optional) Control elements
+     */
+    public void testResponseWith2Controls()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 2, modifyResponse.getControls().size() );
+
+        Control control = modifyResponse.getCurrentControl();
+
+        assertFalse( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
+
+        assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a response with 3 (optional) Control elements without value
+     */
+    public void testResponseWith3ControlsWithoutValue()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 3, modifyResponse.getControls().size() );
+
+        Control control = modifyResponse.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a response without Result Code element
+     */
+    public void testResponseWithoutResultCode()
+    {
+        testParsingFail( ModifyResponseTest.class, "response_without_result_code.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( ModifyResponseTest.class, "response_with_result_code_not_integer.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code 
+     */
+    public void testResponseWithResultCode()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyResponse.getLdapResult();
+
+        assertEquals( ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode() );
+    }
+
+
+    /**
+     * Test parsing of a response with Error Message
+     */
+    public void testResponseWithErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyResponse.getLdapResult();
+
+        assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
+            .getErrorMessage() );
+    }
+    
+    /**
+     * Test parsing of a response with empty Error Message
+     */
+    public void testResponseWithEmptyErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_empty_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyResponse.getLdapResult();
+
+        assertNull( ldapResult.getErrorMessage() );
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral
+     */
+    public void testResponseWith1Referral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 1, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a response with an empty Referral
+     */
+    public void testResponseWith1EmptyReferral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 0, referrals.size() );
+    }
+
+
+    /**
+     * Test parsing of a response with 2 Referral elements
+     */
+    public void testResponseWith2Referrals()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 2, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+
+        Object referral2 = referrals.get( 1 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apple.com/" ).toString(), referral2.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral and an Error Message
+     */
+    public void testResponseWith1ReferralAndAnErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class
+                .getResource( "response_with_1_referral_and_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 1, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a response with MatchedDN attribute
+     */
+    public void testResponseWithMatchedDNAttribute()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = modifyResponse.getLdapResult();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", ldapResult.getMatchedDN() );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong matched DN
+     */
+    public void testResponseWithWrongMatchedDN()
+    {
+        testParsingFail( ModifyResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+        testParsingFail( ModifyResponseTest.class, "response_with_wrong_descr.xml" );
+    }
+}

Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyResponse/ModifyResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message