2 * Copyright (c) 2016 CableLabs 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
8 package org.opendaylight.unimgr.cli;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
14 import java.math.BigInteger;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.Speed;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100M;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10G;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10M;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1G;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.SpeedBuilder;
35 import org.powermock.api.mockito.PowerMockito;
36 import org.powermock.api.support.membermodification.MemberModifier;
37 import org.powermock.core.classloader.annotations.PrepareForTest;
38 import org.powermock.modules.junit4.PowerMockRunner;
39 import org.powermock.reflect.Whitebox;
41 @RunWith(PowerMockRunner.class)
42 @PrepareForTest(UniAddShellCommand.class)
43 public class UniAddShellCommandTest {
45 private final String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
46 private final String macAddress = "00:00:00:00:00:00";
47 private final String mode = "Full Duplex";
48 private final String macLayer = "IEEE 802.3-2005";
49 private final String type = "";
50 private final String mtuSize = "0";
51 private final String ipAddress = "192.168.1.1";
52 private final String speed = "1G";
54 private final UnimgrConsoleProviderTest provider = new UnimgrConsoleProviderTest();
56 @Mock UniAddShellCommand uniAddShellCommand;
57 //@Mock UnimgrProvider provider;
60 public void setUp() throws IllegalArgumentException, IllegalAccessException{
61 uniAddShellCommand = mock(UniAddShellCommand.class, Mockito.CALLS_REAL_METHODS);
62 MemberModifier.field(UniAddShellCommand.class, "provider").set(uniAddShellCommand, provider);
63 Whitebox.setInternalState(uniAddShellCommand, "macAddress", macAddress);
64 Whitebox.setInternalState(uniAddShellCommand, "macLayer", macLayer);
65 Whitebox.setInternalState(uniAddShellCommand, "mode", mode);
66 Whitebox.setInternalState(uniAddShellCommand, "mtuSize", mtuSize);
67 Whitebox.setInternalState(uniAddShellCommand, "physicalMedium", physicalMedium);
68 Whitebox.setInternalState(uniAddShellCommand, "type", type);
69 Whitebox.setInternalState(uniAddShellCommand, "ipAddress", ipAddress);
70 Whitebox.setInternalState(uniAddShellCommand, "speed", speed);
74 * Test method for {@link org.opendaylight.unimgr.cli.UniAddShellCommand#doExecute()}.
78 public void testDoExecute() throws Exception {
79 final UniAugmentation uni = new UniAugmentationBuilder()
80 .setMacAddress(new MacAddress(macAddress))
81 .setMacLayer(macLayer)
83 .setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
84 .setPhysicalMedium(physicalMedium)
85 .setSpeed(new SpeedBuilder().setSpeed(Utils.getSpeed(speed)).build())
87 .setIpAddress(new IpAddress(ipAddress.toCharArray()))
89 final Object success = new String("Uni with ip " +ipAddress+" created");
90 final Object error = new String("Error creating new Uni");
91 Object stringReturn = uniAddShellCommand.doExecute();
92 assertEquals(success, stringReturn);
93 assertEquals(uni, provider.getUni(null));
94 stringReturn = uniAddShellCommand.doExecute();
95 assertEquals(error, stringReturn);