directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r1037316 - /directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/TicketFlagsTest.java
Date Sat, 20 Nov 2010 19:58:31 GMT
Author: felixk
Date: Sat Nov 20 19:58:30 2010
New Revision: 1037316

URL: http://svn.apache.org/viewvc?rev=1037316&view=rev
Log:
Add some more tests

Modified:
    directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/TicketFlagsTest.java

Modified: directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/TicketFlagsTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/TicketFlagsTest.java?rev=1037316&r1=1037315&r2=1037316&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/TicketFlagsTest.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/TicketFlagsTest.java
Sat Nov 20 19:58:30 2010
@@ -20,10 +20,14 @@
 package org.apache.directory.server.kerberos.shared.messages.value.flags;
 
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
 
 /**
@@ -31,13 +35,14 @@ import org.junit.Test;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
 public class TicketFlagsTest
 {
 
     @Test
-    public void constructorsTest() throws Exception
+    public void testEmptyConstructor() throws Exception
     {
-        // Empty c'tor -> no flags set
         TicketFlags tf = new TicketFlags();
         for ( TicketFlag t : TicketFlag.values() )
         {
@@ -60,9 +65,38 @@ public class TicketFlagsTest
         assertFalse( tf.isRenewable() );
         assertFalse( tf.isReserved() );
         assertFalse( tf.isTransitedPolicyChecked() );
+    }
+
+
+    @Test
+    public void testGivenIntConstructor() throws Exception
+    {
+        // Flags 1, 2, 4, 8 set
+        TicketFlags tf = new TicketFlags( ( int ) ( Math.pow( 2, 1 ) + Math.pow( 2, 2 ) +
Math.pow( 2, 4 ) + Math.pow(
+            2, 8 ) ) );
+        assertFalse( tf.isReserved() ); // 0
+        assertTrue( tf.isForwardable() ); // 1
+        assertTrue( tf.isForwarded() ); // 2
+        assertFalse( tf.isProxiable() ); // 3
+        assertTrue( tf.isProxy() ); // 4
+        assertFalse( tf.isMayPosdate() ); // 5
+        assertFalse( tf.isPostdated() ); // 6
+        assertFalse( tf.isInvalid() ); // 7
+        assertTrue( tf.isRenewable() ); // 8
+        assertFalse( tf.isInitial() ); // 9
+        assertFalse( tf.isPreAuth() ); // 10
+        assertFalse( tf.isHwAuthent() ); // 11
+        assertFalse( tf.isTransitedPolicyChecked() ); // 12
+        assertFalse( tf.isOkAsDelegate() ); // 13
+    }
+
 
+    @Test
+    public void testGivenByteArrayConstructor() throws Exception
+    {
         // Flags 1, 2, 4, 8 set
-        tf = new TicketFlags( 278 );
+        TicketFlags tf = new TicketFlags(
+            getBytes( ( int ) ( Math.pow( 2, 1 ) + Math.pow( 2, 2 ) + Math.pow( 2, 4 ) +
Math.pow( 2, 8 ) ) ) );
         assertFalse( tf.isReserved() ); // 0
         assertTrue( tf.isForwardable() ); // 1
         assertTrue( tf.isForwarded() ); // 2
@@ -77,6 +111,79 @@ public class TicketFlagsTest
         assertFalse( tf.isHwAuthent() ); // 11
         assertFalse( tf.isTransitedPolicyChecked() ); // 12
         assertFalse( tf.isOkAsDelegate() ); // 13
+
+    }
+
+
+    @Test
+    public void testSetFlag() throws Exception
+    {
+        TicketFlags tf = new TicketFlags();
+        for ( TicketFlag t : TicketFlag.values() )
+        {
+            if ( !t.equals( TicketFlags.MAX_SIZE ) )
+            {
+
+                tf.setFlag( t );
+            }
+        }
+        assertTrue( tf.isReserved() ); // 0
+        assertTrue( tf.isForwardable() ); // 1
+        assertTrue( tf.isForwarded() ); // 2
+        assertTrue( tf.isProxiable() ); // 3
+        assertTrue( tf.isProxy() ); // 4
+        assertTrue( tf.isMayPosdate() ); // 5
+        assertTrue( tf.isPostdated() ); // 6
+        assertTrue( tf.isInvalid() ); // 7
+        assertTrue( tf.isRenewable() ); // 8
+        assertTrue( tf.isInitial() ); // 9
+        assertTrue( tf.isPreAuth() ); // 10
+        assertTrue( tf.isHwAuthent() ); // 11
+        assertTrue( tf.isTransitedPolicyChecked() ); // 12
+        assertTrue( tf.isOkAsDelegate() ); // 13
+    }
+
+
+    @Test
+    public void testNoFlagsToString() throws Exception
+    {
+        TicketFlags tf = new TicketFlags();
+        assertEquals( "toString()", "", tf.toString() );
     }
 
+
+    @Test
+    public void testAllFlagsToString() throws Exception
+    {
+        int i = 0;
+        for ( TicketFlag t : TicketFlag.values() )
+        {
+            if ( !t.equals( TicketFlags.MAX_SIZE ) )
+            {
+                i += Math.pow( 2, t.getOrdinal() );
+            }
+        }
+
+        TicketFlags tf = new TicketFlags( i );
+        assertEquals( "toString()", "RESERVED(0) FORWARDABLE(1) FORWARDED(2) PROXIABLE(3)
PROXY(4) "
+            + "MAY_POSTDATE(5) POSTDATED(6) INVALID(7) RENEWABLE(8) INITIAL(9) PRE_AUTHENT(10)
"
+            + "HW_AUTHENT(11) TRANSITED_POLICY_CHECKED(12) OK_AS_DELEGATE(13)", tf.toString()
);
+    }
+
+
+    /**
+     * 
+     * Get the byte array representation of an int
+     *
+     * @param flags The flags as int
+     * @return The Flags as byte array
+     */
+    private byte[] getBytes( int flags )
+    {
+        return new byte[]
+            {
+                ( byte ) ( 0 ), // unused bits
+                ( byte ) ( flags >>> 24 ), ( byte ) ( ( flags >> 16 ) &
0x00ff ), ( byte ) ( ( flags >> 8 ) & 0x00ff ),
+                ( byte ) ( flags & 0x00ff ) };
+    }
 }



Mime
View raw message