You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2006/11/16 17:38:51 UTC

svn commit: r475805 [10/17] - in /directory/sandbox/pamarcelot/ldapstudio/ldapstudio-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/direc...

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/errorResponse/ErrorResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/errorResponse/ErrorResponseTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/errorResponse/ErrorResponseTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/errorResponse/ErrorResponseTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,299 @@
+/*
+ *  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.ldapstudio.dsmlv2.errorResponse;
+
+import org.apache.directory.ldapstudio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2ResponseParser;
+import org.apache.directory.ldapstudio.dsmlv2.reponse.ErrorResponse;
+import org.apache.directory.ldapstudio.dsmlv2.reponse.ErrorResponse.ErrorResponseType;
+
+/**
+ * Tests for the Error Response parsing
+ */
+public class ErrorResponseTest extends AbstractResponseTest
+{
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 456, errorResponse.getMessageId() );
+    }
+  
+
+    /**
+     * Test parsing of a response without Type attribute
+     */
+    public void testResponseWithoutType()
+    {
+    	testParsingFail( ErrorResponseTest.class, "response_without_type.xml");
+    }
+
+    
+    /**
+     * Test parsing of a response with type == notAttempted
+     */
+    public void testResponseWithTypeNotAttempted()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_notAttempted.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( ErrorResponseType.NOT_ATTEMPTED, errorResponse.getType() );
+    }
+    
+    
+    /**
+     * Test parsing of a response with type == couldNotConnect
+     */
+    public void testResponseWithTypeCouldNotConnect()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_couldNotConnect.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( ErrorResponseType.COULD_NOT_CONNECT, errorResponse.getType() );
+    }
+    
+    
+    /**
+     * Test parsing of a response with type == connectionClosed
+     */
+    public void testResponseWithTypeConnectionClosed()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_connectionClosed.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( ErrorResponseType.CONNECTION_CLOSED, errorResponse.getType() );
+    }
+    
+    
+    /**
+     * Test parsing of a response with type == malformedRequest
+     */
+    public void testResponseWithTypeMalformedRequest()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_malformedRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( ErrorResponseType.MALFORMED_REQUEST, errorResponse.getType() );
+    }
+    
+    
+    /**
+     * Test parsing of a response with type == gatewayInternalError
+     */
+    public void testResponseWithTypeGatewayInternalError()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_gatewayInternalError.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( ErrorResponseType.GATEWAY_INTERNAL_ERROR, errorResponse.getType() );
+    }
+    
+    
+    /**
+     * Test parsing of a response with type == authenticationFailed
+     */
+    public void testResponseWithTypeAuthenticationFailed()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_authenticationFailed.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( ErrorResponseType.AUTHENTICATION_FAILED, errorResponse.getType() );
+    }
+    
+    
+    /**
+     * Test parsing of a response with type == unresolvableURI
+     */
+    public void testResponseWithTypeUnresolvableURI()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_unresolvableURI.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( ErrorResponseType.UNRESOLVABLE_URI, errorResponse.getType() );
+    }
+    
+    
+    /**
+     * Test parsing of a response with type == other
+     */
+    public void testResponseWithTypeOther()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_other.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( ErrorResponseType.OTHER, errorResponse.getType() );
+    }    
+    
+    /**
+     * Test parsing of a response with type in error
+     */
+    public void testResponseWithTypeError()
+    {
+    	testParsingFail( ErrorResponseTest.class, "response_with_type_inError.xml");
+    }
+    
+    /**
+     * Test parsing of a response with Message
+     */
+    public void testResponseWithMessage()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_message.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( "Connection refused", errorResponse.getMessage() );
+    }    
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedRequest/ExtendedRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedRequest/ExtendedRequestTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedRequest/ExtendedRequestTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedRequest/ExtendedRequestTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,201 @@
+/*
+ *  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.ldapstudio.dsmlv2.extendedRequest;
+
+import org.apache.directory.ldapstudio.dsmlv2.AbstractTest;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2Parser;
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedRequest;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+/**
+ * Tests for the Extended Request parsing
+ */
+public class ExtendedRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( ExtendedRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 456, extendedRequest.getMessageId() );
+    }
+    
+
+    /**
+     * Test parsing of a request with a (optional) Control element
+     */
+    public void testRequestWith1Control()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( ExtendedRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 1, extendedRequest.getControls().size() );
+        
+        Control control = extendedRequest.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 request with 2 (optional) Control elements
+     */
+    public void testRequestWith2Controls()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( ExtendedRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 2, extendedRequest.getControls().size() );
+        
+        Control control = extendedRequest.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 request with 3 (optional) Control elements without value
+     */
+    public void testRequestWith3ControlsWithoutValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( ExtendedRequestTest.class.getResource( "request_with_3_controls_without_value.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 3, extendedRequest.getControls().size() );
+        
+        Control control = extendedRequest.getCurrentControl();
+        
+        assertTrue( control.getCriticality() );
+        
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+        
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+    
+    /**
+     * Test parsing of a request with a RequestValue element
+     */
+    public void testRequestWithRequestValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( ExtendedRequestTest.class.getResource( "request_with_requestValue.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        String s1 = StringTools.dumpBytes( StringTools.getBytesUtf8( "RFNNTHYyLjAgcm9ja3MhIQ==" ) );
+        String s2 = StringTools.dumpBytes( extendedRequest.getRequestValue() );
+        
+        //assertTrue( Arrays.equals( StringTools.getBytesUtf8( "RFNNTHYyLjAgcm9ja3MhIQ==" ), extendedRequest.getRequestValue() ) );
+        
+//        assertEquals( s1, s2 );
+        assertEquals( StringTools.getBytesUtf8( "RFNNTHYyLjAgcm9ja3MhIQ==" ), extendedRequest.getRequestValue() );
+    }
+    
+    /**
+     * Test parsing of a request with 2 requestValue Elements
+     */
+    public void testRequestWith2RequestValue()
+    {
+        testParsingFail( ExtendedRequestTest.class, "request_with_2_requestValue.xml" );
+    }
+    
+    /**
+     * Test parsing of a request with 2 requestName Elements
+     */
+    public void testRequestWith2RequestName()
+    {
+        testParsingFail( ExtendedRequestTest.class, "request_with_2_requestName.xml" );
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedResponse/ExtendedResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedResponse/ExtendedResponseTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedResponse/ExtendedResponseTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedResponse/ExtendedResponseTest.java Thu Nov 16 08:38:31 2006
@@ -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.ldapstudio.dsmlv2.extendedResponse;
+
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.ldapstudio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2ResponseParser;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.LdapResult;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import com.sun.jndi.ldap.LdapURL;
+
+/**
+ * Tests for the Extended Response parsing
+ */
+public class ExtendedResponseTest extends AbstractResponseTest
+{
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 456, extendedResponse.getMessageId() );
+    }
+    
+
+    /**
+     * Test parsing of a response with a (optional) Control element
+     */
+    public void testResponseWith1Control()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 1, extendedResponse.getControls().size() );
+        
+        Control control = extendedResponse.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 2 (optional) Control elements
+     */
+    public void testResponseWith2Controls()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 2, extendedResponse.getControls().size() );
+        
+        Control control = extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_3_controls_without_value.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 3, extendedResponse.getControls().size() );
+        
+        Control control = extendedResponse.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( ExtendedResponseTest.class, "response_without_result_code.xml");
+    }
+    
+    
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( ExtendedResponseTest.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( ExtendedResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = extendedResponse.getLdapResult();
+        
+        assertEquals( 2, ldapResult.getResultCode() );
+    }
+    
+    
+    /**
+     * Test parsing of a response with Error Message
+     */
+    public void testResponseWithErrorMessage()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = extendedResponse.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 a Referral
+     */
+    public void testResponseWith1Referral()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = extendedResponse.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 2 Referral elements
+     */
+    public void testResponseWith2Referrals()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = extendedResponse.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( ExtendedResponseTest.class, "response_with_wrong_matchedDN_attribute.xml");
+    }
+    
+    
+    /**
+     * Test parsing of a response with Response Name
+     */
+    public void testResponseWithResponseName()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_responseName.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        try 
+        {
+			assertEquals( new OID( "1.2.3.4.5.6.7.8.9.0" ).toString(), extendedResponse.getResponseName().toString() );
+		} 
+        catch (DecoderException e) 
+        {
+			fail();
+		}
+    }
+    
+    
+    /**
+     * Test parsing of a response with wrong Response Name
+     */
+    public void testResponseWithWrongResponseName()
+    {
+    	testParsingFail( ExtendedResponseTest.class, "response_with_wrong_responseName.xml");
+    }
+    
+    
+    /**
+     * Test parsing of a response with Response
+     */
+    public void testResponseWithResponse()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_response.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( "This is a response", extendedResponse.getResponse() );
+    }
+    
+    
+    /**
+     * Test parsing of a response with Response Name and Response
+     */
+    public void testResponseWithResponseNameAndResponse()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_responseName_and_response.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( "This is a response", extendedResponse.getResponse() );
+                
+        try 
+        {
+			assertEquals( new OID( "1.2.3.4.5.6.7.8.9.0" ).toString(), extendedResponse.getResponseName().toString() );
+		} 
+        catch (DecoderException e) 
+        {
+			fail();
+		}
+    }
+    
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+    	testParsingFail( ExtendedResponseTest.class, "response_with_wrong_descr.xml");
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNRequest/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNRequest/ModifyDNRequestTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNRequest/ModifyDNRequestTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNRequest/ModifyDNRequestTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,328 @@
+/*
+ *  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.ldapstudio.dsmlv2.modDNRequest;
+
+import org.apache.directory.ldapstudio.dsmlv2.AbstractTest;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2Parser;
+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;
+
+/**
+ * Tests for the Modify DN Request parsing
+ */
+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 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();
+        
+        assertEquals( 1, modifyDNRequest.getControls().size() );
+        
+        Control control = modifyDNRequest.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 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();
+        
+        assertEquals( 2, modifyDNRequest.getControls().size() );
+        
+        Control control = modifyDNRequest.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 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();
+        
+        assertEquals( 3, modifyDNRequest.getControls().size() );
+        
+        Control control = modifyDNRequest.getCurrentControl();
+        
+        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() );
+    }
+    
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNResponse/ModifyDNResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNResponse/ModifyDNResponseTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNResponse/ModifyDNResponseTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNResponse/ModifyDNResponseTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,402 @@
+/*
+ *  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.ldapstudio.dsmlv2.modDNResponse;
+
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.ldapstudio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2ResponseParser;
+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.util.StringTools;
+
+import com.sun.jndi.ldap.LdapURL;
+
+/**
+ * Tests for the Modify DN Response parsing
+ */
+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 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 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( 2, 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 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 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");
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyRequest/ModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyRequest/ModifyRequestTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyRequest/ModifyRequestTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyRequest/ModifyRequestTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,417 @@
+/*
+ *  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.ldapstudio.dsmlv2.modifyRequest;
+
+import java.util.ArrayList;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.ModificationItem;
+
+import org.apache.directory.ldapstudio.dsmlv2.AbstractTest;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2Parser;
+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.util.StringTools;
+
+/**
+ * Tests for the Modify Request parsing
+ */
+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 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();
+        
+        assertEquals( 1, modifyRequest.getControls().size() );
+        
+        Control control = modifyRequest.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 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();
+        
+        assertEquals( 2, modifyRequest.getControls().size() );
+        
+        Control control = modifyRequest.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 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();
+        
+        assertEquals( 3, modifyRequest.getControls().size() );
+        
+        Control control = modifyRequest.getCurrentControl();
+        
+        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() );
+        
+        ArrayList 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 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() );
+        
+        ArrayList 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() );
+        
+        ArrayList 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() );
+        
+        ArrayList 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 ) );
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyResponse/ModifyResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyResponse/ModifyResponseTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyResponse/ModifyResponseTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyResponse/ModifyResponseTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,402 @@
+/*
+ *  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.ldapstudio.dsmlv2.modifyResponse;
+
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.ldapstudio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2ResponseParser;
+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.util.StringTools;
+
+import com.sun.jndi.ldap.LdapURL;
+
+/**
+ * Tests for the Modify Response parsing
+ */
+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 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 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( 2, 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 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 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");
+    }
+}