a9754654d5a7a4e1ee1e2588fb3a127bcc677d61
[controller.git] / opendaylight / netconf / netconf-client / src / test / java / org / opendaylight / controller / netconf / client / NetconfReconnectingClientConfigurationTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.netconf.client;
10
11 import com.google.common.base.Optional;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.mockito.Mockito;
15 import org.opendaylight.controller.netconf.client.NetconfClientSessionListener;
16 import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener;
17 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
18 import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration;
19 import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder;
20 import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
21 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
22 import org.opendaylight.protocol.framework.ReconnectStrategy;
23 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
24
25 import java.net.InetSocketAddress;
26
27 public class NetconfReconnectingClientConfigurationTest {
28     @Test
29     public void testNetconfReconnectingClientConfiguration() throws Exception {
30         Long timeout = 200L;
31         NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
32         NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
33         InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
34         ReconnectStrategyFactory strategy = Mockito.mock(ReconnectStrategyFactory.class);
35         AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
36         ReconnectStrategy reconnect = Mockito.mock(ReconnectStrategy.class);
37
38         NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().
39                 withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).
40                 withAddress(address).
41                 withConnectionTimeoutMillis(timeout).
42                 withReconnectStrategy(reconnect).
43                 withAdditionalHeader(header).
44                 withSessionListener(listener).
45                 withConnectStrategyFactory(strategy).
46                 withAuthHandler(handler).build();
47
48         Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
49         Assert.assertEquals(Optional.fromNullable(header), cfg.getAdditionalHeader());
50         Assert.assertEquals(listener, cfg.getSessionListener());
51         Assert.assertEquals(handler, cfg.getAuthHandler());
52         Assert.assertEquals(strategy, cfg.getConnectStrategyFactory());
53         Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol());
54         Assert.assertEquals(address, cfg.getAddress());
55         Assert.assertEquals(reconnect, cfg.getReconnectStrategy());
56     }
57 }