You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/01/30 13:30:19 UTC
svn commit: r373498 - in
/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations:
GracefulDisconnectTest.java GracefulShutdownTest.java
Author: elecharny
Date: Mon Jan 30 04:30:10 2006
New Revision: 373498
URL: http://svn.apache.org/viewcvs?rev=373498&view=rev
Log:
Added encoding tests
Modified:
directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java
directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulShutdownTest.java
Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java?rev=373498&r1=373497&r2=373498&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java (original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java Mon Jan 30 04:30:10 2006
@@ -112,12 +112,14 @@
public void testDecodeGracefulDisconnectTimeOffline() throws NamingException
{
Asn1Decoder decoder = new GracefulDisconnectDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x0b );
+ ByteBuffer bb = ByteBuffer.allocate( 0x05 );
bb.put( new byte[]
{
0x30, 0x03, // GracefulDisconnect ::= SEQUENCE {
0x02, 0x01, 0x01 // timeOffline INTEGER (0..720) DEFAULT 0,
} );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
bb.flip();
GracefulDisconnectContainer container = new GracefulDisconnectContainer();
@@ -136,6 +138,24 @@
assertEquals( 1, gracefulDisconnect.getTimeOffline() );
assertEquals( 0, gracefulDisconnect.getDelay() );
assertEquals( 0, gracefulDisconnect.getReplicatedContexts().size() );
+
+ // Check the length
+ assertEquals( 0x05, gracefulDisconnect.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulDisconnect.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
}
/**
@@ -144,12 +164,14 @@
public void testDecodeGracefulDisconnectDelay() throws NamingException
{
Asn1Decoder decoder = new GracefulDisconnectDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x0b );
+ ByteBuffer bb = ByteBuffer.allocate( 0x05 );
bb.put( new byte[]
{
0x30, 0x03, // GracefulDisconnect ::= SEQUENCE {
(byte)0x80, 0x01, 0x01 // delay INTEGER (0..86400) DEFAULT 0
} );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
bb.flip();
GracefulDisconnectContainer container = new GracefulDisconnectContainer();
@@ -168,6 +190,24 @@
assertEquals( 0, gracefulDisconnect.getTimeOffline() );
assertEquals( 1, gracefulDisconnect.getDelay() );
assertEquals( 0, gracefulDisconnect.getReplicatedContexts().size() );
+
+ // Check the length
+ assertEquals( 0x05, gracefulDisconnect.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulDisconnect.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
}
/**
@@ -251,6 +291,7 @@
'0', '4', ')'
// }
} );
+
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -298,11 +339,13 @@
public void testDecodeGracefulDisconnectEmpty() throws NamingException
{
Asn1Decoder decoder = new GracefulDisconnectDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x0b );
+ ByteBuffer bb = ByteBuffer.allocate( 0x02 );
bb.put( new byte[]
{
0x30, 0x00 // GracefulDisconnect ::= SEQUENCE {
} );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
bb.flip();
GracefulDisconnectContainer container = new GracefulDisconnectContainer();
@@ -321,6 +364,24 @@
assertEquals( 0, gracefulDisconnect.getTimeOffline() );
assertEquals( 0, gracefulDisconnect.getDelay() );
assertEquals( 0, gracefulDisconnect.getReplicatedContexts().size() );
+
+ // Check the length
+ assertEquals( 0x02, gracefulDisconnect.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulDisconnect.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
}
// Defensive tests
Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulShutdownTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulShutdownTest.java?rev=373498&r1=373497&r2=373498&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulShutdownTest.java (original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulShutdownTest.java Mon Jan 30 04:30:10 2006
@@ -21,8 +21,10 @@
import javax.naming.NamingException;
import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
import org.apache.asn1.ber.Asn1Decoder;
import org.apache.ldap.common.codec.LdapDecoder;
+import org.apache.ldap.common.util.StringTools;
import junit.framework.Assert;
import junit.framework.TestCase;
@@ -39,7 +41,7 @@
public void testDecodeGracefulShutdownSuccess() throws NamingException
{
Asn1Decoder decoder = new LdapDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x0b );
+ ByteBuffer bb = ByteBuffer.allocate( 0x08 );
bb.put( new byte[]
{
0x30, 0x06, // GracefulShutdown ::= SEQUENCE {
@@ -47,6 +49,8 @@
(byte)0x80, 0x01, 0x01 // delay INTEGER (0..86400) DEFAULT 0
// }
} );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
bb.flip();
GracefulShutdownContainer container = new GracefulShutdownContainer();
@@ -64,6 +68,24 @@
GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
assertEquals( 1, gracefulShutdown.getTimeOffline() );
assertEquals( 1, gracefulShutdown.getDelay() );
+
+ // Check the length
+ assertEquals( 0x08, gracefulShutdown.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulShutdown.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
}
/**
@@ -72,12 +94,14 @@
public void testDecodeGracefulShutdownTimeOffline() throws NamingException
{
Asn1Decoder decoder = new LdapDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x0b );
+ ByteBuffer bb = ByteBuffer.allocate( 0x05 );
bb.put( new byte[]
{
0x30, 0x03, // GracefulShutdown ::= SEQUENCE {
0x02, 0x01, 0x01 // timeOffline INTEGER (0..720) DEFAULT 0,
} );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
bb.flip();
GracefulShutdownContainer container = new GracefulShutdownContainer();
@@ -95,6 +119,24 @@
GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
assertEquals( 1, gracefulShutdown.getTimeOffline() );
assertEquals( 0, gracefulShutdown.getDelay() );
+
+ // Check the length
+ assertEquals( 0x05, gracefulShutdown.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulShutdown.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
}
/**
@@ -103,12 +145,14 @@
public void testDecodeGracefulShutdownDelay() throws NamingException
{
Asn1Decoder decoder = new LdapDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x0b );
+ ByteBuffer bb = ByteBuffer.allocate( 0x05 );
bb.put( new byte[]
{
0x30, 0x03, // GracefulShutdown ::= SEQUENCE {
(byte)0x80, 0x01, 0x01 // delay INTEGER (0..86400) DEFAULT 0
} );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
bb.flip();
GracefulShutdownContainer container = new GracefulShutdownContainer();
@@ -126,6 +170,24 @@
GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
assertEquals( 0, gracefulShutdown.getTimeOffline() );
assertEquals( 1, gracefulShutdown.getDelay() );
+
+ // Check the length
+ assertEquals( 0x05, gracefulShutdown.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulShutdown.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
}
/**
@@ -134,11 +196,13 @@
public void testDecodeGracefulShutdownEmpty() throws NamingException
{
Asn1Decoder decoder = new LdapDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x0b );
+ ByteBuffer bb = ByteBuffer.allocate( 0x02 );
bb.put( new byte[]
{
0x30, 0x00 // GracefulShutdown ::= SEQUENCE {
} );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
bb.flip();
GracefulShutdownContainer container = new GracefulShutdownContainer();
@@ -156,8 +220,179 @@
GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
assertEquals( 0, gracefulShutdown.getTimeOffline() );
assertEquals( 0, gracefulShutdown.getDelay() );
+
+ // Check the length
+ assertEquals( 0x02, gracefulShutdown.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulShutdown.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
}
+ /**
+ * Test the decoding of a GracefulShutdown with a delay above 128
+ */
+ public void testDecodeGracefulShutdownDelayHigh() throws NamingException
+ {
+ Asn1Decoder decoder = new LdapDecoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x06 );
+ bb.put( new byte[]
+ {
+ 0x30, 0x04, // GracefulShutdown ::= SEQUENCE {
+ (byte)0x80, 0x02, 0x01, (byte)0xF4 // delay INTEGER (0..86400) DEFAULT 0
+ } );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
+ bb.flip();
+
+ GracefulShutdownContainer container = new GracefulShutdownContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
+ assertEquals( 0, gracefulShutdown.getTimeOffline() );
+ assertEquals( 500, gracefulShutdown.getDelay() );
+
+ // Check the length
+ assertEquals( 0x06, gracefulShutdown.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulShutdown.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of a GracefulShutdown with a delay equals 32767
+ */
+ public void testDecodeGracefulShutdownDelay32767() throws NamingException
+ {
+ Asn1Decoder decoder = new LdapDecoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x06 );
+ bb.put( new byte[]
+ {
+ 0x30, 0x04, // GracefulShutdown ::= SEQUENCE {
+ (byte)0x80, 0x02, 0x7F, (byte)0xFF // delay INTEGER (0..86400) DEFAULT 0
+ } );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
+ bb.flip();
+
+ GracefulShutdownContainer container = new GracefulShutdownContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
+ assertEquals( 0, gracefulShutdown.getTimeOffline() );
+ assertEquals( 32767, gracefulShutdown.getDelay() );
+
+ // Check the length
+ assertEquals( 0x06, gracefulShutdown.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulShutdown.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of a GracefulShutdown with a delay above 32768
+ */
+ public void testDecodeGracefulShutdownDelay32768() throws NamingException
+ {
+ Asn1Decoder decoder = new LdapDecoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x07 );
+ bb.put( new byte[]
+ {
+ 0x30, 0x05, // GracefulShutdown ::= SEQUENCE {
+ (byte)0x80, 0x03, 0x00, (byte)0x80, (byte)0x00 // delay INTEGER (0..86400) DEFAULT 0
+ } );
+
+ String decodedPdu = StringTools.dumpBytes( bb.array() );
+ bb.flip();
+
+ GracefulShutdownContainer container = new GracefulShutdownContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
+ assertEquals( 0, gracefulShutdown.getTimeOffline() );
+ assertEquals( 32768, gracefulShutdown.getDelay() );
+
+ // Check the length
+ assertEquals( 0x07, gracefulShutdown.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulShutdown.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
// Defensive tests
/**
@@ -166,7 +401,7 @@
public void testDecodeGracefulShutdownTimeOfflineOffLimit() throws NamingException
{
Asn1Decoder decoder = new LdapDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x0b );
+ ByteBuffer bb = ByteBuffer.allocate( 0x06 );
bb.put( new byte[]
{
0x30, 0x04, // GracefulShutdown ::= SEQUENCE {