directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r580756 - in /directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp: NtpMessageDecoderTest.java NtpMessageEncoderTest.java io/NtpMessageDecoderTest.java io/NtpMessageEncoderTest.java
Date Sun, 30 Sep 2007 17:22:38 GMT
Author: szoerner
Date: Sun Sep 30 10:22:37 2007
New Revision: 580756

URL: http://svn.apache.org/viewvc?rev=580756&view=rev
Log:
Existing NTP tests moved to appropriate package

Added:
    directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageDecoderTest.java
    directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageEncoderTest.java
Removed:
    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

Added: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageDecoderTest.java?rev=580756&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageDecoderTest.java
(added)
+++ directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageDecoderTest.java
Sun Sep 30 10:22:37 2007
@@ -0,0 +1,104 @@
+/*
+ *  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.server.ntp.io;
+
+
+import java.nio.ByteBuffer;
+
+import junit.framework.TestCase;
+
+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: 547542 $, $Date: 2007-06-15 08:15:11 +0200 (Fr, 15 Jun 2007) $
+ */
+public class NtpMessageDecoderTest extends TestCase
+{
+    /** 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
+    {
+        ByteBuffer buffer = ByteBuffer.wrap( clientRequest );
+        NtpMessageDecoder decoder = new NtpMessageDecoder();
+        NtpMessage request = decoder.decode( buffer );
+        print( request );
+    }
+
+
+    /**
+     * Tests the parsing of a server response.
+     *
+     * @throws Exception
+     */
+    public void testParseServer() throws Exception
+    {
+        ByteBuffer buffer = ByteBuffer.wrap( serverResponse );
+        NtpMessageDecoder decoder = new NtpMessageDecoder();
+        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() ) );
+    }
+}

Added: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageEncoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageEncoderTest.java?rev=580756&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageEncoderTest.java
(added)
+++ directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/io/NtpMessageEncoderTest.java
Sun Sep 30 10:22:37 2007
@@ -0,0 +1,105 @@
+/*
+ *  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.server.ntp.io;
+
+
+import java.nio.ByteBuffer;
+
+import junit.framework.TestCase;
+
+import org.apache.directory.server.ntp.messages.LeapIndicatorType;
+import org.apache.directory.server.ntp.messages.ModeType;
+import org.apache.directory.server.ntp.messages.NtpMessage;
+import org.apache.directory.server.ntp.messages.NtpMessageModifier;
+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: 547542 $, $Date: 2007-06-15 08:15:11 +0200 (Fr, 15 Jun 2007) $
+ */
+public class NtpMessageEncoderTest extends TestCase
+{
+    /** 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();
+        modifier.setLeapIndicator( LeapIndicatorType.NO_WARNING );
+        modifier.setVersionNumber( 4 );
+        modifier.setMode( ModeType.SERVER );
+        modifier.setStratum( StratumType.PRIMARY_REFERENCE );
+        modifier.setPollInterval( ( byte ) 0x06 ); // 6
+        modifier.setPrecision( ( byte ) 0xFA ); // -6
+        modifier.setRootDelay( 0 );
+        modifier.setRootDispersion( 0 );
+        modifier.setReferenceIdentifier( ReferenceIdentifier.LOCL );
+
+        NtpTimeStamp now = new NtpTimeStamp();
+
+        modifier.setReferenceTimestamp( now );
+        modifier.setOriginateTimestamp( now );
+        modifier.setReceiveTimestamp( now );
+        modifier.setTransmitTimestamp( now );
+
+        NtpMessage message = modifier.getNtpMessage();
+
+        ByteBuffer replyByteBuffer = ByteBuffer.allocate( 1024 );
+
+        NtpMessageEncoder encoder = new NtpMessageEncoder();
+        encoder.encode( replyByteBuffer, message );
+
+        print( message );
+
+        NtpMessageDecoder decoder = new NtpMessageDecoder();
+        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