2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.netconf.client;
11 import com.google.common.base.Optional;
12 import java.net.InetSocketAddress;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
17 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
18 import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
19 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
20 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder;
21 import org.opendaylight.protocol.framework.ReconnectStrategy;
22 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
24 public class NetconfReconnectingClientConfigurationTest {
26 public void testNetconfReconnectingClientConfiguration() throws Exception {
28 NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
29 NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
30 InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
31 ReconnectStrategyFactory strategy = Mockito.mock(ReconnectStrategyFactory.class);
32 AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
33 ReconnectStrategy reconnect = Mockito.mock(ReconnectStrategy.class);
35 NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().
36 withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).
38 withConnectionTimeoutMillis(timeout).
39 withReconnectStrategy(reconnect).
40 withAdditionalHeader(header).
41 withSessionListener(listener).
42 withConnectStrategyFactory(strategy).
43 withAuthHandler(handler).build();
45 Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
46 Assert.assertEquals(Optional.fromNullable(header), cfg.getAdditionalHeader());
47 Assert.assertEquals(listener, cfg.getSessionListener());
48 Assert.assertEquals(handler, cfg.getAuthHandler());
49 Assert.assertEquals(strategy, cfg.getConnectStrategyFactory());
50 Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol());
51 Assert.assertEquals(address, cfg.getAddress());
52 Assert.assertEquals(reconnect, cfg.getReconnectStrategy());