2 * Copyright (c) 2015 Huawei, 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.nemo.renderer.cli;
11 import junit.framework.TestCase;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.jboss.netty.bootstrap.ClientBootstrap;
16 import org.jboss.netty.channel.ChannelFactory;
17 import org.jboss.netty.channel.ChannelPipeline;
18 import org.jboss.netty.channel.ChannelPipelineFactory;
19 import org.jboss.netty.channel.Channels;
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
22 import org.jboss.netty.handler.codec.string.StringDecoder;
23 import org.jboss.netty.handler.codec.string.StringEncoder;
24 import org.jboss.netty.channel.*;
26 import java.lang.reflect.Method;
27 import java.net.InetSocketAddress;
28 import java.util.concurrent.Executors;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import sun.java2d.pipe.AAShapePipe;
34 import static org.junit.Assert.*;
35 import static org.mockito.Mockito.*;
37 * Created by zhangmeng on 2015/12/8.
39 public class TelnetUtilsTest extends TestCase {
40 private TelnetUtils telnetUtils;
42 public void setUp() throws Exception {
43 telnetUtils = new TelnetUtils();
47 public void testClose() throws Exception {
49 Assert.assertTrue(telnetUtils != null);
53 public void testIsClearOver() throws Exception {
54 Assert.assertTrue(TelnetUtils.isClearOver());
58 public void testSetClearOver() throws Exception {
59 Boolean clearOver = false;
60 TelnetUtils.setClearOver(clearOver);
61 Assert.assertTrue(!TelnetUtils.isClearOver());
65 public void testSet_GetInstanceOfClearCliTemplate() throws Exception {
66 // Assert.assertTrue(TelnetUtils.getInstanceOfClearCliTemplate() == null);//test null
67 String instanceOfClearCliTemplate = new String("test");
68 TelnetUtils.setInstanceOfClearCliTemplate(instanceOfClearCliTemplate);
69 Assert.assertTrue(TelnetUtils.getInstanceOfClearCliTemplate().equals("test"));
73 public void testSet_GetInstanceOfNewCliTemplate() throws Exception {
74 // Assert.assertEquals(TelnetUtils.getInstanceOfNewCliTemplate(),null);//test null
75 String instanceOfNewCliTemplate = new String("test");
76 TelnetUtils.setInstanceOfNewCliTemplate(instanceOfNewCliTemplate);
77 Assert.assertTrue(TelnetUtils.getInstanceOfNewCliTemplate().equals("test"));
81 public void testSet_GetCurrentDeviceName() throws Exception {
82 // Assert.assertTrue(TelnetUtils.getCurrentDeviceName() == null); //test null
83 String currentDeviceName = new String("test");
84 TelnetUtils.setCurrentDeviceName(currentDeviceName);
85 Assert.assertTrue(TelnetUtils.getCurrentDeviceName().equals("test"));
89 public void testSet_GetConfigOver() throws Exception {
90 Assert.assertTrue(!TelnetUtils.isConfigOver()); //test null
91 Boolean configOver = true;
92 TelnetUtils.setConfigOver(configOver);
93 Assert.assertTrue(TelnetUtils.isConfigOver());
97 public void testConfigL3vpnOnDeviceByCli() throws Exception {
98 String deviceName = new String("deviceNamePE1");
99 String clearOldConfigString = new String("clearOldConfigString");
100 String cliExecutionSequences = new String("cliExecutionSequences");
102 telnetUtils.configL3vpnOnDeviceByCli(deviceName,clearOldConfigString,cliExecutionSequences);
104 Assert.assertTrue(!TelnetUtils.isConfigOver());
105 Assert.assertEquals(TelnetUtils.getInstanceOfClearCliTemplate(), "clearOldConfigString");
106 Assert.assertEquals(TelnetUtils.getInstanceOfNewCliTemplate(),"cliExecutionSequences");
107 Assert.assertEquals(TelnetUtils.getCurrentDeviceName(),"deviceNamePE1");
111 public void testStartConnectAndConfig() throws Exception {
112 Class<TelnetUtils> class1 = TelnetUtils.class;
113 Method method = class1.getDeclaredMethod("startConnectAndConfig",new Class[]{SimpleChannelUpstreamHandler.class});
114 Method method1 = class1.getDeclaredMethod("sendNewConfig");
115 method.setAccessible(true);
116 method1.setAccessible(true);
118 SimpleChannelUpstreamHandler simpleChannelUpstreamHandler = mock(SimpleChannelUpstreamHandler.class);
119 Assert.assertEquals(TelnetUtils.getCurrentDeviceName(),"deviceNamePE1");
120 method.invoke(telnetUtils,simpleChannelUpstreamHandler);
121 method1.invoke(telnetUtils);