directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r796383 [8/23] - in /directory/shared/trunk: ./ dsml-parser/ dsml-parser/src/ dsml-parser/src/main/ dsml-parser/src/main/java/ dsml-parser/src/main/java/org/ dsml-parser/src/main/java/org/apache/ dsml-parser/src/main/java/org/apache/directo...
Date Tue, 21 Jul 2009 17:04:29 GMT
Added: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ExtendedRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ExtendedRequestDsml.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ExtendedRequestDsml.java (added)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ExtendedRequestDsml.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,140 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.dsmlv2.request;
+
+
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
+import org.apache.directory.studio.dsmlv2.ParserUtils;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+
+
+/**
+ * DSML Decorator for ExtendedRequest
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExtendedRequestDsml extends AbstractRequestDsml
+{
+    /**
+     * Creates a new instance of ExtendedRequestDsml.
+     */
+    public ExtendedRequestDsml()
+    {
+        super( new ExtendedRequestCodec() );
+    }
+
+
+    /**
+     * Creates a new instance of ExtendedRequestDsml.
+     *
+     * @param ldapMessage
+     *      the message to decorate
+     */
+    public ExtendedRequestDsml( ExtendedRequestCodec ldapMessage )
+    {
+        super( ldapMessage );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getMessageType()
+    {
+        return instance.getMessageType();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Element toDsml( Element root )
+    {
+        Element element = super.toDsml( root );
+
+        ExtendedRequestCodec request = ( ExtendedRequestCodec ) instance;
+
+        // Request Name
+        if ( request.getRequestName() != null )
+        {
+            element.addElement( "requestName" ).setText( request.getRequestName() );
+        }
+
+        // Request Value        
+        Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
+        Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
+        element.getDocument().getRootElement().add( xsdNamespace );
+        element.getDocument().getRootElement().add( xsiNamespace );
+
+        Element valueElement = element.addElement( "requestValue" ).addText(
+            ParserUtils.base64Encode( request.getRequestValue() ) );
+        valueElement.addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY );
+
+        return element;
+    }
+
+
+    /**
+     * Get the extended request name
+     * 
+     * @return Returns the request name.
+     */
+    public String getRequestName()
+    {
+        return ( ( ExtendedRequestCodec ) instance ).getRequestName();
+    }
+
+
+    /**
+     * Set the extended request name
+     * 
+     * @param requestName The request name to set.
+     */
+    public void setRequestName( OID requestName )
+    {
+        ( ( ExtendedRequestCodec ) instance ).setRequestName( requestName );
+    }
+
+
+    /**
+     * Get the extended request value
+     * 
+     * @return Returns the request value.
+     */
+    public byte[] getRequestValue()
+    {
+        return ( ( ExtendedRequestCodec ) instance ).getRequestValue();
+    }
+
+
+    /**
+     * Set the extended request value
+     * 
+     * @param requestValue The request value to set.
+     */
+    public void setRequestValue( byte[] requestValue )
+    {
+        ( ( ExtendedRequestCodec ) instance ).getRequestValue();
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/LdapRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/LdapRequestDecorator.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/LdapRequestDecorator.java (added)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/LdapRequestDecorator.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.dsmlv2.request;
+
+import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
+import org.apache.directory.studio.dsmlv2.LdapMessageDecorator;
+
+/**
+ * Decorator abstract class for LdapRequest
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapRequestDecorator extends LdapMessageDecorator
+{
+    /**
+     * Creates a new instance of LdapRequestDecorator.
+     *
+     * @param ldapMessage
+     *      the message to decorate
+     */
+    public LdapRequestDecorator( LdapMessageCodec ldapMessage )
+    {
+        super( ldapMessage );
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyDNRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyDNRequestDsml.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyDNRequestDsml.java (added)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyDNRequestDsml.java Tue Jul 21 17:04:13 2009
@@ -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.studio.dsmlv2.request;
+
+
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequestCodec;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.dom4j.Element;
+
+
+/**
+ * DSML Decorator for ModifyDNRequest
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ModifyDNRequestDsml extends AbstractRequestDsml
+{
+    /**
+     * Creates a new instance of ModifyDNRequestDsml.
+     */
+    public ModifyDNRequestDsml()
+    {
+        super( new ModifyDNRequestCodec() );
+    }
+
+
+    /**
+     * Creates a new instance of ModifyDNRequestDsml.
+     *
+     * @param ldapMessage
+     *      the message to decorate
+     */
+    public ModifyDNRequestDsml( ModifyDNRequestCodec ldapMessage )
+    {
+        super( ldapMessage );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getMessageType()
+    {
+        return instance.getMessageType();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Element toDsml( Element root )
+    {
+        Element element = super.toDsml( root );
+
+        ModifyDNRequestCodec request = ( ModifyDNRequestCodec ) instance;
+
+        // DN
+        if ( request.getEntry() != null )
+        {
+            element.addAttribute( "dn", request.getEntry().getUpName() );
+        }
+
+        // NewRDN
+        if ( request.getNewRDN() != null )
+        {
+            element.addAttribute( "newrdn", request.getNewRDN().getUpName() );
+        }
+
+        // DeleteOldRDN
+        element.addAttribute( "deleteoldrdn", ( request.isDeleteOldRDN() ? "true" : "false" ) );
+
+        // NewSuperior
+        if ( request.getNewRDN() != null )
+        {
+            element.addAttribute( "newSuperior", request.getNewSuperior().getUpName() );
+        }
+
+        return element;
+    }
+
+
+    /**
+     * Get the modification's DN
+     * 
+     * @return Returns the entry.
+     */
+    public LdapDN getEntry()
+    {
+        return ( ( ModifyDNRequestCodec ) instance ).getEntry();
+    }
+
+
+    /**
+     * Set the modification DN.
+     * 
+     * @param entry The entry to set.
+     */
+    public void setEntry( LdapDN entry )
+    {
+        ( ( ModifyDNRequestCodec ) instance ).setEntry( entry );
+    }
+
+
+    /**
+     * Tells if the old RDN is to be deleted
+     * 
+     * @return Returns the deleteOldRDN.
+     */
+    public boolean isDeleteOldRDN()
+    {
+        return ( ( ModifyDNRequestCodec ) instance ).isDeleteOldRDN();
+    }
+
+
+    /**
+     * Set the flag to delete the old RDN
+     * 
+     * @param deleteOldRDN The deleteOldRDN to set.
+     */
+    public void setDeleteOldRDN( boolean deleteOldRDN )
+    {
+        ( ( ModifyDNRequestCodec ) instance ).setDeleteOldRDN( deleteOldRDN );
+    }
+
+
+    /**
+     * Get the new RDN
+     * 
+     * @return Returns the newRDN.
+     */
+    public Rdn getNewRDN()
+    {
+        return ( ( ModifyDNRequestCodec ) instance ).getNewRDN();
+    }
+
+
+    /**
+     * Set the new RDN
+     * 
+     * @param newRDN The newRDN to set.
+     */
+    public void setNewRDN( Rdn newRDN )
+    {
+        ( ( ModifyDNRequestCodec ) instance ).setNewRDN( newRDN );
+    }
+
+
+    /**
+     * Get the newSuperior
+     * 
+     * @return Returns the newSuperior.
+     */
+    public LdapDN getNewSuperior()
+    {
+        return ( ( ModifyDNRequestCodec ) instance ).getNewSuperior();
+    }
+
+
+    /**
+     * Set the new superior
+     * 
+     * @param newSuperior The newSuperior to set.
+     */
+    public void setNewSuperior( LdapDN newSuperior )
+    {
+        ( ( ModifyDNRequestCodec ) instance ).setNewSuperior( newSuperior );
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java (added)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,145 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.dsmlv2.request;
+
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.codec.modify.ModifyRequestCodec;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.studio.dsmlv2.ParserUtils;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+
+
+/**
+ * DSML Decorator for ModifyRequest
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ModifyRequestDsml extends AbstractRequestDsml
+{
+    /**
+     * Creates a new instance of ModifyRequestDsml.
+     */
+    public ModifyRequestDsml()
+    {
+        super( new ModifyRequestCodec() );
+    }
+
+
+    /**
+     * Creates a new instance of ModifyRequestDsml.
+     *
+     * @param ldapMessage
+     *      the message to decorate
+     */
+    public ModifyRequestDsml( ModifyRequestCodec ldapMessage )
+    {
+        super( ldapMessage );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getMessageType()
+    {
+        return instance.getMessageType();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Element toDsml( Element root )
+    {
+        Element element = super.toDsml( root );
+
+        ModifyRequestCodec request = ( ModifyRequestCodec ) instance;
+
+        // DN
+        if ( request.getObject() != null )
+        {
+            element.addAttribute( "dn", request.getObject().getUpName() );
+        }
+
+        // Modifications
+        List<Modification> modifications = request.getModifications();
+
+        for ( int i = 0; i < modifications.size(); i++ )
+        {
+            Modification modificationItem = modifications.get( i );
+
+            Element modElement = element.addElement( "modification" );
+            if ( modificationItem.getAttribute() != null )
+            {
+                modElement.addAttribute( "name", modificationItem.getAttribute().getId() );
+
+                Iterator<Value<?>> iterator = modificationItem.getAttribute().getAll();
+                while ( iterator.hasNext() )
+                {
+                    Value<?> value = iterator.next();
+
+                    if ( value.get() != null )
+                    {
+                        if ( ParserUtils.needsBase64Encoding( value.get() ) )
+                        {
+                            Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
+                            Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
+                            element.getDocument().getRootElement().add( xsdNamespace );
+                            element.getDocument().getRootElement().add( xsiNamespace );
+
+                            Element valueElement = modElement.addElement( "value" ).addText(
+                                ParserUtils.base64Encode( value.get() ) );
+                            valueElement.addAttribute( new QName( "type", xsiNamespace ), "xsd:"
+                                + ParserUtils.BASE64BINARY );
+                        }
+                        else
+                        {
+                            modElement.addElement( "value" ).setText( ( String ) value.get() );
+                        }
+                    }
+                }
+            }
+
+            ModificationOperation operation = modificationItem.getOperation();
+            if ( operation == ModificationOperation.ADD_ATTRIBUTE )
+            {
+                modElement.addAttribute( "operation", "add" );
+            }
+            else if ( operation == ModificationOperation.REPLACE_ATTRIBUTE )
+            {
+                modElement.addAttribute( "operation", "replace" );
+            }
+            else if ( operation == ModificationOperation.REMOVE_ATTRIBUTE )
+            {
+                modElement.addAttribute( "operation", "delete" );
+            }
+        }
+
+        return element;
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/SearchRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/SearchRequestDsml.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/SearchRequestDsml.java (added)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/SearchRequestDsml.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,341 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.dsmlv2.request;
+
+
+import java.util.List;
+
+import org.apache.directory.shared.ldap.codec.AttributeValueAssertion;
+import org.apache.directory.shared.ldap.codec.LdapConstants;
+import org.apache.directory.shared.ldap.codec.search.AndFilter;
+import org.apache.directory.shared.ldap.codec.search.AttributeValueAssertionFilter;
+import org.apache.directory.shared.ldap.codec.search.ExtensibleMatchFilter;
+import org.apache.directory.shared.ldap.codec.search.Filter;
+import org.apache.directory.shared.ldap.codec.search.NotFilter;
+import org.apache.directory.shared.ldap.codec.search.OrFilter;
+import org.apache.directory.shared.ldap.codec.search.PresentFilter;
+import org.apache.directory.shared.ldap.codec.search.SearchRequestCodec;
+import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.studio.dsmlv2.ParserUtils;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+
+
+/**
+ * DSML Decorator for SearchRequest
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SearchRequestDsml extends AbstractRequestDsml
+{
+    /**
+     * Creates a new instance of SearchRequestDsml.
+     */
+    public SearchRequestDsml()
+    {
+        super( new SearchRequestCodec() );
+    }
+
+
+    /**
+     * Creates a new instance of SearchRequestDsml.
+     *
+     * @param ldapMessage
+     *      the message to decorate
+     */
+    public SearchRequestDsml( SearchRequestCodec ldapMessage )
+    {
+        super( ldapMessage );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getMessageType()
+    {
+        return instance.getMessageType();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Element toDsml( Element root )
+    {
+        Element element = super.toDsml( root );
+
+        SearchRequestCodec request = ( SearchRequestCodec ) instance;
+
+        // DN
+        if ( request.getBaseObject() != null )
+        {
+            element.addAttribute( "dn", request.getBaseObject().getUpName() );
+        }
+
+        // Scope
+        SearchScope scope = request.getScope();
+        if ( scope != null )
+        {
+            if ( scope == SearchScope.OBJECT )
+            {
+                element.addAttribute( "scope", "baseObject" );
+            }
+            else if ( scope == SearchScope.ONELEVEL )
+            {
+                element.addAttribute( "scope", "singleLevel" );
+            }
+            else if ( scope == SearchScope.SUBTREE )
+            {
+                element.addAttribute( "scope", "wholeSubtree" );
+            }
+        }
+
+        // DerefAliases
+        int derefAliases = request.getDerefAliases();
+        if ( derefAliases == LdapConstants.NEVER_DEREF_ALIASES )
+        {
+            element.addAttribute( "derefAliases", "neverDerefAliases" );
+        }
+        else if ( derefAliases == LdapConstants.DEREF_IN_SEARCHING )
+        {
+            element.addAttribute( "derefAliases", "derefInSearching" );
+        }
+        else if ( derefAliases == LdapConstants.DEREF_FINDING_BASE_OBJ )
+        {
+            element.addAttribute( "derefAliases", "derefFindingBaseObj" );
+        }
+        else if ( derefAliases == LdapConstants.DEREF_ALWAYS )
+        {
+            element.addAttribute( "derefAliases", "derefAlways" );
+        }
+
+        // SizeLimit
+        if ( request.getSizeLimit() != 0 )
+        {
+            element.addAttribute( "sizeLimit", "" + request.getSizeLimit() );
+        }
+
+        // TimeLimit
+        if ( request.getTimeLimit() != 0 )
+        {
+            element.addAttribute( "timeLimit", "" + request.getTimeLimit() );
+        }
+
+        // TypesOnly
+        if ( request.isTypesOnly() )
+        {
+            element.addAttribute( "typesOnly", "true" );
+        }
+
+        // Filter
+        Element filterElement = element.addElement( "filter" );
+        toDsml( filterElement, request.getFilter() );
+
+        // Attributes
+        List<EntryAttribute> attributes = request.getAttributes();
+        if ( attributes.size() > 0 )
+        {
+            Element attributesElement = element.addElement( "attributes" );
+
+            for ( EntryAttribute entryAttribute : attributes )
+            {
+                attributesElement.addElement( "attribute" ).addAttribute( "name", entryAttribute.getId() );
+            }
+        }
+
+        return element;
+    }
+
+
+    /**
+     * Recursively converts the filter of the Search Request into a DSML representation and adds 
+     * it to the XML Element corresponding to the Search Request
+     *
+     * @param element
+     *      the parent Element
+     * @param filter
+     *      the filter to convert
+     */
+    private void toDsml( Element element, Filter filter )
+    {
+        // AND FILTER
+        if ( filter instanceof AndFilter )
+        {
+            Element newElement = element.addElement( "and" );
+
+            List<Filter> filterList = ( ( AndFilter ) filter ).getAndFilter();
+            for ( int i = 0; i < filterList.size(); i++ )
+            {
+                toDsml( newElement, filterList.get( i ) );
+            }
+        }
+
+        // OR FILTER
+        else if ( filter instanceof OrFilter )
+        {
+            Element newElement = element.addElement( "or" );
+
+            List<Filter> filterList = ( ( OrFilter ) filter ).getOrFilter();
+            for ( int i = 0; i < filterList.size(); i++ )
+            {
+                toDsml( newElement, filterList.get( i ) );
+            }
+        }
+
+        // NOT FILTER
+        else if ( filter instanceof NotFilter )
+        {
+            Element newElement = element.addElement( "not" );
+
+            toDsml( newElement, ( ( NotFilter ) filter ).getNotFilter() );
+        }
+
+        // SUBSTRING FILTER
+        else if ( filter instanceof SubstringFilter )
+        {
+            Element newElement = element.addElement( "substrings" );
+
+            SubstringFilter substringFilter = ( SubstringFilter ) filter;
+
+            newElement.addAttribute( "name", substringFilter.getType() );
+
+            String initial = substringFilter.getInitialSubstrings();
+            if ( ( initial != null ) && ( !"".equals( initial ) ) )
+            {
+                newElement.addElement( "initial" ).setText( initial );
+            }
+
+            List<String> anyList = substringFilter.getAnySubstrings();
+            for ( int i = 0; i < anyList.size(); i++ )
+            {
+                newElement.addElement( "any" ).setText( anyList.get( i ) );
+            }
+
+            String finalString = substringFilter.getFinalSubstrings();
+            if ( ( finalString != null ) && ( !"".equals( finalString ) ) )
+            {
+                newElement.addElement( "final" ).setText( finalString );
+            }
+        }
+
+        // APPROXMATCH, EQUALITYMATCH, GREATEROREQUALS & LESSOREQUAL FILTERS
+        else if ( filter instanceof AttributeValueAssertionFilter )
+        {
+            AttributeValueAssertionFilter avaFilter = ( AttributeValueAssertionFilter ) filter;
+
+            Element newElement = null;
+            int filterType = avaFilter.getFilterType();
+            if ( filterType == LdapConstants.APPROX_MATCH_FILTER )
+            {
+                newElement = element.addElement( "approxMatch" );
+            }
+            else if ( filterType == LdapConstants.EQUALITY_MATCH_FILTER )
+            {
+                newElement = element.addElement( "equalityMatch" );
+            }
+            else if ( filterType == LdapConstants.GREATER_OR_EQUAL_FILTER )
+            {
+                newElement = element.addElement( "greaterOrEqual" );
+            }
+            else if ( filterType == LdapConstants.LESS_OR_EQUAL_FILTER )
+            {
+                newElement = element.addElement( "lessOrEqual" );
+            }
+
+            AttributeValueAssertion assertion = avaFilter.getAssertion();
+            if ( assertion != null )
+            {
+                newElement.addAttribute( "name", assertion.getAttributeDesc() );
+
+                Object value = assertion.getAssertionValue();
+                if ( value != null )
+                {
+                    if ( ParserUtils.needsBase64Encoding( value ) )
+                    {
+                        Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
+                        Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
+                        element.getDocument().getRootElement().add( xsdNamespace );
+                        element.getDocument().getRootElement().add( xsiNamespace );
+
+                        Element valueElement = newElement.addElement( "value" ).addText(
+                            ParserUtils.base64Encode( value ) );
+                        valueElement
+                            .addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY );
+                    }
+                    else
+                    {
+                        newElement.addElement( "value" ).setText( ( String ) value );
+                    }
+                }
+            }
+        }
+
+        // PRESENT FILTER
+        else if ( filter instanceof PresentFilter )
+        {
+            Element newElement = element.addElement( "present" );
+
+            newElement.addAttribute( "name", ( ( PresentFilter ) filter ).getAttributeDescription() );
+        }
+
+        // EXTENSIBLEMATCH
+        else if ( filter instanceof ExtensibleMatchFilter )
+        {
+            Element newElement = element.addElement( "extensibleMatch" );
+
+            ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter ) filter;
+
+            Object value = extensibleMatchFilter.getMatchValue();
+            if ( value != null )
+            {
+                if ( ParserUtils.needsBase64Encoding( value ) )
+                {
+                    Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
+                    Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
+                    element.getDocument().getRootElement().add( xsdNamespace );
+                    element.getDocument().getRootElement().add( xsiNamespace );
+
+                    Element valueElement = newElement.addElement( "value" ).addText( ParserUtils.base64Encode( value ) );
+                    valueElement.addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY );
+                }
+                else
+                {
+                    newElement.addElement( "value" ).setText( ( String ) value );
+                }
+            }
+
+            if ( extensibleMatchFilter.isDnAttributes() )
+            {
+                newElement.addAttribute( "dnAttributes", "true" );
+            }
+
+            String matchingRule = extensibleMatchFilter.getMatchingRule();
+            if ( ( matchingRule != null ) && ( "".equals( matchingRule ) ) )
+            {
+                newElement.addAttribute( "matchingRule", matchingRule );
+            }
+        }
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/main/resources/org/apache/directory/studio/dsmlv2/engine/DSMLv2.xslt
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/resources/org/apache/directory/studio/dsmlv2/engine/DSMLv2.xslt?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/resources/org/apache/directory/studio/dsmlv2/engine/DSMLv2.xslt (added)
+++ directory/shared/trunk/dsml-parser/src/main/resources/org/apache/directory/studio/dsmlv2/engine/DSMLv2.xslt Tue Jul 21 17:04:13 2009
@@ -0,0 +1,48 @@
+<!--
+  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.
+-->
+<xsl:stylesheet version="1.0" 
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:output method="xml"/>
+   <xsl:param name="indent-increment" select="'   '" />
+
+   <xsl:template match="*">
+      <xsl:param name="indent" select="'&#xA;'"/>
+
+      <xsl:value-of select="$indent"/>
+      <xsl:copy>
+        <xsl:copy-of select="@*" />
+        <xsl:apply-templates>
+          <xsl:with-param name="indent"
+               select="concat($indent, $indent-increment)"/>
+        </xsl:apply-templates>
+        <xsl:if test="*">
+          <xsl:value-of select="$indent"/>
+        </xsl:if>
+      </xsl:copy>
+   </xsl:template>
+
+   <xsl:template match="comment()|processing-instruction()">
+      <xsl:copy />
+   </xsl:template>
+
+   <!-- WARNING: this is dangerous. Handle with care -->
+   <!-- <xsl:template match="text()[normalize-space(.)='']"/> -->
+
+</xsl:stylesheet>

Added: directory/shared/trunk/dsml-parser/src/site/site.xml
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/site/site.xml?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/site/site.xml (added)
+++ directory/shared/trunk/dsml-parser/src/site/site.xml Tue Jul 21 17:04:13 2009
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!--
+  @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+-->
+<project name="${project.name}">
+  <body>
+    <menu ref="parent" />
+    <menu ref="reports" />
+  </body>
+</project>

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractResponseTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractResponseTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractResponseTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,67 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2;
+
+
+import junit.framework.TestCase;
+
+import org.apache.directory.studio.dsmlv2.Dsmlv2ResponseParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+
+/**
+ * This class had to be used to create a Response TestCase
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractResponseTest extends TestCase
+{
+    /**
+     * Asserts that parsing throws a correct XmlPullParserException due to an incorrect file
+     *
+     * @param testClass
+     *      the Class of the TestCase
+     * @param filename
+     *      the path of the xml file to parse 
+     */
+    public void testParsingFail( Class testClass, String filename )
+    {
+        try
+        {
+            Dsmlv2ResponseParser parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( testClass.getResource( filename ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( XmlPullParserException e )
+        {
+            assertTrue( e.getMessage(), true );
+            return;
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        fail();
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,69 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2;
+
+
+import java.io.FileInputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
+import org.xmlpull.v1.XmlPullParserException;
+
+
+/**
+ * This class had to be used to create a Request TestCase
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractTest extends TestCase
+{
+    /**
+     * Asserts that parsing throws a correct XmlPullParserException due to an incorrect file
+     *
+     * @param testClass
+     *      the Class of the TestCase
+     * @param filename
+     *      the path of the xml file to parse 
+     */
+    public void testParsingFail( Class testClass, String filename )
+    {
+        try
+        {
+            Dsmlv2Parser parser = new Dsmlv2Parser();
+
+            parser.setInput( testClass.getResource( filename ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( XmlPullParserException e )
+        {
+            assertTrue( e.getMessage(), true );
+            return;
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+        fail();
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AllTests.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AllTests.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AllTests.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AllTests.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,96 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.directory.studio.dsmlv2.abandonRequest.AbandonRequestTest;
+import org.apache.directory.studio.dsmlv2.addRequest.AddRequestTest;
+import org.apache.directory.studio.dsmlv2.addResponse.AddResponseTest;
+import org.apache.directory.studio.dsmlv2.authRequest.AuthRequestTest;
+import org.apache.directory.studio.dsmlv2.authResponse.AuthResponseTest;
+import org.apache.directory.studio.dsmlv2.batchRequest.BatchRequestTest;
+import org.apache.directory.studio.dsmlv2.batchResponse.BatchResponseTest;
+import org.apache.directory.studio.dsmlv2.compareRequest.CompareRequestTest;
+import org.apache.directory.studio.dsmlv2.compareResponse.CompareResponseTest;
+import org.apache.directory.studio.dsmlv2.delRequest.DelRequestTest;
+import org.apache.directory.studio.dsmlv2.delResponse.DelResponseTest;
+import org.apache.directory.studio.dsmlv2.errorResponse.ErrorResponseTest;
+import org.apache.directory.studio.dsmlv2.extendedRequest.ExtendedRequestTest;
+import org.apache.directory.studio.dsmlv2.extendedResponse.ExtendedResponseTest;
+import org.apache.directory.studio.dsmlv2.modDNRequest.ModifyDNRequestTest;
+import org.apache.directory.studio.dsmlv2.modDNResponse.ModifyDNResponseTest;
+import org.apache.directory.studio.dsmlv2.modifyRequest.ModifyRequestTest;
+import org.apache.directory.studio.dsmlv2.modifyResponse.ModifyResponseTest;
+import org.apache.directory.studio.dsmlv2.searchRequest.SearchRequestTest;
+import org.apache.directory.studio.dsmlv2.searchResponse.SearchResponseTest;
+import org.apache.directory.studio.dsmlv2.searchResponse.searchResultDone.SearchResultDoneTest;
+import org.apache.directory.studio.dsmlv2.searchResponse.searchResultEntry.SearchResultEntryTest;
+import org.apache.directory.studio.dsmlv2.searchResponse.searchResultReference.SearchResultReferenceTest;
+
+
+/**
+ * This is the complete Test Suite for DSMLv2 Parser (Request and Response)
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AllTests
+{
+    /**
+     * Lauches the Test Suite
+     * 
+     * @return
+     *      the test
+     */
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite( "Test for org.apache.directory.studio.dsmlv2.addRequest" );
+        //$JUnit-BEGIN$
+        suite.addTestSuite( AbandonRequestTest.class );
+        suite.addTestSuite( AddRequestTest.class );
+        suite.addTestSuite( AddResponseTest.class );
+        suite.addTestSuite( AuthRequestTest.class );
+        suite.addTestSuite( AuthResponseTest.class );
+        suite.addTestSuite( BatchRequestTest.class );
+        suite.addTestSuite( BatchResponseTest.class );
+        suite.addTestSuite( CompareRequestTest.class );
+        suite.addTestSuite( CompareResponseTest.class );
+        suite.addTestSuite( DelRequestTest.class );
+        suite.addTestSuite( DelResponseTest.class );
+        suite.addTestSuite( ErrorResponseTest.class );
+        suite.addTestSuite( ExtendedRequestTest.class );
+        suite.addTestSuite( ExtendedResponseTest.class );
+        suite.addTestSuite( ModifyDNRequestTest.class );
+        suite.addTestSuite( ModifyDNResponseTest.class );
+        suite.addTestSuite( ModifyRequestTest.class );
+        suite.addTestSuite( ModifyResponseTest.class );
+        suite.addTestSuite( SearchRequestTest.class );
+        suite.addTestSuite( SearchResponseTest.class );
+        suite.addTestSuite( SearchResultDoneTest.class );
+        suite.addTestSuite( SearchResultEntryTest.class );
+        suite.addTestSuite( SearchResultReferenceTest.class );
+        //$JUnit-END$
+        return suite;
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/abandonRequest/AbandonRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/abandonRequest/AbandonRequestTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/abandonRequest/AbandonRequestTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/abandonRequest/AbandonRequestTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,273 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.abandonRequest;
+
+
+import org.apache.directory.shared.ldap.codec.ControlCodec;
+import org.apache.directory.shared.ldap.codec.abandon.AbandonRequestCodec;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
+
+
+/**
+ * Tests for the Abandon Request parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AbandonRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request without the abandonID attribute
+     */
+    public void testRequestWithoutAbandonId()
+    {
+        testParsingFail( AbandonRequestTest.class, "request_without_abandonID_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with the abandonID attribute
+     */
+    public void testRequestWithAbandonId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AbandonRequestTest.class.getResource( "request_with_abandonID_attribute.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AbandonRequestCodec abandonRequest = ( AbandonRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 123, abandonRequest.getAbandonedMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute equals to 0
+     */
+    public void testRequestWithRequestIdEquals0()
+    {
+        testParsingFail( AbandonRequestTest.class, "request_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AbandonRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AbandonRequestCodec abandonRequest = ( AbandonRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 456, abandonRequest.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element
+     */
+    public void testRequestWith1Control()
+    {
+        Dsmlv2Parser parser = null;
+
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser
+                .setInput( AbandonRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AbandonRequestCodec abandonRequest = ( AbandonRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 1, abandonRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with Base64 value
+     */
+    public void testRequestWith1ControlBase64Value()
+    {
+        Dsmlv2Parser parser = null;
+
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AbandonRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AbandonRequestCodec abandonRequest = ( AbandonRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 1, abandonRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( "DSMLv2.0 rocks!!", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with empty value
+     */
+    public void testRequestWith1ControlEmptyValue()
+    {
+        Dsmlv2Parser parser = null;
+
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AbandonRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AbandonRequestCodec abandonRequest = ( AbandonRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 1, abandonRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 (optional) Control elements
+     */
+    public void testRequestWith2Controls()
+    {
+        Dsmlv2Parser parser = null;
+
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AbandonRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AbandonRequestCodec abandonRequest = ( AbandonRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 2, abandonRequest.getControls().size() );
+        assertFalse( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
+        assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with 3 (optional) Control elements without value
+     */
+    public void testRequestWith3ControlsWithoutValue()
+    {
+        Dsmlv2Parser parser = null;
+
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AbandonRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AbandonRequestCodec abandonRequest = ( AbandonRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 3, abandonRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with a needed requestID attribute
+     * 
+     * DIRSTUDIO-1
+     */
+    public void testRequestWithNeededRequestId()
+    {
+        testParsingFail( AbandonRequestTest.class, "request_with_needed_requestID.xml" );
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addRequest/AddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addRequest/AddRequestTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addRequest/AddRequestTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addRequest/AddRequestTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,516 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.addRequest;
+
+
+import java.util.Iterator;
+
+import org.apache.directory.shared.ldap.codec.ControlCodec;
+import org.apache.directory.shared.ldap.codec.add.AddRequestCodec;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
+
+
+/**
+ * Tests for the Add Request parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AddRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request without the dn attribute
+     */
+    public void testRequestWithoutDn()
+    {
+        testParsingFail( AddRequestTest.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.setInput( AddRequestTest.class.getResource( "request_with_dn_attribute.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", addRequest.getEntryDn().toString() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 456, addRequest.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute equals to 0
+     */
+    public void testRequestWithRequestIdEquals0()
+    {
+        testParsingFail( AddRequestTest.class, "request_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element
+     */
+    public void testRequestWith1Control()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 1, addRequest.getControls().size() );
+
+        ControlCodec control = addRequest.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 a (optional) Control element with Base64 value
+     */
+    public void testRequestWith1ControlBase64Value()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput(
+                AddRequestTest.class.getResource( "request_with_1_control_base64_value.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = addRequest.getCurrentControl();
+
+        assertEquals( 1, addRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( "DSMLv2.0 rocks!!", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with empty value
+     */
+    public void testRequestWith1ControlEmptyValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_1_control_empty_value.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = addRequest.getCurrentControl();
+
+        assertEquals( 1, addRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 (optional) Control elements
+     */
+    public void testRequestWith2Controls()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = addRequest.getCurrentControl();
+
+        assertEquals( 2, addRequest.getControls().size() );
+        assertFalse( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
+        assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with 3 (optional) Control elements without value
+     */
+    public void testRequestWith3ControlsWithoutValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = addRequest.getCurrentControl();
+
+        assertEquals( 3, addRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with an Attr elements with value
+     */
+    public void testRequestWith1AttrWithoutValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_without_value.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        Entry entry = addRequest.getEntry();
+        assertEquals( 1, entry.size() );
+
+        // Getting the Attribute  
+        Iterator<EntryAttribute> attributeIterator = entry.iterator();
+        EntryAttribute attribute = attributeIterator.next();
+        assertEquals( "objectclass", attribute.getUpId() );
+
+        // Getting the Value
+        Iterator<Value<?>> valueIterator = attribute.iterator();
+        assertFalse( valueIterator.hasNext() );
+    }
+
+
+    /**
+     * Test parsing of a request with an Attr elements with empty value
+     */
+    public void testRequestWith1AttrEmptyValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_empty_value.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        Entry entry = addRequest.getEntry();
+        assertEquals( 1, entry.size() );
+
+        // Getting the Attribute       
+        Iterator<EntryAttribute> attributeIterator = entry.iterator();
+        EntryAttribute attribute = attributeIterator.next();
+        assertEquals( "objectclass", attribute.getUpId() );
+
+        // Getting the Value
+        Iterator<Value<?>> valueIterator = attribute.iterator();
+        assertFalse( valueIterator.hasNext() );
+    }
+
+
+    /**
+     * Test parsing of a request with an Attr elements with value
+     */
+    public void testRequestWith1AttrWithValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_value.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        Entry entry = addRequest.getEntry();
+        assertEquals( 1, entry.size() );
+
+        // Getting the Attribute       
+        Iterator<EntryAttribute> attributeIterator = entry.iterator();
+        EntryAttribute attribute = attributeIterator.next();
+        assertEquals( "objectclass", attribute.getUpId() );
+
+        // Getting the Value
+        Iterator<Value<?>> valueIterator = attribute.iterator();
+        assertTrue( valueIterator.hasNext() );
+        Value<?> value = valueIterator.next();
+        assertEquals( "top", value.get() );
+    }
+
+
+    /**
+     * Test parsing of a request with an Attr elements with value
+     */
+    public void testRequestWith1AttrWithBase64Value()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_base64_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        Entry entry = addRequest.getEntry();
+        assertEquals( 1, entry.size() );
+
+        // Getting the Attribute       
+        Iterator<EntryAttribute> attributeIterator = entry.iterator();
+        EntryAttribute attribute = attributeIterator.next();
+        assertEquals( "objectclass", attribute.getUpId() );
+
+        // Getting the Value
+        Iterator<Value<?>> valueIterator = attribute.iterator();
+        assertTrue( valueIterator.hasNext() );
+        Value<?> value = valueIterator.next();
+        assertTrue( value.isBinary() );
+        assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) value.get() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 Attr elements with value
+     */
+    public void testRequestWith2AttrWithValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_2_attr_with_value.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        Entry entry = addRequest.getEntry();
+        assertEquals( 1, entry.size() );
+
+        // Getting the Attribute       
+        Iterator<EntryAttribute> attributeIterator = entry.iterator();
+        EntryAttribute attribute = attributeIterator.next();
+        assertEquals( "objectclass", attribute.getUpId() );
+
+        // Getting the Value
+        Iterator<Value<?>> valueIterator = attribute.iterator();
+        assertTrue( valueIterator.hasNext() );
+        Value<?> value = valueIterator.next();
+        assertEquals( "top", value.get() );
+        assertTrue( valueIterator.hasNext() );
+        value = valueIterator.next();
+        assertEquals( "person", value.get() );
+        assertFalse( valueIterator.hasNext() );
+    }
+
+
+    /**
+     * Test parsing of a request with 1 Attr element without attribute value
+     */
+    public void testRequestWith1AttrWithoutNameAttribute()
+    {
+        testParsingFail( AddRequestTest.class, "request_with_1_attr_without_name_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with 1 Attr element with 2 Values
+     */
+    public void testRequestWith1AttrWith2Values()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_2_values.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddRequestCodec addRequest = ( AddRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        Entry entry = addRequest.getEntry();
+        assertEquals( 1, entry.size() );
+
+        // Getting the Attribute       
+        Iterator<EntryAttribute> attributeIterator = entry.iterator();
+        EntryAttribute attribute = attributeIterator.next();
+        assertEquals( "objectclass", attribute.getUpId() );
+
+        // Getting the Value
+        Iterator<Value<?>> valueIterator = attribute.iterator();
+        assertTrue( valueIterator.hasNext() );
+        Value<?> value = valueIterator.next();
+        assertEquals( "top", value.get() );
+        assertTrue( valueIterator.hasNext() );
+        value = valueIterator.next();
+        assertEquals( "person", value.get() );
+        assertFalse( valueIterator.hasNext() );
+    }
+
+
+    /**
+     * Test parsing of a request with a needed requestID attribute
+     * 
+     * DIRSTUDIO-1
+     */
+    public void testRequestWithNeededRequestId()
+    {
+        testParsingFail( AddRequestTest.class, "request_with_needed_requestID.xml" );
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addResponse/AddResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addResponse/AddResponseTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addResponse/AddResponseTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addResponse/AddResponseTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,523 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.addResponse;
+
+
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.codec.ControlCodec;
+import org.apache.directory.shared.ldap.codec.LdapResultCodec;
+import org.apache.directory.shared.ldap.codec.add.AddResponseCodec;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2ResponseParser;
+
+import com.sun.jndi.ldap.LdapURL;
+
+
+/**
+ * Tests for the Add Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AddResponseTest extends AbstractResponseTest
+{
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AddResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 456, addResponse.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute equals 0
+     */
+    public void testResponseWithRequestIdEquals0()
+    {
+        testParsingFail( AddResponseTest.class, "response_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with a (optional) Control element
+     */
+    public void testResponseWith1Control()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AddResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 1, addResponse.getControls().size() );
+
+        ControlCodec control = addResponse.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a response with a (optional) Control element with emptyValue
+     */
+    public void testResponseWith1ControlEmptyValue()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AddResponseTest.class.getResource( "response_with_1_control_empty_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+        ControlCodec control = addResponse.getCurrentControl();
+
+        assertEquals( 1, addResponse.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, ( byte[] ) control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a response with 2 (optional) Control elements
+     */
+    public void testResponseWith2Controls()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AddResponseTest.class.getResource( "response_with_2_controls.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 2, addResponse.getControls().size() );
+
+        ControlCodec control = addResponse.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.setInput( AddResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 3, addResponse.getControls().size() );
+
+        ControlCodec control = addResponse.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( AddResponseTest.class, "response_without_result_code.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( AddResponseTest.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
+                .setInput( AddResponseTest.class.getResource( "response_with_result_code.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = addResponse.getLdapResult();
+
+        assertEquals( ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode() );
+    }
+
+
+    /**
+     * Test parsing of a response with Error Message
+     */
+    public void testResponseWithErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AddResponseTest.class.getResource( "response_with_error_message.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = addResponse.getLdapResult();
+
+        assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
+            .getErrorMessage() );
+    }
+
+
+    /**
+     * Test parsing of a response with empty Error Message
+     */
+    public void testResponseWithEmptyErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AddResponseTest.class.getResource( "response_with_empty_error_message.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = addResponse.getLdapResult();
+
+        assertNull( ldapResult.getErrorMessage() );
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral
+     */
+    public void testResponseWith1Referral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AddResponseTest.class.getResource( "response_with_1_referral.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = addResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 1, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a response with an empty Referral
+     */
+    public void testResponseWith1EmptyReferral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AddResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = addResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 0, referrals.size() );
+    }
+
+
+    /**
+     * Test parsing of a response with 2 Referral elements
+     */
+    public void testResponseWith2Referrals()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser
+                .setInput( AddResponseTest.class.getResource( "response_with_2_referrals.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = addResponse.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.setInput( AddResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = addResponse.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.setInput( AddResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        AddResponseCodec addResponse = ( AddResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = addResponse.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( AddResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+        testParsingFail( AddResponseTest.class, "response_with_wrong_descr.xml" );
+    }
+}



Mime
View raw message