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.controller.netconf.client;
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;
25 import java.net.InetSocketAddress;
27 public class NetconfReconnectingClientConfigurationTest {
29 public void testNetconfReconnectingClientConfiguration() throws Exception {
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);
38 NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().
39 withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).
41 withConnectionTimeoutMillis(timeout).
42 withReconnectStrategy(reconnect).
43 withAdditionalHeader(header).
44 withSessionListener(listener).
45 withConnectStrategyFactory(strategy).
46 withAuthHandler(handler).build();
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());