You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by fe...@apache.org on 2007/11/05 15:53:11 UTC
svn commit: r592023 [8/25] - in
/directory/sandbox/felixk/studio-dsml-parser: ./ META-INF/ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/directory/
src/main/java/org/apache/directory/studio/ src/mai...
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/Dsmlv2Grammar.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ExtendedRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ExtendedRequestDsml.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ExtendedRequestDsml.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ExtendedRequestDsml.java Mon Nov 5 06:52:22 2007
@@ -0,0 +1,86 @@
+/*
+ * 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.LdapMessage;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedRequest;
+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.
+ *
+ * @param ldapMessage
+ * the message to decorate
+ */
+ public ExtendedRequestDsml( LdapMessage ldapMessage )
+ {
+ super( ldapMessage );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMessageType()
+ {
+ return instance.getMessageType();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Element toDsml( Element root )
+ {
+ Element element = super.toDsml( root );
+
+ ExtendedRequest request = ( ExtendedRequest ) 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;
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ExtendedRequestDsml.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/LdapRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/LdapRequestDecorator.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/LdapRequestDecorator.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/LdapRequestDecorator.java Mon Nov 5 06:52:22 2007
@@ -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.LdapMessage;
+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( LdapMessage ldapMessage )
+ {
+ super( ldapMessage );
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/LdapRequestDecorator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyDNRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyDNRequestDsml.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyDNRequestDsml.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyDNRequestDsml.java Mon Nov 5 06:52:22 2007
@@ -0,0 +1,87 @@
+/*
+ * 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.LdapMessage;
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest;
+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.
+ *
+ * @param ldapMessage
+ * the message to decorate
+ */
+ public ModifyDNRequestDsml( LdapMessage ldapMessage )
+ {
+ super( ldapMessage );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMessageType()
+ {
+ return instance.getMessageType();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Element toDsml( Element root )
+ {
+ Element element = super.toDsml( root );
+
+ ModifyDNRequest request = ( ModifyDNRequest ) instance;
+
+ // DN
+ if ( request.getEntry() != null )
+ {
+ element.addAttribute( "dn", request.getEntry().toString() );
+ }
+
+ // NewRDN
+ if ( request.getNewRDN() != null )
+ {
+ element.addAttribute( "newrdn", request.getNewRDN().toString() );
+ }
+
+ // DeleteOldRDN
+ element.addAttribute( "deleteoldrdn", ( request.isDeleteOldRDN() ? "true" : "false" ) );
+
+ // NewSuperior
+ if ( request.getNewRDN() != null )
+ {
+ element.addAttribute( "newSuperior", request.getNewSuperior().toString() );
+ }
+
+ return element;
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyDNRequestDsml.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java Mon Nov 5 06:52:22 2007
@@ -0,0 +1,141 @@
+/*
+ * 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 javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+
+import org.apache.directory.shared.ldap.codec.LdapMessage;
+import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+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.
+ *
+ * @param ldapMessage
+ * the message to decorate
+ */
+ public ModifyRequestDsml( LdapMessage ldapMessage )
+ {
+ super( ldapMessage );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMessageType()
+ {
+ return instance.getMessageType();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Element toDsml( Element root )
+ {
+ Element element = super.toDsml( root );
+
+ ModifyRequest request = ( ModifyRequest ) instance;
+
+ // DN
+ if ( request.getObject() != null )
+ {
+ element.addAttribute( "dn", request.getObject().toString() );
+ }
+
+ // Modifications
+ List<ModificationItemImpl> modifications = request.getModifications();
+
+ for ( int i = 0; i < modifications.size(); i++ )
+ {
+ ModificationItemImpl modificationItem = modifications.get( i );
+
+ Element modElement = element.addElement( "modification" );
+ if ( modificationItem.getAttribute() != null )
+ {
+ modElement.addAttribute( "name", modificationItem.getAttribute().getID() );
+
+ try
+ {
+ NamingEnumeration ne = modificationItem.getAttribute().getAll();
+ while ( ne.hasMoreElements() )
+ {
+ Object value = ( Object ) ne.nextElement();
+
+ 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 = modElement.addElement( "value" ).addText( ParserUtils.base64Encode( value ) );
+ valueElement
+ .addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY );
+ }
+ else
+ {
+ modElement.addElement( "value" ).setText( (String) value );
+ }
+ }
+ }
+ }
+ catch ( NamingException e )
+ {
+ }
+ }
+
+ int operation = modificationItem.getModificationOp();
+ if ( operation == DirContext.ADD_ATTRIBUTE )
+ {
+ modElement.addAttribute( "operation", "add" );
+ }
+ else if ( operation == DirContext.REPLACE_ATTRIBUTE )
+ {
+ modElement.addAttribute( "operation", "replace" );
+ }
+ else if ( operation == DirContext.REMOVE_ATTRIBUTE )
+ {
+ modElement.addAttribute( "operation", "delete" );
+ }
+ }
+
+ return element;
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/SearchRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/SearchRequestDsml.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/SearchRequestDsml.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/SearchRequestDsml.java Mon Nov 5 06:52:22 2007
@@ -0,0 +1,338 @@
+/*
+ * 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 javax.naming.NamingEnumeration;
+import javax.naming.directory.Attributes;
+
+import org.apache.directory.shared.ldap.codec.AttributeValueAssertion;
+import org.apache.directory.shared.ldap.codec.LdapConstants;
+import org.apache.directory.shared.ldap.codec.LdapMessage;
+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.SearchRequest;
+import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
+import org.apache.directory.shared.ldap.message.ScopeEnum;
+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.
+ *
+ * @param ldapMessage
+ * the message to decorate
+ */
+ public SearchRequestDsml( LdapMessage ldapMessage )
+ {
+ super( ldapMessage );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMessageType()
+ {
+ return instance.getMessageType();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Element toDsml( Element root )
+ {
+ Element element = super.toDsml( root );
+
+ SearchRequest request = ( SearchRequest ) instance;
+
+ // DN
+ if ( request.getBaseObject() != null )
+ {
+ element.addAttribute( "dn", request.getBaseObject().toString() );
+ }
+
+ // Scope
+ ScopeEnum scope = request.getScope();
+ if ( scope != null )
+ {
+ if ( scope == ScopeEnum.BASE_OBJECT )
+ {
+ element.addAttribute( "scope", "baseObject" );
+ }
+ else if ( scope == ScopeEnum.SINGLE_LEVEL )
+ {
+ element.addAttribute( "scope", "singleLevel" );
+ }
+ else if ( scope == ScopeEnum.WHOLE_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
+ Attributes attributes = request.getAttributes();
+ if ( attributes.size() > 0 )
+ {
+ Element attributesElement = element.addElement( "attributes" );
+
+ NamingEnumeration<String> ids = attributes.getIDs();
+ while ( ids.hasMoreElements() )
+ {
+ attributesElement.addElement( "attribute" ).addAttribute( "name", ids.nextElement() );
+ }
+ }
+
+ 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 );
+ }
+ }
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/SearchRequestDsml.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/main/resources/org/apache/directory/studio/dsmlv2/engine/DSMLv2.xslt
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/main/resources/org/apache/directory/studio/dsmlv2/engine/DSMLv2.xslt?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/main/resources/org/apache/directory/studio/dsmlv2/engine/DSMLv2.xslt (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/main/resources/org/apache/directory/studio/dsmlv2/engine/DSMLv2.xslt Mon Nov 5 06:52:22 2007
@@ -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="'
'"/>
+
+ <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>
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/main/resources/org/apache/directory/studio/dsmlv2/engine/DSMLv2.xslt
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractResponseTest.java Mon Nov 5 06:52:22 2007
@@ -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 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.setInputFile( testClass.getResource( filename ).getFile() );
+
+ parser.parse();
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage(), true );
+ return;
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+ fail();
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractResponseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractTest.java Mon Nov 5 06:52:22 2007
@@ -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.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 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.setInputFile( testClass.getResource( filename ).getFile() );
+
+ parser.parse();
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage(), true );
+ return;
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+ fail();
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AbstractTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AllTests.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AllTests.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AllTests.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AllTests.java Mon Nov 5 06:52:22 2007
@@ -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;
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/AllTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/abandonRequest/AbandonRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/abandonRequest/AbandonRequestTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/abandonRequest/AbandonRequestTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/abandonRequest/AbandonRequestTest.java Mon Nov 5 06:52:22 2007
@@ -0,0 +1,268 @@
+/*
+ * 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.Control;
+import org.apache.directory.shared.ldap.codec.abandon.AbandonRequest;
+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.setInputFile( AbandonRequestTest.class.getResource( "request_with_abandonID_attribute.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AbandonRequest abandonRequest = ( AbandonRequest ) 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.setInputFile( AbandonRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AbandonRequest abandonRequest = ( AbandonRequest ) 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.setInputFile( AbandonRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AbandonRequest abandonRequest = ( AbandonRequest ) parser.getBatchRequest().getCurrentRequest();
+ Control 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.setInputFile( AbandonRequestTest.class.getResource( "request_with_1_control_base64_value.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AbandonRequest abandonRequest = ( AbandonRequest ) parser.getBatchRequest().getCurrentRequest();
+ Control 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.setInputFile( AbandonRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AbandonRequest abandonRequest = ( AbandonRequest ) parser.getBatchRequest().getCurrentRequest();
+ Control 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.setInputFile( AbandonRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AbandonRequest abandonRequest = ( AbandonRequest ) parser.getBatchRequest().getCurrentRequest();
+ Control 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.setInputFile( AbandonRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AbandonRequest abandonRequest = ( AbandonRequest ) parser.getBatchRequest().getCurrentRequest();
+ Control 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" );
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/abandonRequest/AbandonRequestTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addRequest/AddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addRequest/AddRequestTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addRequest/AddRequestTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addRequest/AddRequestTest.java Mon Nov 5 06:52:22 2007
@@ -0,0 +1,675 @@
+/*
+ * 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 javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.add.AddRequest;
+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.setInputFile( AddRequestTest.class.getResource( "request_with_dn_attribute.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", addRequest.getEntry().toString() );
+ }
+
+
+ /**
+ * Test parsing of a request with the (optional) requestID attribute
+ */
+ public void testRequestWithRequestId()
+ {
+ Dsmlv2Parser parser = null;
+ try
+ {
+ parser = new Dsmlv2Parser();
+
+ parser.setInputFile( AddRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) 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.setInputFile( AddRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ assertEquals( 1, addRequest.getControls().size() );
+
+ Control 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.setInputFile( AddRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+ Control 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
+ .setInputFile( AddRequestTest.class.getResource( "request_with_1_control_empty_value.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+ Control 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.setInputFile( AddRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+ Control 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.setInputFile( AddRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+ Control 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.setInputFile( AddRequestTest.class.getResource( "request_with_1_attr_without_value.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ Attributes attributes = addRequest.getAttributes();
+
+ assertEquals( 1, attributes.size() );
+
+ // Getting the Attribute
+ NamingEnumeration ne = attributes.getAll();
+
+ Attribute attribute = null;
+ try
+ {
+ attribute = ( Attribute ) ne.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "objectclass", attribute.getID() );
+
+ // Getting the Value
+ NamingEnumeration ne2 = null;
+ try
+ {
+ ne2 = attribute.getAll();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertFalse( ne2.hasMoreElements() );
+ }
+
+
+ /**
+ * Test parsing of a request with an Attr elements with empty value
+ */
+ public void testRequestWith1AttrEmptyValue()
+ {
+ Dsmlv2Parser parser = null;
+ try
+ {
+ parser = new Dsmlv2Parser();
+
+ parser.setInputFile( AddRequestTest.class.getResource( "request_with_1_attr_empty_value.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ Attributes attributes = addRequest.getAttributes();
+
+ assertEquals( 1, attributes.size() );
+
+ // Getting the Attribute
+ NamingEnumeration ne = attributes.getAll();
+
+ Attribute attribute = null;
+ try
+ {
+ attribute = ( Attribute ) ne.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "objectclass", attribute.getID() );
+
+ // Getting the Value
+ NamingEnumeration ne2 = null;
+ try
+ {
+ ne2 = attribute.getAll();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertFalse( ne2.hasMoreElements() );
+ }
+
+
+ /**
+ * Test parsing of a request with an Attr elements with value
+ */
+ public void testRequestWith1AttrWithValue()
+ {
+ Dsmlv2Parser parser = null;
+ try
+ {
+ parser = new Dsmlv2Parser();
+
+ parser.setInputFile( AddRequestTest.class.getResource( "request_with_1_attr_with_value.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ Attributes attributes = addRequest.getAttributes();
+
+ assertEquals( 1, attributes.size() );
+
+ // Getting the Attribute
+ NamingEnumeration ne = attributes.getAll();
+
+ Attribute attribute = null;
+ try
+ {
+ attribute = ( Attribute ) ne.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "objectclass", attribute.getID() );
+
+ // Getting the Value
+ NamingEnumeration ne2 = null;
+ try
+ {
+ ne2 = attribute.getAll();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ String value = null;
+ try
+ {
+ value = ( String ) ne2.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "top", value );
+ }
+
+
+ /**
+ * Test parsing of a request with an Attr elements with value
+ */
+ public void testRequestWith1AttrWithBase64Value()
+ {
+ Dsmlv2Parser parser = null;
+ try
+ {
+ parser = new Dsmlv2Parser();
+
+ parser.setInputFile( AddRequestTest.class.getResource( "request_with_1_attr_with_base64_value.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ Attributes attributes = addRequest.getAttributes();
+
+ assertEquals( 1, attributes.size() );
+
+ // Getting the Attribute
+ NamingEnumeration ne = attributes.getAll();
+
+ Attribute attribute = null;
+ try
+ {
+ attribute = ( Attribute ) ne.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "objectclass", attribute.getID() );
+
+ // Getting the Value
+ NamingEnumeration ne2 = null;
+ try
+ {
+ ne2 = attribute.getAll();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ Object value = null;
+ try
+ {
+ value = ne2.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) value ) );
+ }
+
+
+ /**
+ * Test parsing of a request with 2 Attr elements with value
+ */
+ public void testRequestWith2AttrWithValue()
+ {
+ Dsmlv2Parser parser = null;
+ try
+ {
+ parser = new Dsmlv2Parser();
+
+ parser.setInputFile( AddRequestTest.class.getResource( "request_with_2_attr_with_value.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ Attributes attributes = addRequest.getAttributes();
+
+ assertEquals( 1, attributes.size() );
+
+ // Getting the Attribute
+ NamingEnumeration ne = attributes.getAll();
+
+ Attribute attribute = null;
+ try
+ {
+ attribute = ( Attribute ) ne.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "objectclass", attribute.getID() );
+
+ // Getting the Value
+ NamingEnumeration ne2 = null;
+ try
+ {
+ ne2 = attribute.getAll();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ String value = null;
+ try
+ {
+ value = ( String ) ne2.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "top", value );
+
+ try
+ {
+ value = ( String ) ne2.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "person", value );
+ }
+
+
+ /**
+ * 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.setInputFile( AddRequestTest.class.getResource( "request_with_1_attr_with_2_values.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ Attributes attributes = addRequest.getAttributes();
+
+ assertEquals( 1, attributes.size() );
+
+ // Getting the Attribute
+ NamingEnumeration ne = attributes.getAll();
+
+ Attribute attribute = null;
+ try
+ {
+ attribute = ( Attribute ) ne.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "objectclass", attribute.getID() );
+
+ // Getting the Value
+ NamingEnumeration ne2 = null;
+ try
+ {
+ ne2 = attribute.getAll();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ String value = null;
+ try
+ {
+ value = ( String ) ne2.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "top", value );
+
+ try
+ {
+ value = ( String ) ne2.next();
+ }
+ catch ( NamingException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ assertEquals( "person", value );
+ }
+
+
+ /**
+ * Test parsing of a request with a needed requestID attribute
+ *
+ * DIRSTUDIO-1
+ */
+ public void testRequestWithNeededRequestId()
+ {
+ testParsingFail( AddRequestTest.class, "request_with_needed_requestID.xml" );
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addRequest/AddRequestTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addResponse/AddResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addResponse/AddResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addResponse/AddResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addResponse/AddResponseTest.java Mon Nov 5 06:52:22 2007
@@ -0,0 +1,512 @@
+/*
+ * 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.Control;
+import org.apache.directory.shared.ldap.codec.LdapResult;
+import org.apache.directory.shared.ldap.codec.add.AddResponse;
+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
+ .setInputFile( AddResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) 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.setInputFile( AddResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ assertEquals( 1, addResponse.getControls().size() );
+
+ Control 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.setInputFile( AddResponseTest.class.getResource( "response_with_1_control_empty_value.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+ Control 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.setInputFile( AddResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ assertEquals( 2, addResponse.getControls().size() );
+
+ Control 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.setInputFile( AddResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ assertEquals( 3, addResponse.getControls().size() );
+
+ Control 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.setInputFile( AddResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ LdapResult 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.setInputFile( AddResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ LdapResult 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.setInputFile( AddResponseTest.class.getResource( "response_with_empty_error_message.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ LdapResult 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.setInputFile( AddResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ LdapResult 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.setInputFile( AddResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ LdapResult 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.setInputFile( AddResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ LdapResult 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.setInputFile( AddResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ LdapResult 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
+ .setInputFile( AddResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
+
+ LdapResult 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" );
+ }
+}
Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/addResponse/AddResponseTest.java
------------------------------------------------------------------------------
svn:eol-style = native