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;
13 import java.util.ArrayList;
14 import java.util.List;
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.unimgr.impl.UnimgrConstants;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentationBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.EgressBwBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.IngressBwBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceKey;
33 import org.powermock.api.mockito.PowerMockito;
34 import org.powermock.api.support.membermodification.MemberModifier;
35 import org.powermock.core.classloader.annotations.PrepareForTest;
36 import org.powermock.modules.junit4.PowerMockRunner;
37 import org.powermock.reflect.Whitebox;
39 @RunWith(PowerMockRunner.class)
40 @PrepareForTest(EvcAddShellCommand.class)
41 public class EvcAddShellCommandTest {
43 private final String IPs = "192.168.1.1";
44 private final String IPd = "192.168.1.2";
45 private final String egress = "100M";
46 private final String ingress = "10M";
48 private final UnimgrConsoleProviderTest provider = new UnimgrConsoleProviderTest();
50 @Mock EvcAddShellCommand evcAddShellCommand;
53 public void setUp() throws IllegalArgumentException, IllegalAccessException{
54 evcAddShellCommand = mock(EvcAddShellCommand.class, Mockito.CALLS_REAL_METHODS);
55 MemberModifier.field(EvcAddShellCommand.class, "provider").set(evcAddShellCommand, provider);
60 * Test method for {@link org.opendaylight.unimgr.cli.EvcAddShellCommand#doExecute()}.
64 public void testDoExecute() throws Exception {
65 final EvcAddShellCommand spyEvc = PowerMockito.spy(new EvcAddShellCommand(provider));
66 Whitebox.setInternalState(spyEvc, "ipSource", IPs);
67 Whitebox.setInternalState(spyEvc, "ipDestination", IPd);
68 Whitebox.setInternalState(spyEvc, "egress", egress);
69 Whitebox.setInternalState(spyEvc, "ingress", ingress);
70 final Short order = new Short("0");
71 final IpAddress ipAddreSource = new IpAddress(IPs.toCharArray());
72 final UniSource uniSource = new UniSourceBuilder()
73 .setIpAddress(ipAddreSource)
74 .setKey(new UniSourceKey(order))
77 final List<UniSource> uniSourceList = new ArrayList<UniSource>();
78 uniSourceList.add(uniSource);
79 final IpAddress ipAddreDest = new IpAddress(IPd.toCharArray());
80 final UniDest uniDest = new UniDestBuilder()
82 .setKey(new UniDestKey(order))
83 .setIpAddress(ipAddreDest)
85 final List<UniDest> uniDestList = new ArrayList<UniDest>();
86 uniDestList.add(uniDest);
87 final EvcAugmentation evcAug = new EvcAugmentationBuilder()
88 .setCosId(UnimgrConstants.EVC_PREFIX + 1)
89 .setEgressBw(new EgressBwBuilder().setSpeed(Utils.getSpeed(egress)).build())
90 .setIngressBw(new IngressBwBuilder().setSpeed(Utils.getSpeed(ingress)).build())
91 .setUniDest(uniDestList)
92 .setUniSource(uniSourceList)
94 final Object success = new String("Evc with Source Uni " +IPs+" and destenation Uni " +IPd+" created");
95 final Object error = new String("Error creating new Evc");
96 Object stringReturn = spyEvc.doExecute();
97 assertEquals(success, stringReturn);
98 assertEquals(evcAug, provider.getEvc(null));
99 stringReturn = spyEvc.doExecute();
100 assertEquals(error, stringReturn);