592cdad4c196bdc47fb24588fad630192da593fa
[controller.git] / opendaylight / netconf / netconf-client / src / test / java / org / opendaylight / controller / netconf / client / NetconfClientConfigurationTest.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.NetconfClientConfigurationBuilder;
19 import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
20 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
21 import org.opendaylight.protocol.framework.ReconnectStrategy;
22
23 import java.net.InetSocketAddress;
24
25 public class NetconfClientConfigurationTest {
26     @Test
27     public void testNetconfClientConfiguration() throws Exception {
28         Long timeout = 200L;
29         NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
30         NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
31         InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
32         ReconnectStrategy strategy = Mockito.mock(ReconnectStrategy.class);
33         AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
34         NetconfClientConfiguration cfg = NetconfClientConfigurationBuilder.create().
35                 withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).
36                 withAddress(address).
37                 withConnectionTimeoutMillis(timeout).
38                 withReconnectStrategy(strategy).
39                 withAdditionalHeader(header).
40                 withSessionListener(listener).
41                 withAuthHandler(handler).build();
42
43         Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
44         Assert.assertEquals(Optional.fromNullable(header), cfg.getAdditionalHeader());
45         Assert.assertEquals(listener, cfg.getSessionListener());
46         Assert.assertEquals(handler, cfg.getAuthHandler());
47         Assert.assertEquals(strategy, cfg.getReconnectStrategy());
48         Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol());
49         Assert.assertEquals(address, cfg.getAddress());
50     }
51 }