You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2006/12/06 14:17:46 UTC
svn commit: r483066 [8/10] - in
/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src:
main/java/org/apache/directory/ldapstudio/dsmlv2/
main/java/org/apache/directory/ldapstudio/dsmlv2/engine/
main/java/org/apache/directory/ldapstudio/ds...
Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedResponse/ExtendedResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedResponse/ExtendedResponseTest.java?view=diff&rev=483066&r1=483065&r2=483066
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedResponse/ExtendedResponseTest.java (original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/extendedResponse/ExtendedResponseTest.java Wed Dec 6 05:17:42 2006
@@ -20,6 +20,7 @@
package org.apache.directory.ldapstudio.dsmlv2.extendedResponse;
+
import java.util.List;
import javax.naming.NamingException;
@@ -35,13 +36,13 @@
import com.sun.jndi.ldap.LdapURL;
+
/**
* Tests for the Extended Response parsing
*/
public class ExtendedResponseTest extends AbstractResponseTest
{
-
-
+
/**
* Test parsing of a Response with the (optional) requestID attribute
*/
@@ -51,34 +52,35 @@
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
-
+
+ parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 456, extendedResponse.getMessageId() );
}
-
+
/**
* Test parsing of a response with a (optional) Control element
*/
public void testResponseWith1Control()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -87,64 +89,65 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 1, extendedResponse.getControls().size() );
-
+
Control control = extendedResponse.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
-
+
assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
+
/**
* Test parsing of a response with 2 (optional) Control elements
*/
public void testResponseWith2Controls()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 2, extendedResponse.getControls().size() );
-
+
Control control = extendedResponse.getCurrentControl();
-
+
assertFalse( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
-
+
assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
-
+
+
/**
* Test parsing of a response with 3 (optional) Control elements without value
*/
public void testResponseWith3ControlsWithoutValue()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_3_controls_without_value.xml" ).getFile() );
-
+
+ parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -153,49 +156,49 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 3, extendedResponse.getControls().size() );
-
+
Control control = extendedResponse.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
-
+
assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
}
-
-
+
+
/**
* Test parsing of a response without Result Code element
*/
public void testResponseWithoutResultCode()
{
- testParsingFail( ExtendedResponseTest.class, "response_without_result_code.xml");
+ testParsingFail( ExtendedResponseTest.class, "response_without_result_code.xml" );
}
-
-
+
+
/**
* Test parsing of a response with Result Code element but a not integer value
*/
public void testResponseWithResultCodeNotInteger()
{
- testParsingFail( ExtendedResponseTest.class, "response_with_result_code_not_integer.xml");
+ testParsingFail( ExtendedResponseTest.class, "response_with_result_code_not_integer.xml" );
}
-
-
+
+
/**
* Test parsing of a response with Result Code
*/
public void testResponseWithResultCode()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -204,25 +207,25 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = extendedResponse.getLdapResult();
-
+
assertEquals( 2, ldapResult.getResultCode() );
}
-
-
+
+
/**
* Test parsing of a response with Error Message
*/
public void testResponseWithErrorMessage()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -231,25 +234,26 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = extendedResponse.getLdapResult();
-
- assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult.getErrorMessage() );
+
+ assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
+ .getErrorMessage() );
}
-
-
+
+
/**
* Test parsing of a response with a Referral
*/
public void testResponseWith1Referral()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -258,38 +262,38 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = extendedResponse.getLdapResult();
-
+
List referrals = ldapResult.getReferrals();
-
+
assertEquals( 1, referrals.size() );
-
+
Object referral = referrals.get( 0 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
- }
- catch (NamingException e)
+ assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+ }
+ catch ( NamingException e )
{
- fail();
- }
+ fail();
+ }
}
-
-
+
+
/**
* Test parsing of a response with 2 Referral elements
*/
public void testResponseWith2Referrals()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -298,49 +302,50 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = extendedResponse.getLdapResult();
-
+
List referrals = ldapResult.getReferrals();
-
+
assertEquals( 2, referrals.size() );
-
+
Object referral = referrals.get( 0 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
- }
- catch (NamingException e)
- {
- fail();
- }
-
+ assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+ }
+ catch ( NamingException e )
+ {
+ fail();
+ }
+
Object referral2 = referrals.get( 1 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apple.com/" ).toString(), referral2.toString() );
- }
- catch (NamingException e)
+ assertEquals( new LdapURL( "ldap://www.apple.com/" ).toString(), referral2.toString() );
+ }
+ catch ( NamingException e )
{
- fail();
- }
+ fail();
+ }
}
-
-
+
+
/**
* Test parsing of a response with a Referral and an Error Message
*/
public void testResponseWith1ReferralAndAnErrorMessage()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" ).getFile() );
-
+
+ parser.setInputFile( ExtendedResponseTest.class.getResource(
+ "response_with_1_referral_and_error_message.xml" ).getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -349,38 +354,39 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = extendedResponse.getLdapResult();
-
+
List referrals = ldapResult.getReferrals();
-
+
assertEquals( 1, referrals.size() );
-
+
Object referral = referrals.get( 0 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
- }
- catch (NamingException e)
+ assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+ }
+ catch ( NamingException e )
{
- fail();
- }
+ fail();
+ }
}
-
-
+
+
/**
* Test parsing of a response with MatchedDN attribute
*/
public void testResponseWithMatchedDNAttribute()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).getFile() );
-
+
+ parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -389,34 +395,34 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = extendedResponse.getLdapResult();
-
+
assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", ldapResult.getMatchedDN() );
}
-
-
+
+
/**
* Test parsing of a response with wrong matched DN
*/
public void testResponseWithWrongMatchedDN()
{
- testParsingFail( ExtendedResponseTest.class, "response_with_wrong_matchedDN_attribute.xml");
+ testParsingFail( ExtendedResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
}
-
-
+
+
/**
* Test parsing of a response with Response Name
*/
public void testResponseWithResponseName()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_responseName.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -425,39 +431,39 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
- try
+
+ try
{
- assertEquals( new OID( "1.2.3.4.5.6.7.8.9.0" ).toString(), extendedResponse.getResponseName().toString() );
- }
- catch (DecoderException e)
+ assertEquals( new OID( "1.2.3.4.5.6.7.8.9.0" ).toString(), extendedResponse.getResponseName().toString() );
+ }
+ catch ( DecoderException e )
{
- fail();
- }
+ fail();
+ }
}
-
-
+
+
/**
* Test parsing of a response with wrong Response Name
*/
public void testResponseWithWrongResponseName()
{
- testParsingFail( ExtendedResponseTest.class, "response_with_wrong_responseName.xml");
+ testParsingFail( ExtendedResponseTest.class, "response_with_wrong_responseName.xml" );
}
-
-
+
+
/**
* Test parsing of a response with Response
*/
public void testResponseWithResponse()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_response.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -466,23 +472,24 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( "This is a response", extendedResponse.getResponse() );
}
-
-
+
+
/**
* Test parsing of a response with Response Name and Response
*/
public void testResponseWithResponseNameAndResponse()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_responseName_and_response.xml" ).getFile() );
-
+
+ parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_responseName_and_response.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -491,24 +498,25 @@
}
ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( "This is a response", extendedResponse.getResponse() );
-
- try
+
+ try
{
- assertEquals( new OID( "1.2.3.4.5.6.7.8.9.0" ).toString(), extendedResponse.getResponseName().toString() );
- }
- catch (DecoderException e)
+ assertEquals( new OID( "1.2.3.4.5.6.7.8.9.0" ).toString(), extendedResponse.getResponseName().toString() );
+ }
+ catch ( DecoderException e )
{
- fail();
- }
+ fail();
+ }
}
-
+
+
/**
* Test parsing of a response with wrong Descr attribute
*/
public void testResponseWithWrongDescr()
{
- testParsingFail( ExtendedResponseTest.class, "response_with_wrong_descr.xml");
+ testParsingFail( ExtendedResponseTest.class, "response_with_wrong_descr.xml" );
}
}
Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNRequest/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNRequest/ModifyDNRequestTest.java?view=diff&rev=483066&r1=483065&r2=483066
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNRequest/ModifyDNRequestTest.java (original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNRequest/ModifyDNRequestTest.java Wed Dec 6 05:17:42 2006
@@ -20,12 +20,14 @@
package org.apache.directory.ldapstudio.dsmlv2.modDNRequest;
+
import org.apache.directory.ldapstudio.dsmlv2.AbstractTest;
import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2Parser;
import org.apache.directory.shared.ldap.codec.Control;
import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest;
import org.apache.directory.shared.ldap.util.StringTools;
+
/**
* Tests for the Modify DN Request parsing
*/
@@ -40,21 +42,22 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( 456, modifyDNRequest.getMessageId() );
}
-
+
/**
* Test parsing of a request with a (optional) Control element
@@ -65,29 +68,63 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( 1, modifyDNRequest.getControls().size() );
-
+
Control control = modifyDNRequest.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
-
+
assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
+
+
+ /**
+ * Test parsing of a request with a (optional) Control element with empty value
+ */
+ public void testRequestWith1ControlEmptyValue()
+ {
+ Dsmlv2Parser parser = null;
+ try
+ {
+ parser = new Dsmlv2Parser();
+
+ parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ assertEquals( 1, modifyDNRequest.getControls().size() );
+
+ Control control = modifyDNRequest.getCurrentControl();
+
+ 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
@@ -98,29 +135,30 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( 2, modifyDNRequest.getControls().size() );
-
+
Control control = modifyDNRequest.getCurrentControl();
-
+
assertFalse( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
-
+
assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
+
+
/**
* Test parsing of a request with 3 (optional) Control elements without value
*/
@@ -130,29 +168,31 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_3_controls_without_value.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( 3, modifyDNRequest.getControls().size() );
-
+
Control control = modifyDNRequest.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
-
+
assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
}
-
+
+
/**
* Test parsing of a request without dn attribute
*/
@@ -160,7 +200,8 @@
{
testParsingFail( ModifyDNRequestTest.class, "request_without_dn_attribute.xml" );
}
-
+
+
/**
* Test parsing of a request without newrdn attribute
*/
@@ -168,7 +209,8 @@
{
testParsingFail( ModifyDNRequestTest.class, "request_without_newrdn_attribute.xml" );
}
-
+
+
/**
* Test parsing of a request without dn and newrdn attributes
*/
@@ -178,23 +220,25 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_dn_and_newrdn_attributes.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_dn_and_newrdn_attributes.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", modifyDNRequest.getEntry().toString() );
-
+
assertEquals( "cn=Steve Jobs", modifyDNRequest.getNewRDN().toString() );
}
-
+
+
/**
* Test parsing of a request with deleteoldrdn to true
*/
@@ -204,22 +248,23 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_true.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_true.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertTrue( modifyDNRequest.isDeleteOldRDN() );
}
-
-
+
+
/**
* Test parsing of a request with deleteoldrdn to 1
*/
@@ -229,21 +274,22 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_1.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertTrue( modifyDNRequest.isDeleteOldRDN() );
}
-
+
+
/**
* Test parsing of a request with deleteoldrdn to false
*/
@@ -253,21 +299,22 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_false.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_false.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertFalse( modifyDNRequest.isDeleteOldRDN() );
}
-
+
/**
* Test parsing of a request with deleteoldrdn to 0
@@ -278,21 +325,22 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_0.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertFalse( modifyDNRequest.isDeleteOldRDN() );
}
-
+
+
/**
* Test parsing of a request with deleteoldrdn to an error value
*/
@@ -300,7 +348,8 @@
{
testParsingFail( ModifyDNRequestTest.class, "request_with_deleteoldrdn_error.xml" );
}
-
+
+
/**
* Test parsing of a request with newSuperior attribute
*/
@@ -310,19 +359,20 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_newSuperior_attribute.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNRequestTest.class.getResource( "request_with_newSuperior_attribute.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNRequest modifyDNRequest = ( ModifyDNRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( "cn=Steve Jobs,ou=Dev,dc=apple,dc=com", modifyDNRequest.getNewSuperior().toString() );
}
-
+
}
Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNResponse/ModifyDNResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNResponse/ModifyDNResponseTest.java?view=diff&rev=483066&r1=483065&r2=483066
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNResponse/ModifyDNResponseTest.java (original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modDNResponse/ModifyDNResponseTest.java Wed Dec 6 05:17:42 2006
@@ -20,6 +20,7 @@
package org.apache.directory.ldapstudio.dsmlv2.modDNResponse;
+
import java.util.List;
import javax.naming.NamingException;
@@ -33,13 +34,13 @@
import com.sun.jndi.ldap.LdapURL;
+
/**
* Tests for the Modify DN Response parsing
*/
public class ModifyDNResponseTest extends AbstractResponseTest
{
-
-
+
/**
* Test parsing of a Response with the (optional) requestID attribute
*/
@@ -49,34 +50,35 @@
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 456, modifyDNResponse.getMessageId() );
}
-
+
/**
* Test parsing of a response with a (optional) Control element
*/
public void testResponseWith1Control()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -85,63 +87,65 @@
}
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 1, modifyDNResponse.getControls().size() );
-
+
Control control = modifyDNResponse.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
-
+
assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
+
/**
* Test parsing of a response with 2 (optional) Control elements
*/
public void testResponseWith2Controls()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 2, modifyDNResponse.getControls().size() );
-
+
Control control = modifyDNResponse.getCurrentControl();
-
+
assertFalse( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
-
+
assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
+
+
/**
* Test parsing of a response with 3 (optional) Control elements without value
*/
public void testResponseWith3ControlsWithoutValue()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_3_controls_without_value.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -150,46 +154,49 @@
}
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 3, modifyDNResponse.getControls().size() );
-
+
Control control = modifyDNResponse.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
-
+
assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
}
-
+
+
/**
* Test parsing of a response without Result Code element
*/
public void testResponseWithoutResultCode()
{
- testParsingFail( ModifyDNResponseTest.class, "response_without_result_code.xml");
+ testParsingFail( ModifyDNResponseTest.class, "response_without_result_code.xml" );
}
-
+
+
/**
* Test parsing of a response with Result Code element but a not integer value
*/
public void testResponseWithResultCodeNotInteger()
{
- testParsingFail( ModifyDNResponseTest.class, "response_with_result_code_not_integer.xml");
+ testParsingFail( ModifyDNResponseTest.class, "response_with_result_code_not_integer.xml" );
}
-
+
+
/**
* Test parsing of a response with Result Code
*/
public void testResponseWithResultCode()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -198,24 +205,25 @@
}
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyDNResponse.getLdapResult();
-
+
assertEquals( 2, ldapResult.getResultCode() );
}
-
+
+
/**
* Test parsing of a response with Error Message
*/
public void testResponseWithErrorMessage()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -224,24 +232,26 @@
}
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyDNResponse.getLdapResult();
-
- assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult.getErrorMessage() );
+
+ assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
+ .getErrorMessage() );
}
-
+
+
/**
* Test parsing of a response with a Referral
*/
public void testResponseWith1Referral()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -250,37 +260,38 @@
}
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyDNResponse.getLdapResult();
-
+
List referrals = ldapResult.getReferrals();
-
+
assertEquals( 1, referrals.size() );
-
+
Object referral = referrals.get( 0 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
- }
- catch (NamingException e)
+ assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+ }
+ catch ( NamingException e )
{
- fail();
- }
+ fail();
+ }
}
-
+
+
/**
* Test parsing of a response with 2 Referral elements
*/
public void testResponseWith2Referrals()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -289,48 +300,50 @@
}
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyDNResponse.getLdapResult();
-
+
List referrals = ldapResult.getReferrals();
-
+
assertEquals( 2, referrals.size() );
-
+
Object referral = referrals.get( 0 );
-
- try
+
+ try
+ {
+ assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+ }
+ catch ( NamingException e )
{
- assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
- }
- catch (NamingException e)
- {
- fail();
- }
-
+ fail();
+ }
+
Object referral2 = referrals.get( 1 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apple.com/" ).toString(), referral2.toString() );
- }
- catch (NamingException e)
+ assertEquals( new LdapURL( "ldap://www.apple.com/" ).toString(), referral2.toString() );
+ }
+ catch ( NamingException e )
{
- fail();
- }
+ fail();
+ }
}
-
+
+
/**
* Test parsing of a response with a Referral and an Error Message
*/
public void testResponseWith1ReferralAndAnErrorMessage()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNResponseTest.class.getResource(
+ "response_with_1_referral_and_error_message.xml" ).getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -339,37 +352,39 @@
}
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyDNResponse.getLdapResult();
-
+
List referrals = ldapResult.getReferrals();
-
+
assertEquals( 1, referrals.size() );
-
+
Object referral = referrals.get( 0 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
- }
- catch (NamingException e)
+ assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+ }
+ catch ( NamingException e )
{
- fail();
- }
+ fail();
+ }
}
-
+
+
/**
* Test parsing of a response with MatchedDN attribute
*/
public void testResponseWithMatchedDNAttribute()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyDNResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -378,25 +393,27 @@
}
ModifyDNResponse modifyDNResponse = ( ModifyDNResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyDNResponse.getLdapResult();
-
+
assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", ldapResult.getMatchedDN() );
}
-
+
+
/**
* Test parsing of a response with wrong matched DN
*/
public void testResponseWithWrongMatchedDN()
{
- testParsingFail( ModifyDNResponseTest.class, "response_with_wrong_matchedDN_attribute.xml");
+ testParsingFail( ModifyDNResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
}
+
/**
* Test parsing of a response with wrong Descr attribute
*/
public void testResponseWithWrongDescr()
{
- testParsingFail( ModifyDNResponseTest.class, "response_with_wrong_descr.xml");
+ testParsingFail( ModifyDNResponseTest.class, "response_with_wrong_descr.xml" );
}
}
Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyRequest/ModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyRequest/ModifyRequestTest.java?view=diff&rev=483066&r1=483065&r2=483066
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyRequest/ModifyRequestTest.java (original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyRequest/ModifyRequestTest.java Wed Dec 6 05:17:42 2006
@@ -20,6 +20,7 @@
package org.apache.directory.ldapstudio.dsmlv2.modifyRequest;
+
import java.util.ArrayList;
import javax.naming.NamingException;
@@ -33,6 +34,7 @@
import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
import org.apache.directory.shared.ldap.util.StringTools;
+
/**
* Tests for the Modify Request parsing
*/
@@ -47,21 +49,22 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( 456, modifyRequest.getMessageId() );
}
-
+
/**
* Test parsing of a request with a (optional) Control element
@@ -72,29 +75,63 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( 1, modifyRequest.getControls().size() );
-
+
Control control = modifyRequest.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
-
+
assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
+
+
+ /**
+ * Test parsing of a request with a (optional) Control element with empty value
+ */
+ public void testRequestWith1ControlEmptyValue()
+ {
+ Dsmlv2Parser parser = null;
+ try
+ {
+ parser = new Dsmlv2Parser();
+
+ parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ assertEquals( 1, modifyRequest.getControls().size() );
+
+ Control control = modifyRequest.getCurrentControl();
+
+ 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
@@ -105,29 +142,30 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( 2, modifyRequest.getControls().size() );
-
+
Control control = modifyRequest.getCurrentControl();
-
+
assertFalse( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
-
+
assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
+
+
/**
* Test parsing of a request with 3 (optional) Control elements without value
*/
@@ -137,29 +175,31 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_3_controls_without_value.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( 3, modifyRequest.getControls().size() );
-
+
Control control = modifyRequest.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
-
+
assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
}
-
+
+
/**
* Test parsing of a request without dn attribute
*/
@@ -167,7 +207,8 @@
{
testParsingFail( ModifyRequestTest.class, "request_without_dn_attribute.xml" );
}
-
+
+
/**
* Test parsing of a request with a Modification element
* @throws NamingException
@@ -178,33 +219,34 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_1_modification.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
-
+
assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
-
+
ArrayList modifications = modifyRequest.getModifications();
-
- assertEquals(1, modifications.size() );
-
+
+ assertEquals( 1, modifications.size() );
+
ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
-
+
Attribute attribute = modification.getAttribute();
-
+
assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ) );
}
-
+
+
/**
* Test parsing of a request with 2 Modification elements
* @throws NamingException
@@ -215,33 +257,34 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_2_modifications.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( LdapConstants.OPERATION_REPLACE, modifyRequest.getCurrentOperation() );
-
+
assertEquals( "sn", modifyRequest.getCurrentAttributeType() );
-
+
ArrayList modifications = modifyRequest.getModifications();
-
- assertEquals(2, modifications.size() );
-
+
+ assertEquals( 2, modifications.size() );
+
ModificationItem modification = ( ModificationItem ) modifications.get( 1 );
-
+
Attribute attribute = modification.getAttribute();
-
+
assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 0 ) );
}
-
+
+
/**
* Test parsing of a request without name attribute to the Modification element
*/
@@ -249,7 +292,8 @@
{
testParsingFail( ModifyRequestTest.class, "request_without_name_attribute.xml" );
}
-
+
+
/**
* Test parsing of a request without operation attribute to the Modification element
*/
@@ -257,7 +301,8 @@
{
testParsingFail( ModifyRequestTest.class, "request_without_operation_attribute.xml" );
}
-
+
+
/**
* Test parsing of a request with operation attribute to Add value
* @throws NamingException
@@ -268,21 +313,22 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_operation_add.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
}
-
+
+
/**
* Test parsing of a request with operation attribute to Delete value
* @throws NamingException
@@ -293,21 +339,22 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_operation_delete.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( LdapConstants.OPERATION_DELETE, modifyRequest.getCurrentOperation() );
}
+
/**
* Test parsing of a request with operation attribute to Replace value
* @throws NamingException
@@ -318,21 +365,22 @@
try
{
parser = new Dsmlv2Parser();
-
+
parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_operation_replace.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( LdapConstants.OPERATION_REPLACE, modifyRequest.getCurrentOperation() );
}
-
+
+
/**
* Test parsing of a request without operation attribute to the Modification element
*/
@@ -340,7 +388,8 @@
{
testParsingFail( ModifyRequestTest.class, "request_with_operation_error.xml" );
}
-
+
+
/**
* Test parsing of a request with a Modification element without Value element
* @throws NamingException
@@ -351,31 +400,33 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_modification_without_value.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_modification_without_value.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
-
+
assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
-
+
ArrayList modifications = modifyRequest.getModifications();
ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
-
+
Attribute attribute = modification.getAttribute();
-
+
assertEquals( 0, attribute.size() );
}
-
+
+
/**
* Test parsing of a request with a Modification element
* @throws NamingException
@@ -386,32 +437,73 @@
try
{
parser = new Dsmlv2Parser();
-
- parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_modification_with_2_values.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_modification_with_2_values.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
-
+
assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
-
+
assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
-
+
ArrayList modifications = modifyRequest.getModifications();
-
+
assertEquals( 1, modifications.size() );
-
+
ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
-
+
Attribute attribute = modification.getAttribute();
-
- assertEquals( 2, attribute.size() );
+
+ assertEquals( 2, attribute.size() );
assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ) );
assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 1 ) );
+ }
+
+
+ /**
+ * Test parsing of a request with a Modification element with an empty value
+ * @throws NamingException
+ */
+ public void testRequestWithModificationWithEmptyValue() throws NamingException
+ {
+ Dsmlv2Parser parser = null;
+ try
+ {
+ parser = new Dsmlv2Parser();
+
+ parser.setInputFile( ModifyRequestTest.class.getResource( "request_with_modification_with_empty_value.xml" )
+ .getFile() );
+
+ parser.parse();
+ }
+ catch ( Exception e )
+ {
+ fail( e.getMessage() );
+ }
+
+ ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
+
+ assertEquals( LdapConstants.OPERATION_ADD, modifyRequest.getCurrentOperation() );
+
+ assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
+
+ ArrayList modifications = modifyRequest.getModifications();
+
+ assertEquals( 1, modifications.size() );
+
+ ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+
+ Attribute attribute = modification.getAttribute();
+
+ assertEquals( 1, attribute.size() );
+ assertEquals( "", attribute.get( 0 ) );
}
}
Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyResponse/ModifyResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyResponse/ModifyResponseTest.java?view=diff&rev=483066&r1=483065&r2=483066
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyResponse/ModifyResponseTest.java (original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/test/java/org/apache/directory/ldapstudio/dsmlv2/modifyResponse/ModifyResponseTest.java Wed Dec 6 05:17:42 2006
@@ -20,6 +20,7 @@
package org.apache.directory.ldapstudio.dsmlv2.modifyResponse;
+
import java.util.List;
import javax.naming.NamingException;
@@ -33,13 +34,13 @@
import com.sun.jndi.ldap.LdapURL;
+
/**
* Tests for the Modify Response parsing
*/
public class ModifyResponseTest extends AbstractResponseTest
{
-
-
+
/**
* Test parsing of a Response with the (optional) requestID attribute
*/
@@ -49,34 +50,35 @@
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 456, modifyResponse.getMessageId() );
}
-
+
/**
* Test parsing of a response with a (optional) Control element
*/
public void testResponseWith1Control()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -85,63 +87,65 @@
}
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 1, modifyResponse.getControls().size() );
-
+
Control control = modifyResponse.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
-
+
assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
+
/**
* Test parsing of a response with 2 (optional) Control elements
*/
public void testResponseWith2Controls()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
-
+
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 2, modifyResponse.getControls().size() );
-
+
Control control = modifyResponse.getCurrentControl();
-
+
assertFalse( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
-
+
assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
}
-
+
+
/**
* Test parsing of a response with 3 (optional) Control elements without value
*/
public void testResponseWith3ControlsWithoutValue()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_3_controls_without_value.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -150,46 +154,49 @@
}
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
assertEquals( 3, modifyResponse.getControls().size() );
-
+
Control control = modifyResponse.getCurrentControl();
-
+
assertTrue( control.getCriticality() );
-
+
assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
-
+
assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
}
-
+
+
/**
* Test parsing of a response without Result Code element
*/
public void testResponseWithoutResultCode()
{
- testParsingFail( ModifyResponseTest.class, "response_without_result_code.xml");
+ testParsingFail( ModifyResponseTest.class, "response_without_result_code.xml" );
}
-
+
+
/**
* Test parsing of a response with Result Code element but a not integer value
*/
public void testResponseWithResultCodeNotInteger()
{
- testParsingFail( ModifyResponseTest.class, "response_with_result_code_not_integer.xml");
+ testParsingFail( ModifyResponseTest.class, "response_with_result_code_not_integer.xml" );
}
-
+
+
/**
* Test parsing of a response with Result Code
*/
public void testResponseWithResultCode()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -198,24 +205,25 @@
}
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyResponse.getLdapResult();
-
+
assertEquals( 2, ldapResult.getResultCode() );
}
-
+
+
/**
* Test parsing of a response with Error Message
*/
public void testResponseWithErrorMessage()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -224,24 +232,26 @@
}
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyResponse.getLdapResult();
-
- assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult.getErrorMessage() );
+
+ assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
+ .getErrorMessage() );
}
-
+
+
/**
* Test parsing of a response with a Referral
*/
public void testResponseWith1Referral()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -250,37 +260,38 @@
}
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyResponse.getLdapResult();
-
+
List referrals = ldapResult.getReferrals();
-
+
assertEquals( 1, referrals.size() );
-
+
Object referral = referrals.get( 0 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
- }
- catch (NamingException e)
+ assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+ }
+ catch ( NamingException e )
{
- fail();
- }
+ fail();
+ }
}
-
+
+
/**
* Test parsing of a response with 2 Referral elements
*/
public void testResponseWith2Referrals()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
+
parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
-
+
parser.parse();
}
catch ( Exception e )
@@ -289,48 +300,50 @@
}
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyResponse.getLdapResult();
-
+
List referrals = ldapResult.getReferrals();
-
+
assertEquals( 2, referrals.size() );
-
+
Object referral = referrals.get( 0 );
-
- try
+
+ try
+ {
+ assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+ }
+ catch ( NamingException e )
{
- assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
- }
- catch (NamingException e)
- {
- fail();
- }
-
+ fail();
+ }
+
Object referral2 = referrals.get( 1 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apple.com/" ).toString(), referral2.toString() );
- }
- catch (NamingException e)
+ assertEquals( new LdapURL( "ldap://www.apple.com/" ).toString(), referral2.toString() );
+ }
+ catch ( NamingException e )
{
- fail();
- }
+ fail();
+ }
}
-
+
+
/**
* Test parsing of a response with a Referral and an Error Message
*/
public void testResponseWith1ReferralAndAnErrorMessage()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyResponseTest.class
+ .getResource( "response_with_1_referral_and_error_message.xml" ).getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -339,37 +352,39 @@
}
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyResponse.getLdapResult();
-
+
List referrals = ldapResult.getReferrals();
-
+
assertEquals( 1, referrals.size() );
-
+
Object referral = referrals.get( 0 );
-
- try
+
+ try
{
- assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
- }
- catch (NamingException e)
+ assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+ }
+ catch ( NamingException e )
{
- fail();
- }
+ fail();
+ }
}
-
+
+
/**
* Test parsing of a response with MatchedDN attribute
*/
public void testResponseWithMatchedDNAttribute()
{
- Dsmlv2ResponseParser parser = null;
+ Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser();
-
- parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).getFile() );
-
+
+ parser.setInputFile( ModifyResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" )
+ .getFile() );
+
parser.parse();
}
catch ( Exception e )
@@ -378,25 +393,27 @@
}
ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse();
-
+
LdapResult ldapResult = modifyResponse.getLdapResult();
-
+
assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", ldapResult.getMatchedDN() );
}
-
+
+
/**
* Test parsing of a response with wrong matched DN
*/
public void testResponseWithWrongMatchedDN()
{
- testParsingFail( ModifyResponseTest.class, "response_with_wrong_matchedDN_attribute.xml");
+ testParsingFail( ModifyResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
}
-
+
+
/**
* Test parsing of a response with wrong Descr attribute
*/
public void testResponseWithWrongDescr()
{
- testParsingFail( ModifyResponseTest.class, "response_with_wrong_descr.xml");
+ testParsingFail( ModifyResponseTest.class, "response_with_wrong_descr.xml" );
}
}