directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r475805 [9/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/direct...
Date Thu, 16 Nov 2006 16:38:51 GMT
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/batchRequest/BatchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/batchRequest/BatchRequestTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/batchRequest/BatchRequestTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/batchRequest/BatchRequestTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,743 @@
+/*
+ *  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.batchRequest;
+
+import java.util.List;
+
+import org.apache.directory.ldapstudio.dsmlv2.AbstractTest;
+import org.apache.directory.ldapstudio.dsmlv2.BatchRequest;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2Parser;
+import org.apache.directory.shared.ldap.codec.LdapMessage;
+import org.apache.directory.shared.ldap.codec.abandon.AbandonRequest;
+import org.apache.directory.shared.ldap.codec.add.AddRequest;
+import org.apache.directory.shared.ldap.codec.bind.BindRequest;
+import org.apache.directory.shared.ldap.codec.compare.CompareRequest;
+import org.apache.directory.shared.ldap.codec.del.DelRequest;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedRequest;
+import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest;
+import org.apache.directory.shared.ldap.codec.search.SearchRequest;
+
+/**
+ * Tests for the Compare Response parsing
+ */
+public class BatchRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a Request with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1234567890, batchRequest.getRequestID() );
+    }
+    
+    /**
+     * Test parsing of a Request with the (optional) requestID attribute
+     */
+    public void testResponseWith0Request()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 0, batchRequest.getRequests().size() );
+    }
+    
+    /**
+     * Test parsing of a Request with 1 AuthRequest
+     */
+    public void testResponseWith1AuthRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AuthRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof BindRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 1 AddRequest
+     */
+    public void testResponseWith1AddRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AddRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof AddRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 1 CompareRequest
+     */
+    public void testResponseWith1CompareRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_CompareRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof CompareRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 1 AbandonRequest
+     */
+    public void testResponseWith1AbandonRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AbandonRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof AbandonRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 1 DelRequest
+     */
+    public void testResponseWith1DelRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_DelRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof DelRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 1 ExtendedRequest
+     */
+    public void testResponseWith1ExtendedRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_ExtendedRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof ExtendedRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 1 ModDNRequest
+     */
+    public void testResponseWith1ModDNRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_ModDNRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof ModifyDNRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 1 ModifyRequest
+     */
+    public void testResponseWith1ModifyRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_ModifyRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof ModifyRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 1 SearchRequest
+     */
+    public void testResponseWith1SearchRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_SearchRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 1, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof SearchRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    
+    /**
+     * Test parsing of a Request with 2 AddRequest
+     */
+    public void testResponseWith2AddRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_AddRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 2, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof AddRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 2 CompareRequest
+     */
+    public void testResponseWith2CompareRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_CompareRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 2, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof CompareRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 2 AbandonRequest
+     */
+    public void testResponseWith2AbandonRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_AbandonRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 2, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof AbandonRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 2 DelRequest
+     */
+    public void testResponseWith2DelRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_DelRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 2, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof DelRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 2 ExtendedRequest
+     */
+    public void testResponseWith2ExtendedRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_ExtendedRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 2, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof ExtendedRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 2 ModDNRequest
+     */
+    public void testResponseWith2ModDNRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_ModDNRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 2, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof ModifyDNRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 2 ModifyRequest
+     */
+    public void testResponseWith2ModifyRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_ModifyRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 2, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof ModifyRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 2 SearchRequest
+     */
+    public void testResponseWith2SearchRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_SearchRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        assertEquals( 2, batchRequest.getRequests().size() );
+        
+        LdapMessage request = batchRequest.getCurrentRequest();
+        
+        if ( request instanceof SearchRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Request with 1 AuthRequest and 1 AddRequest
+     */
+    public void testResponseWith1AuthRequestAnd1AddRequest()
+    {
+    	Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AuthRequest_1_AddRequest.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchRequest batchRequest = parser.getBatchRequest();
+        
+        List requests = batchRequest.getRequests();
+        
+        assertEquals( 2, requests.size() );
+        
+        LdapMessage request = (LdapMessage) requests.get( 0 );
+        
+        if ( request instanceof BindRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+        
+        request = (LdapMessage) requests.get( 1 );
+        
+        if ( request instanceof AddRequest ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a request with 1 wrong placed AuthRequest
+     */
+    public void testRequestWithWrongPlacedAuthRequest()
+    {
+        testParsingFail( BatchRequestTest.class, "request_with_wrong_placed_AuthRequest.xml" );
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/batchResponse/BatchResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/batchResponse/BatchResponseTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/batchResponse/BatchResponseTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/batchResponse/BatchResponseTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,720 @@
+/*
+ *  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.batchResponse;
+
+import org.apache.directory.ldapstudio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.ldapstudio.dsmlv2.BatchResponse;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2ResponseParser;
+import org.apache.directory.ldapstudio.dsmlv2.reponse.ErrorResponse;
+import org.apache.directory.ldapstudio.dsmlv2.reponse.SearchResponse;
+import org.apache.directory.shared.ldap.codec.LdapResponse;
+import org.apache.directory.shared.ldap.codec.add.AddResponse;
+import org.apache.directory.shared.ldap.codec.bind.BindResponse;
+import org.apache.directory.shared.ldap.codec.compare.CompareResponse;
+import org.apache.directory.shared.ldap.codec.del.DelResponse;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
+import org.apache.directory.shared.ldap.codec.modify.ModifyResponse;
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNResponse;
+
+/**
+ * Tests for the Compare Response parsing
+ */
+public class BatchResponseTest extends AbstractResponseTest
+{
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1234567890, batchResponse.getRequestID() );
+    }
+    
+    /**
+     * Test parsing of a Response with 0 Response
+     */
+    public void testResponseWith0Reponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_0_response.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 0, batchResponse.getResponses().size() );
+    }
+    
+    
+    /**
+     * Test parsing of a Response with the 1 AddResponse
+     */
+    public void testResponseWith1AddResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_AddResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof AddResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 1 AuthResponse
+     */
+    public void testResponseWith1AuthResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_AuthResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof BindResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 1 CompareResponse
+     */
+    public void testResponseWith1CompareResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_CompareResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof CompareResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 1 DelResponse
+     */
+    public void testResponseWith1DelResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_DelResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof DelResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 1 ErrorResponse
+     */
+    public void testResponseWith1ErrorResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ErrorResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof ErrorResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 1 ExtendedResponse
+     */
+    public void testResponseWith1ExtendedResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ExtendedResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof ExtendedResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 1 ModDNResponse
+     */
+    public void testResponseWith1ModDNResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ModDNResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof ModifyDNResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 1 ModifyResponse
+     */
+    public void testResponseWith1ModifyResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ModifyResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof ModifyResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 1 SearchResponse
+     */
+    public void testResponseWith1SearchResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_SearchResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 1, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof SearchResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 2 AddResponse
+     */
+    public void testResponseWith2AddResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_AddResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 2, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof AddResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 2 AuthResponse
+     */
+    public void testResponseWith2AuthResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_AuthResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 2, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof BindResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 2 CompareResponse
+     */
+    public void testResponseWith2CompareResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_CompareResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 2, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof CompareResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 2 DelResponse
+     */
+    public void testResponseWith2DelResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_DelResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 2, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof DelResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 2 ErrorResponse
+     */
+    public void testResponseWith2ErrorResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ErrorResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 2, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof ErrorResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 2 ExtendedResponse
+     */
+    public void testResponseWith2ExtendedResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ExtendedResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 2, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof ExtendedResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 2 ModDNResponse
+     */
+    public void testResponseWith2ModDNResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ModDNResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 2, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof ModifyDNResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 2 ModifyResponse
+     */
+    public void testResponseWith2ModifyResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ModifyResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 2, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof ModifyResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a Response with the 2 SearchResponse
+     */
+    public void testResponseWith2SearchResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_SearchResponse.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        BatchResponse batchResponse = parser.getBatchResponse();
+        
+        assertEquals( 2, batchResponse.getResponses().size() );
+        
+        LdapResponse response = batchResponse.getCurrentResponse();
+        
+        if ( response instanceof SearchResponse ) 
+        {
+        	assertTrue( true );
+		}
+        else
+        {
+        	fail();
+        }
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/compareRequest/CompareRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/compareRequest/CompareRequestTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/compareRequest/CompareRequestTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/compareRequest/CompareRequestTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,256 @@
+/*
+ *  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.compareRequest;
+
+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.compare.CompareRequest;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+/**
+ * Tests for the Compare Request parsing
+ */
+public class CompareRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request without the dn attribute
+     */
+    public void testRequestWithoutDn()
+    {
+        testParsingFail( CompareRequestTest.class, "request_without_dn_attribute.xml" );
+    }
+    
+    /**
+     * Test parsing of a request with the dn attribute
+     */
+    public void testRequestWithDn()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( CompareRequestTest.class.getResource( "request_with_dn_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", compareRequest.getEntry().toString() );
+    }
+    
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( CompareRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 456, compareRequest.getMessageId() );
+    }
+    
+
+    /**
+     * Test parsing of a request with a (optional) Control element
+     */
+    public void testRequestWith1Control()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( CompareRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 1, compareRequest.getControls().size() );
+        
+        Control control = compareRequest.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( CompareRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 2, compareRequest.getControls().size() );
+        
+        Control control = compareRequest.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( CompareRequestTest.class.getResource( "request_with_3_controls_without_value.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 3, compareRequest.getControls().size() );
+        
+        Control control = compareRequest.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 an Attr elements with value
+     */
+    public void testRequestWith1CompleteAssertion()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( CompareRequestTest.class.getResource( "request_with_1_complete_assertion.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", (String) compareRequest.getEntry().toString() );
+
+        assertEquals( "sn", (String) compareRequest.getAttributeDesc()  );
+        
+        assertEquals( "Johnson", (String) compareRequest.getAssertionValue() );
+    }
+    
+    /**
+     * Test parsing of a request without the Assertion element
+     */
+    public void testRequestWithoutAssertion()
+    {
+        testParsingFail( CompareRequestTest.class, "request_without_assertion.xml" );
+    }
+    
+    /**
+     * Test parsing of a request with 2 complete Assertion element
+     */
+    public void testRequestWith2CompleteAssertions()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_2_complete_assertions.xml" );
+    }
+    
+    /**
+     * Test parsing of a request with 1 Assertion element without the name attribute
+     */
+    public void testRequestWith1AssertionWithoutNameAttribute()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_1_assertion_without_name_attribute.xml" );
+    }
+    
+    /**
+     * Test parsing of a request with 1 Assertion element without the Value element
+     */
+    public void testRequestWith1AssertionWithoutValue()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_1_assertion_without_value.xml" );
+    }
+    
+    /**
+     * Test parsing of a request with 1 Assertion element with 2 Value elements
+     */
+    public void testRequestWith1AssertionWith2Value()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_1_assertion_with_2_values.xml" );
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/compareResponse/CompareResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/compareResponse/CompareResponseTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/compareResponse/CompareResponseTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/compareResponse/CompareResponseTest.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.compareResponse;
+
+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.compare.CompareResponse;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import com.sun.jndi.ldap.LdapURL;
+
+/**
+ * Tests for the Compare Response parsing
+ */
+public class CompareResponseTest extends AbstractResponseTest
+{
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( CompareResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 456, compareResponse.getMessageId() );
+    }
+    
+
+    /**
+     * Test parsing of a response with a (optional) Control element
+     */
+    public void testResponseWith1Control()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( CompareResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 1, compareResponse.getControls().size() );
+        
+        Control control = compareResponse.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( CompareResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 2, compareResponse.getControls().size() );
+        
+        Control control = compareResponse.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( CompareResponseTest.class.getResource( "response_with_3_controls_without_value.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 3, compareResponse.getControls().size() );
+        
+        Control control = compareResponse.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( CompareResponseTest.class, "response_without_result_code.xml");
+    }
+    
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( CompareResponseTest.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( CompareResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class, "response_with_wrong_matchedDN_attribute.xml");
+    }
+    
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+        testParsingFail( CompareResponseTest.class, "response_with_wrong_descr.xml");
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/delRequest/DelRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/delRequest/DelRequestTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/delRequest/DelRequestTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/delRequest/DelRequestTest.java Thu Nov 16 08:38:31 2006
@@ -0,0 +1,187 @@
+/*
+ *  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.delRequest;
+
+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.del.DelRequest;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+/**
+ * Tests for the Del Request parsing
+ */
+public class DelRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request without the dn attribute
+     */
+    public void testRequestWithoutDn()
+    {
+        testParsingFail( DelRequestTest.class, "request_without_dn_attribute.xml" );
+    }
+    
+    /**
+     * Test parsing of a request with the dn attribute
+     */
+    public void testRequestWithDn()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( DelRequestTest.class.getResource( "request_with_dn_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", delRequest.getEntry().toString() );
+    }
+    
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( DelRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 456, delRequest.getMessageId() );
+    }
+    
+
+    /**
+     * Test parsing of a request with a (optional) Control element
+     */
+    public void testRequestWith1Control()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+            
+            parser.setInputFile( DelRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 1, delRequest.getControls().size() );
+        
+        Control control = delRequest.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( DelRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 2, delRequest.getControls().size() );
+        
+        Control control = delRequest.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( DelRequestTest.class.getResource( "request_with_3_controls_without_value.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        
+        assertEquals( 3, delRequest.getControls().size() );
+        
+        Control control = delRequest.getCurrentControl();
+        
+        assertTrue( control.getCriticality() );
+        
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+        
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/delResponse/DelResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/delResponse/DelResponseTest.java?view=auto&rev=475805
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/delResponse/DelResponseTest.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/delResponse/DelResponseTest.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.delResponse;
+
+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.del.DelResponse;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import com.sun.jndi.ldap.LdapURL;
+
+/**
+ * Tests for the Del Response parsing
+ */
+public class DelResponseTest extends AbstractResponseTest
+{
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( DelResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 456, delResponse.getMessageId() );
+    }
+    
+
+    /**
+     * Test parsing of a response with a (optional) Control element
+     */
+    public void testResponseWith1Control()
+    {
+    	Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+            
+            parser.setInputFile( DelResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 1, delResponse.getControls().size() );
+        
+        Control control = delResponse.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( DelResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 2, delResponse.getControls().size() );
+        
+        Control control = delResponse.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( DelResponseTest.class.getResource( "response_with_3_controls_without_value.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        assertEquals( 3, delResponse.getControls().size() );
+        
+        Control control = delResponse.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( DelResponseTest.class, "response_without_result_code.xml");
+    }
+    
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( DelResponseTest.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( DelResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).getFile() );
+        
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class, "response_with_wrong_matchedDN_attribute.xml");
+    }
+    
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+        testParsingFail( DelResponseTest.class, "response_with_wrong_descr.xml");
+    }
+}



Mime
View raw message