Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 10142 invoked from network); 30 Sep 2007 19:04:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Sep 2007 19:04:21 -0000 Received: (qmail 77658 invoked by uid 500); 30 Sep 2007 19:04:11 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 77600 invoked by uid 500); 30 Sep 2007 19:04:11 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 77589 invoked by uid 99); 30 Sep 2007 19:04:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 30 Sep 2007 12:04:11 -0700 X-ASF-Spam-Status: No, hits=-98.8 required=10.0 tests=ALL_TRUSTED,DNS_FROM_DOB,RCVD_IN_DOB X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 30 Sep 2007 19:04:20 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9F20D1A9832; Sun, 30 Sep 2007 12:03:30 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r580770 - in /directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages: ./ NtpTimeStampTest.java Date: Sun, 30 Sep 2007 19:03:30 -0000 To: commits@directory.apache.org From: szoerner@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070930190330.9F20D1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: szoerner Date: Sun Sep 30 12:03:28 2007 New Revision: 580770 URL: http://svn.apache.org/viewvc?rev=580770&view=rev Log: Tests for class NtpTimeStamp added. Added: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/ directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java Added: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java?rev=580770&view=auto ============================================================================== --- directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java (added) +++ directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java Sun Sep 30 12:03:28 2007 @@ -0,0 +1,99 @@ +/* + * 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.messages; + + +import java.nio.ByteBuffer; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import junit.framework.TestCase; + + +/** + * Some unit tests for NtpTimeStamp. + * + * @author Apache Directory Project + * @version $Rev: $, $Date: $ + */ +public class NtpTimeStampTest extends TestCase +{ + private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( "MM/dd/yyyy HH:mm:ss" ); + + + /** + * equals() should return false for NtpTimeStamps of date objects with different values. + */ + public void testEqualsForDifferent() throws ParseException + { + + Date date = DATE_FORMAT.parse( "04/12/1971 11:23:14" ); + Date otherDate = DATE_FORMAT.parse( "12/24/2002 15:11:11" ); + + assertFalse( date == otherDate ); + assertFalse( date.equals( otherDate ) ); + + NtpTimeStamp timeStamp = new NtpTimeStamp( date ); + NtpTimeStamp otherTimeStamp = new NtpTimeStamp( otherDate ); + + assertFalse( "equals()", timeStamp.equals( otherTimeStamp ) ); + } + + + /** + * equals() should return true for NtpTimeStamps of date objects with same value. + */ + public void testEqualsForSame() throws ParseException + { + + Date date = DATE_FORMAT.parse( "05/30/1978 04:11:02" ); + Date sameDate = DATE_FORMAT.parse( "05/30/1978 04:11:02" ); + + assertFalse( date == sameDate ); + assertTrue( date.equals( sameDate ) ); + + NtpTimeStamp timeStamp = new NtpTimeStamp( date ); + NtpTimeStamp otherTimeStamp = new NtpTimeStamp( sameDate ); + + assertTrue( "equals()", timeStamp.equals( otherTimeStamp ) ); + + } + + + /** + * A roundtrip of wrapping a date into a NtpTimeStamp object A, writing it to a buffer, and creating + * another NtpTimeStamp B from this buffer, should lead to objects A and B with the same content. + */ + public void testWriteToBuffer() throws ParseException + { + Date date = DATE_FORMAT.parse( "04/12/1971 11:23:14" ); + + NtpTimeStamp timeStampA = new NtpTimeStamp( date ); + + ByteBuffer buffer = ByteBuffer.allocate( 1024 ); + timeStampA.writeTo( buffer ); + buffer.rewind(); + + NtpTimeStamp timeStampB = new NtpTimeStamp( buffer ); + + assertTrue( timeStampA.equals( timeStampB ) ); + } +}