Test - PCEPDispatcherImpl : customizeBootstrap method 72/22872/1
authorIveta Halanova <iveta.halanova@pantheon.sk>
Wed, 17 Jun 2015 12:30:24 +0000 (14:30 +0200)
committerIveta Halanova <iveta.halanova@pantheon.sk>
Thu, 18 Jun 2015 10:58:51 +0000 (10:58 +0000)
Change-Id: Ifc2dab2ca522f53de81c31ffe0c3464ab065cef1
Signed-off-by: Iveta Halanova <iveta.halanova@pantheon.sk>
(cherry picked from commit f884277347f0dab0ee7cf390969ca9695100de6f)

pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java

index 6c4d4e8c2acd8cafcc7389ab576262847171ebfe..e917bc7b234085e22e4174bd5260c4b5bd026a8b 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.protocol.pcep.impl;
 
 import com.google.common.base.Preconditions;
+import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
@@ -18,11 +19,15 @@ import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
 import java.net.InetSocketAddress;
+import java.nio.channels.Channel;
 import java.util.concurrent.ExecutionException;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
 import org.opendaylight.protocol.framework.AbstractDispatcher;
 import org.opendaylight.protocol.framework.NeverReconnectStrategy;
 import org.opendaylight.protocol.framework.ProtocolSession;
@@ -33,6 +38,11 @@ import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
+import org.opendaylight.tcpmd5.api.KeyAccess;
+import org.opendaylight.tcpmd5.api.KeyAccessFactory;
+import org.opendaylight.tcpmd5.api.KeyMapping;
+import org.opendaylight.tcpmd5.netty.MD5NioServerSocketChannelFactory;
+import org.opendaylight.tcpmd5.netty.MD5NioSocketChannelFactory;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
@@ -46,11 +56,20 @@ public class PCEPDispatcherImplTest {
     private static final short KEEP_ALIVE = 30;
 
     private PCEPDispatcherImpl dispatcher;
+    private PCEPDispatcherImpl dispatcher2;
+    private PCEPDispatcherImpl disp2Spy;
+    private MD5NioServerSocketChannelFactory scf;
+    private MD5NioSocketChannelFactory cf;
+
+    @Mock private KeyAccessFactory kaf;
+    @Mock private Channel mockChannel;
+    @Mock private KeyAccess mockKeyAccess;
 
     private PCCMock<Message, PCEPSessionImpl, PCEPSessionListener> pccMock;
 
     @Before
     public void setUp() {
+        MockitoAnnotations.initMocks(this);
         final Open open = new OpenBuilder().setSessionId((short) 0).setDeadTimer(DEAD_TIMER).setKeepalive(KEEP_ALIVE)
                 .build();
         final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
@@ -58,6 +77,14 @@ public class PCEPDispatcherImplTest {
                 .getMessageHandlerRegistry();
         this.dispatcher = new PCEPDispatcherImpl(msgReg, new DefaultPCEPSessionNegotiatorFactory(open, 0),
                 eventLoopGroup, eventLoopGroup);
+
+        Mockito.doReturn("mockChannel").when(this.mockChannel).toString();
+        Mockito.doReturn(this.mockKeyAccess).when(this.kaf).getKeyAccess(Mockito.any(Channel.class));
+        this.scf = new MD5NioServerSocketChannelFactory(this.kaf);
+        this.cf = new MD5NioSocketChannelFactory(this.kaf);
+        this.dispatcher2 = new PCEPDispatcherImpl(msgReg, new DefaultPCEPSessionNegotiatorFactory(open, 0), eventLoopGroup, eventLoopGroup, this.cf, this.scf);
+        this.disp2Spy = Mockito.spy(this.dispatcher2);
+
         this.pccMock = new PCCMock<>(new DefaultPCEPSessionNegotiatorFactory(open, 0),
                 new PCEPHandlerFactory(msgReg), new DefaultPromise<PCEPSessionImpl>(
                         GlobalEventExecutor.INSTANCE));
@@ -132,7 +159,7 @@ public class PCEPDispatcherImplTest {
                         }
                     }).get();
             Assert.fail();
-        } catch(ExecutionException e) {
+        } catch(final ExecutionException e) {
             Assert.assertTrue(e.getMessage().contains("A conflicting session for address"));
         } finally {
             session1.close();
@@ -178,6 +205,22 @@ public class PCEPDispatcherImplTest {
         session2.close();
     }
 
+    @Test
+    public void testCustomizeBootstrap() {
+        final KeyMapping keys = new KeyMapping();
+        keys.put(this.CLIENT1_ADDRESS.getAddress(), new String("CLIENT1_ADDRESS").getBytes() );
+        keys.put(this.CLIENT2_ADDRESS.getAddress(), new String("CLIENT2_ADDRESS").getBytes() );
+
+        final ChannelFuture futureChannel = this.disp2Spy.createServer(new InetSocketAddress("0.0.0.0", PORT), keys,
+            new SessionListenerFactory<PCEPSessionListener>() {
+                @Override
+                public PCEPSessionListener getSessionListener() {
+                    return new SimpleSessionListener();
+                }
+            });
+        Mockito.verify(this.disp2Spy).customizeBootstrap(Mockito.any(ServerBootstrap.class));
+    }
+
     @After
     public void tearDown() {
         this.dispatcher.close();
@@ -210,4 +253,4 @@ public class PCEPDispatcherImplTest {
         }
     }
 
-}
+}
\ No newline at end of file