directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r1037350 - /directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
Date Sat, 20 Nov 2010 22:59:10 GMT
Author: felixk
Date: Sat Nov 20 22:59:10 2010
New Revision: 1037350

URL: http://svn.apache.org/viewvc?rev=1037350&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/AbstractKerberosFlagsTest.java

Modified: directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java?rev=1037350&r1=1037349&r2=1037350&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
Sat Nov 20 22:59:10 2010
@@ -20,11 +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.junit.Before;
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
 
 /**
@@ -32,29 +35,88 @@ import org.junit.Test;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
 public class AbstractKerberosFlagsTest
 {
+    @Test
+    public void testClearFlag() throws Exception
+    {
+        // Flags 1, 2, 4, 8 set
+        AbstractKerberosFlags akf = new AbstractKerberosFlags(
+            getBytes( ( int ) ( Math.pow( 2, TicketFlag.FORWARDABLE.getOrdinal() )
+                + Math.pow( 2, TicketFlag.FORWARDED.getOrdinal() ) + Math.pow( 2, TicketFlag.PROXY.getOrdinal()
) + Math
+                .pow( 2, TicketFlag.RENEWABLE.getOrdinal() ) ) ) )
+        {
+            private static final long serialVersionUID = 1L;
+        };
 
-    AbstractKerberosFlags akf;
+        // unset flag 4
+        akf.clearFlag( TicketFlag.PROXY );
+        assertEquals(
+            "clear(KerberosFlag)",
+            ( int ) ( Math.pow( 2, TicketFlag.FORWARDABLE.getOrdinal() )
+                + Math.pow( 2, TicketFlag.FORWARDED.getOrdinal() ) + Math.pow( 2, TicketFlag.RENEWABLE.getOrdinal()
) ),
+            akf.getIntValue() );
+
+        // unset flag 2
+        akf.clearFlag( TicketFlag.FORWARDED.getOrdinal() );
+        assertEquals(
+            "clear(int)",
+            ( int ) ( Math.pow( 2, TicketFlag.FORWARDABLE.getOrdinal() ) + Math.pow( 2,
+                TicketFlag.RENEWABLE.getOrdinal() ) ), akf.getIntValue() );
+    }
 
 
-    @Before
-    public void setUp() throws Exception
+    @Test
+    public void testValue() throws Exception
     {
-        akf = new AbstractKerberosFlags()
+        // Flags 1, 2, 4, 8 set
+        AbstractKerberosFlags akfIntConstructor = new AbstractKerberosFlags( getBytes( (
int ) ( Math.pow( 2,
+            TicketFlag.FORWARDABLE.getOrdinal() )
+            + Math.pow( 2, TicketFlag.FORWARDED.getOrdinal() )
+            + Math.pow( 2, TicketFlag.PROXY.getOrdinal() ) + Math.pow( 2, TicketFlag.RENEWABLE.getOrdinal()
) ) ) )
+        {
+            private static final long serialVersionUID = 1L;
+        };
+
+        // No flags set
+        AbstractKerberosFlags akfEmptyConstructor = new AbstractKerberosFlags()
         {
             private static final long serialVersionUID = 1L;
         };
+
+        // intValue
+        assertEquals( "intValue", 0, akfEmptyConstructor.getIntValue() );
+        assertEquals(
+            "intValue",
+            ( int ) ( Math.pow( 2, TicketFlag.FORWARDABLE.getOrdinal() )
+                + Math.pow( 2, TicketFlag.FORWARDED.getOrdinal() ) + Math.pow( 2, TicketFlag.PROXY.getOrdinal()
) + Math
+                .pow( 2, TicketFlag.RENEWABLE.getOrdinal() ) ), akfIntConstructor.getIntValue()
);
+
+        // hexValue
+        // TODO The method getHexValue() is a bit confusing WRT its comment and naming and
what the method really
+        // does. Ever seen a 'toHex' method returning an 'int'?
+        //        assertEquals( "hexValue", Integer.toHexString( 0 ), Integer.toHexString(
akfEmptyConstructor.getHexValue() ) );
+        //        assertEquals( "hexValue", Integer.toHexString( ( int ) ( Math.pow( 2, TicketFlag.FORWARDABLE.getOrdinal()
)
+        //            + Math.pow( 2, TicketFlag.FORWARDED.getOrdinal() ) + Math.pow( 2, TicketFlag.PROXY.getOrdinal()
) + Math
+        //            .pow( 2, TicketFlag.RENEWABLE.getOrdinal() ) ) ), Integer.toHexString(
akfIntConstructor.getHexValue() ) );
     }
 
 
     @Test
-    public void testFlags()
+    public void testFlagGetterSetter() throws Exception
     {
-        // MAX_VALUE is not a real ticket flag and will cause an Out Of Bounds Exception,
+        AbstractKerberosFlags akf = new AbstractKerberosFlags()
+        {
+            private static final long serialVersionUID = 1L;
+        };
+
+        // MAX_VALUE is not a real ticket flag and will cause an IndexOutOfBoundsException,
         // so skip this
         TicketFlag[] ticketFlags = new TicketFlag[TicketFlag.values().length - 1];
         int i = 0;
+        int flagsValue = 0;
         for ( TicketFlag tf : TicketFlag.values() )
         {
             if ( !tf.equals( TicketFlag.MAX_VALUE ) )
@@ -71,6 +133,7 @@ public class AbstractKerberosFlagsTest
             if ( setFlag )
             {
                 akf.setFlag( ticketFlag.getOrdinal() );
+                flagsValue += Math.pow( 2, ticketFlag.getOrdinal() );
             }
             setFlag = !setFlag;
         }
@@ -81,13 +144,37 @@ public class AbstractKerberosFlagsTest
             // Only every 2nd ticket flag is set
             if ( setFlag )
             {
-                assertTrue( "TicketFlag: " + ticketFlag.toString(), akf.isFlagSet( ticketFlag
) );
+                assertTrue( "isFlagSet(TicketFlag): " + ticketFlag.toString(), akf.isFlagSet(
ticketFlag ) );
+                assertTrue( "isFlagSet(int): " + ticketFlag.toString(), akf.isFlagSet( ticketFlag.getOrdinal()
) );
+                assertTrue( "isFlagSet(int,int): " + ticketFlag.toString(),
+                    AbstractKerberosFlags.isFlagSet( flagsValue, ticketFlag.getOrdinal()
) );
             }
             else
             {
-                assertFalse( "TicketFlag: " + ticketFlag.toString(), akf.isFlagSet( ticketFlag
) );
+                assertFalse( "isFlagSet(TicketFlag): " + ticketFlag.toString(), akf.isFlagSet(
ticketFlag ) );
+                assertFalse( "isFlagSet(int): " + ticketFlag.toString(), akf.isFlagSet( ticketFlag.getOrdinal()
) );
+                assertFalse( "isFlagSet(int,int): " + ticketFlag.toString(),
+                    AbstractKerberosFlags.isFlagSet( flagsValue, ticketFlag.getOrdinal()
) );
             }
             setFlag = !setFlag;
         }
+
+    }
+
+
+    /**
+         * 
+         * 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