directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r690985 [2/2] - in /directory/apacheds/trunk: core/src/main/java/org/apache/directory/server/core/schema/ mitosis/src/main/java/org/apache/directory/mitosis/operation/ mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/code...
Date Mon, 01 Sep 2008 14:53:51 GMT
Modified: directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java?rev=690985&r1=690984&r2=690985&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java
(original)
+++ directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java
Mon Sep  1 07:53:50 2008
@@ -20,18 +20,30 @@
 package org.apache.directory.mitosis.service.protocol.codec;
 
 
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 import java.util.Queue;
 import java.util.concurrent.LinkedBlockingQueue;
 
 import junit.framework.Assert;
 
 import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
+import org.apache.directory.server.core.DefaultDirectoryService;
 import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceConfig;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.TransportType;
 import org.apache.mina.common.WriteFuture;
+import org.apache.mina.common.support.BaseIoSession;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.apache.mina.filter.codec.demux.MessageDecoder;
 import org.apache.mina.filter.codec.demux.MessageEncoder;
 import org.apache.mina.filter.codec.support.SimpleProtocolEncoderOutput;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 
@@ -42,6 +54,15 @@
     private final MessageDecoder decoder;
 
 
+    private static DefaultDirectoryService service;
+
+    @BeforeClass
+    public static void setUp()
+    {
+        service = new DefaultDirectoryService();
+    }
+    
+    
     protected AbstractMessageCodecTest( BaseMessage message, MessageEncoder encoder, MessageDecoder
decoder )
     {
         if ( message == null )
@@ -63,7 +84,8 @@
     }
 
 
-    @Test public void testMessageCodec() throws Exception
+    @Test 
+    public void testMessageCodec() throws Exception
     {
         SimpleProtocolEncoderOutput encoderOut = new SimpleProtocolEncoderOutput()
         {
@@ -73,7 +95,11 @@
             }
 
         };
-        encoder.encode( null, message, encoderOut );
+        
+        IoSession session = new  DummySession();
+        
+        session.setAttribute( "registries", service.getRegistries() );
+        encoder.encode( session, message, encoderOut );
         ByteBuffer buf = encoderOut.getBufferQueue().poll();
 
         buf.mark();
@@ -81,7 +107,7 @@
         buf.reset();
 
         ProtocolDecoderOutputImpl decoderOut = new ProtocolDecoderOutputImpl();
-        decoder.decode( null, buf, decoderOut );
+        decoder.decode( session, buf, decoderOut );
 
         Assert.assertTrue( compare( message, ( BaseMessage ) decoderOut.messages.poll() )
);
     }
@@ -107,4 +133,97 @@
             messages.add( message );
         }
     }
+
+
+    protected static class DummySession extends BaseIoSession
+    {
+        Object message;
+
+
+        @Override
+        public WriteFuture write( Object message )
+        {
+            this.message = message;
+
+            return super.write( message );
+        }
+
+
+        protected Object getMessage()
+        {
+            return message;
+        }
+
+
+        protected void updateTrafficMask()
+        {
+            // Do nothing.
+        }
+
+
+        public IoService getService()
+        {
+            return null;
+        }
+
+
+        public IoHandler getHandler()
+        {
+            return null;
+        }
+
+
+        public IoFilterChain getFilterChain()
+        {
+            return null;
+        }
+
+
+        public TransportType getTransportType()
+        {
+            return null;
+        }
+
+
+        public SocketAddress getRemoteAddress()
+        {
+            return new InetSocketAddress( 10088 );
+        }
+
+
+        public SocketAddress getLocalAddress()
+        {
+            return null;
+        }
+
+
+        public IoSessionConfig getConfig()
+        {
+            return null;
+        }
+
+
+        public int getScheduledWriteRequests()
+        {
+            return 0;
+        }
+
+
+        public SocketAddress getServiceAddress()
+        {
+            return null;
+        }
+
+
+        public IoServiceConfig getServiceConfig()
+        {
+            return null;
+        }
+
+
+        public int getScheduledWriteBytes()
+        {
+            return 0;
+        }
+    }
 }

Modified: directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java?rev=690985&r1=690984&r2=690985&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java
(original)
+++ directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java
Mon Sep  1 07:53:50 2008
@@ -57,17 +57,11 @@
 
     public LogEntryMessageCodecTest() throws InvalidNameException, NamingException
     {
-        // Initialize OIDs maps for normalization
-        /*Map<String, OidNormalizer> oids = new HashMap<String, OidNormalizer>();
-
-        oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
-        oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer()
) );
-        oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() )
);
-         */
         super(
             new LogEntryMessage( 
                 1234, 
                 new AddAttributeOperation( 
+                    service.getRegistries(),
                     new DefaultCSN( System.currentTimeMillis(),
                         "testReplica0", 1234 ), 
                     new LdapDN( "ou=system" ).normalize( oids ),

Modified: directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java?rev=690985&r1=690984&r2=690985&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java
(original)
+++ directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java
Mon Sep  1 07:53:50 2008
@@ -27,7 +27,6 @@
 
 public class LoginAckMessageCodecTest extends AbstractMessageCodecTest
 {
-
     public LoginAckMessageCodecTest()
     {
         super( new LoginAckMessage( 1234, 5678, "ReplicaABCD" ), new LoginAckMessageEncoder(),

Modified: directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java?rev=690985&r1=690984&r2=690985&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java
(original)
+++ directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java
Mon Sep  1 07:53:50 2008
@@ -42,7 +42,9 @@
 import org.apache.directory.server.core.entry.DefaultServerAttribute;
 import org.apache.directory.server.core.entry.DefaultServerEntry;
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
 import org.apache.directory.shared.ldap.schema.OidNormalizer;
 import org.apache.directory.mitosis.common.CSN;
@@ -192,35 +194,35 @@
         AttributeTypeRegistry atRegistry = service.getRegistries().getAttributeTypeRegistry();
 
         CSN csn = csnFactory.newInstance( REPLICA_ID );
-        CompositeOperation op1 = new CompositeOperation( csn );
+        CompositeOperation op1 = new CompositeOperation( service.getRegistries(), csn );
         LdapDN ouA =  new LdapDN( "ou=a" ).normalize( oids );
-        op1.add( new AddEntryOperation( csn, 
+        op1.add( new AddEntryOperation( service.getRegistries(), csn, 
             new DefaultServerEntry( service.getRegistries(), ouA ) ) );
         
-        op1.add( new AddAttributeOperation( csn, ouA, 
+        op1.add( new AddAttributeOperation( service.getRegistries(), csn, ouA, 
             new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
         
-        op1.add( new ReplaceAttributeOperation( csn, ouA, 
+        op1.add( new ReplaceAttributeOperation( service.getRegistries(), csn, ouA, 
             new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
         
-        op1.add( new DeleteAttributeOperation( csn, ouA, 
+        op1.add( new DeleteAttributeOperation( service.getRegistries(), csn, ouA, 
             new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
 
         store.putLog( op1 );
         testGetLogs( csn, op1 );
 
         csn = csnFactory.newInstance( OTHER_REPLICA_ID );
-        CompositeOperation op2 = new CompositeOperation( csn );
-        op2.add( new AddEntryOperation( csn, 
+        CompositeOperation op2 = new CompositeOperation( service.getRegistries(), csn );
+        op2.add( new AddEntryOperation( service.getRegistries(), csn, 
             new DefaultServerEntry( service.getRegistries(), ouA ) ) );
         
-        op2.add( new AddAttributeOperation( csn, ouA, 
+        op2.add( new AddAttributeOperation( service.getRegistries(), csn, ouA, 
             new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
         
-        op2.add( new ReplaceAttributeOperation( csn, ouA, 
+        op2.add( new ReplaceAttributeOperation( service.getRegistries(), csn, ouA, 
             new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
         
-        op2.add( new DeleteAttributeOperation( csn, ouA, 
+        op2.add( new DeleteAttributeOperation( service.getRegistries(), csn, ouA, 
             new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
 
         store.putLog( op2 );
@@ -281,7 +283,7 @@
 
         it = store.getLogs( new DefaultCSN( 0, REPLICA_ID, 0 ), false );
         it.next();
-        csn = it.getOperation().getCSN();
+        csn = it.getOperation( service.getRegistries() ).getCSN();
         it.close();
 
         Assert.assertEquals( 0, store.removeLogs( csn, false ) );
@@ -290,7 +292,7 @@
 
         it = store.getLogs( new DefaultCSN( 0, OTHER_REPLICA_ID, 0 ), false );
         Assert.assertTrue( it.next() );
-        csn = it.getOperation().getCSN();
+        csn = it.getOperation( service.getRegistries() ).getCSN();
         it.close();
 
         Assert.assertEquals( 0, store.removeLogs( csn, false ) );
@@ -307,10 +309,12 @@
         CSN csnB = new DefaultCSN( 1, REPLICA_ID, 0 );
         CSN csnC = new DefaultCSN( 0, OTHER_REPLICA_ID_2, 0 );
         CSN csnD = new DefaultCSN( 0, OTHER_REPLICA_ID_2, 1 );
-        store.putLog( new Operation( csnA ) );
-        store.putLog( new Operation( csnB ) );
-        store.putLog( new Operation( csnC ) );
-        store.putLog( new Operation( csnD ) );
+        AttributeType at = service.getRegistries().getAttributeTypeRegistry().lookup( "ou"
);
+        EntryAttribute attribute = new DefaultServerAttribute( at, "test" );
+        store.putLog( new AddAttributeOperation( service.getRegistries(), csnA, LdapDN.EMPTY_LDAPDN,
attribute ) );
+        store.putLog( new AddAttributeOperation( service.getRegistries(), csnB, LdapDN.EMPTY_LDAPDN,
attribute ) );
+        store.putLog( new AddAttributeOperation( service.getRegistries(), csnC, LdapDN.EMPTY_LDAPDN,
attribute ) );
+        store.putLog( new AddAttributeOperation( service.getRegistries(), csnD, LdapDN.EMPTY_LDAPDN,
attribute ) );
 
         Set<String> expectedKnownReplicaIds = new HashSet<String>();
         expectedKnownReplicaIds.add( REPLICA_ID );
@@ -368,7 +372,7 @@
             Operation expected = expectedIt.next();
             Assert.assertTrue( actualIt.next() );
 
-            Operation actual = actualIt.getOperation();
+            Operation actual = actualIt.getOperation( service.getRegistries() );
             Assert.assertEquals( expected.getCSN(), actual.getCSN() );
             assertEquals( expected, actual );
         }



Mime
View raw message