directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r547542 - in /directory/apacheds/trunk/protocol-ntp/src/test: java/org/apache/directory/server/ntp/ resources/org/
Date Fri, 15 Jun 2007 06:15:12 GMT
Author: erodriguez
Date: Thu Jun 14 23:15:11 2007
New Revision: 547542

URL: http://svn.apache.org/viewvc?view=rev&rev=547542
Log:
Test case clean-up in protocol-ntp:
o  Converted PDU files to byte[] in test cases.
o  Added javadocs.

Removed:
    directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/AbstractNtpTestCase.java
    directory/apacheds/trunk/protocol-ntp/src/test/resources/org/
Modified:
    directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageDecoderTest.java
    directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageEncoderTest.java

Modified: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageDecoderTest.java?view=diff&rev=547542&r1=547541&r2=547542
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageDecoderTest.java
(original)
+++ directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageDecoderTest.java
Thu Jun 14 23:15:11 2007
@@ -21,39 +21,85 @@
 
 
 import java.nio.ByteBuffer;
+
+import junit.framework.TestCase;
+
 import org.apache.directory.server.ntp.io.NtpMessageDecoder;
 import org.apache.directory.server.ntp.messages.NtpMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class NtpMessageDecoderTest extends AbstractNtpTestCase
+public class NtpMessageDecoderTest extends TestCase
 {
-    private ByteBuffer requestByteBuffer;
-
-
-    public NtpMessageDecoderTest()
-    {
-        super( NtpMessageDecoderTest.class );
-    }
-
+    /** the log for this class */
+    private static final Logger log = LoggerFactory.getLogger( NtpMessageDecoderTest.class
);
 
+    private static byte[] clientRequest = new byte[]
+        { ( byte ) 0xe3, ( byte ) 0x00, ( byte ) 0x06, ( byte ) 0xee, ( byte ) 0x00, ( byte
) 0x00, ( byte ) 0x00,
+            ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, (
byte ) 0x49, ( byte ) 0x4e,
+            ( byte ) 0x49, ( byte ) 0x54, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, (
byte ) 0x00, ( byte ) 0x00,
+            ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, (
byte ) 0x00, ( byte ) 0x00,
+            ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, (
byte ) 0x00, ( byte ) 0x00,
+            ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, (
byte ) 0xc5, ( byte ) 0x0f,
+            ( byte ) 0x41, ( byte ) 0x5a, ( byte ) 0xbf, ( byte ) 0xba, ( byte ) 0xdc, (
byte ) 0x09 };
+
+    private static byte[] serverResponse = new byte[]
+        { ( byte ) 0x24, ( byte ) 0x01, ( byte ) 0x06, ( byte ) 0xf0, ( byte ) 0x00, ( byte
) 0x00, ( byte ) 0x00,
+            ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x1b, (
byte ) 0x43, ( byte ) 0x44,
+            ( byte ) 0x4d, ( byte ) 0x41, ( byte ) 0xc5, ( byte ) 0x0f, ( byte ) 0x41, (
byte ) 0x51, ( byte ) 0xba,
+            ( byte ) 0x35, ( byte ) 0x2e, ( byte ) 0xb5, ( byte ) 0xc5, ( byte ) 0x0f, (
byte ) 0x41, ( byte ) 0x5a,
+            ( byte ) 0xbf, ( byte ) 0xba, ( byte ) 0xdc, ( byte ) 0x09, ( byte ) 0xc5, (
byte ) 0x0f, ( byte ) 0x41,
+            ( byte ) 0x5a, ( byte ) 0xc5, ( byte ) 0xeb, ( byte ) 0xa6, ( byte ) 0xac, (
byte ) 0xc5, ( byte ) 0x0f,
+            ( byte ) 0x41, ( byte ) 0x5a, ( byte ) 0xc6, ( byte ) 0x48, ( byte ) 0xd7, (
byte ) 0xe0 };
+
+
+    /**
+     * Tests the parsing of a client request.
+     *
+     * @throws Exception
+     */
     public void testParseClient() throws Exception
     {
-        requestByteBuffer = getByteBufferFromFile( "NTP-CLIENT-UDP.pdu" );
+        ByteBuffer buffer = ByteBuffer.wrap( clientRequest );
         NtpMessageDecoder decoder = new NtpMessageDecoder();
-        NtpMessage request = decoder.decode( requestByteBuffer );
+        NtpMessage request = decoder.decode( buffer );
         print( request );
     }
 
 
+    /**
+     * Tests the parsing of a server response.
+     *
+     * @throws Exception
+     */
     public void testParseServer() throws Exception
     {
-        requestByteBuffer = getByteBufferFromFile( "NTP-SERVER-UDP.pdu" );
+        ByteBuffer buffer = ByteBuffer.wrap( serverResponse );
         NtpMessageDecoder decoder = new NtpMessageDecoder();
-        NtpMessage request = decoder.decode( requestByteBuffer );
+        NtpMessage request = decoder.decode( buffer );
         print( request );
+    }
+
+
+    protected void print( NtpMessage request )
+    {
+        log.debug( String.valueOf( request.getLeapIndicator() ) );
+        log.debug( String.valueOf( request.getVersionNumber() ) );
+        log.debug( String.valueOf( request.getMode() ) );
+        log.debug( String.valueOf( request.getStratum() ) );
+        log.debug( String.valueOf( request.getPollInterval() ) );
+        log.debug( String.valueOf( request.getPrecision() ) );
+        log.debug( String.valueOf( request.getRootDelay() ) );
+        log.debug( String.valueOf( request.getRootDispersion() ) );
+        log.debug( String.valueOf( request.getReferenceIdentifier() ) );
+        log.debug( String.valueOf( request.getReferenceTimestamp() ) );
+        log.debug( String.valueOf( request.getOriginateTimestamp() ) );
+        log.debug( String.valueOf( request.getReceiveTimestamp() ) );
+        log.debug( String.valueOf( request.getTransmitTimestamp() ) );
     }
 }

Modified: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageEncoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageEncoderTest.java?view=diff&rev=547542&r1=547541&r2=547542
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageEncoderTest.java
(original)
+++ directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/NtpMessageEncoderTest.java
Thu Jun 14 23:15:11 2007
@@ -22,6 +22,8 @@
 
 import java.nio.ByteBuffer;
 
+import junit.framework.TestCase;
+
 import org.apache.directory.server.ntp.io.NtpMessageDecoder;
 import org.apache.directory.server.ntp.io.NtpMessageEncoder;
 import org.apache.directory.server.ntp.messages.LeapIndicatorType;
@@ -31,20 +33,25 @@
 import org.apache.directory.server.ntp.messages.NtpTimeStamp;
 import org.apache.directory.server.ntp.messages.ReferenceIdentifier;
 import org.apache.directory.server.ntp.messages.StratumType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class NtpMessageEncoderTest extends AbstractNtpTestCase
+public class NtpMessageEncoderTest extends TestCase
 {
-    public NtpMessageEncoderTest()
-    {
-        super( NtpMessageEncoderTest.class );
-    }
+    /** the log for this class */
+    private static final Logger log = LoggerFactory.getLogger( NtpMessageEncoderTest.class
);
 
 
+    /**
+     * Tests the encoding of an NTP message.
+     *
+     * @throws Exception
+     */
     public void testEncodeMessage() throws Exception
     {
         NtpMessageModifier modifier = new NtpMessageModifier();
@@ -78,5 +85,23 @@
         NtpMessage reply = decoder.decode( replyByteBuffer );
 
         print( reply );
+    }
+
+
+    protected void print( NtpMessage request )
+    {
+        log.debug( String.valueOf( request.getLeapIndicator() ) );
+        log.debug( String.valueOf( request.getVersionNumber() ) );
+        log.debug( String.valueOf( request.getMode() ) );
+        log.debug( String.valueOf( request.getStratum() ) );
+        log.debug( String.valueOf( request.getPollInterval() ) );
+        log.debug( String.valueOf( request.getPrecision() ) );
+        log.debug( String.valueOf( request.getRootDelay() ) );
+        log.debug( String.valueOf( request.getRootDispersion() ) );
+        log.debug( String.valueOf( request.getReferenceIdentifier() ) );
+        log.debug( String.valueOf( request.getReferenceTimestamp() ) );
+        log.debug( String.valueOf( request.getOriginateTimestamp() ) );
+        log.debug( String.valueOf( request.getReceiveTimestamp() ) );
+        log.debug( String.valueOf( request.getTransmitTimestamp() ) );
     }
 }



Mime
View raw message