package org.opendaylight.unimgr.cli;
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
-
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.EgressBw;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.IngressBw;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.EgressBwBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.IngressBwBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
aliases = { "--egress-speed" },
description = "egress speed.\n-s / --speed 10M/100M/1G/10G",
required = false,
- multiValued = true)
- private String egress = "";
+ multiValued = false)
+ private String egress = "1G";
@Option(name = "-ingress",
aliases = { "--ingress-speed" },
description = "ingress speed.\n-s / --speed 10M/100M/1G/10G",
required = false,
- multiValued = true)
- private String ingress = "";
-
- private Object getSpeed(String speed) {
- Object speedObject = null;
- if (speed.equals("10M")) {
- speedObject = new Speed10MBuilder().build();
- }
- else if (speed.equals("100M")) {
- speedObject = new Speed100MBuilder().build();
- }
- else if (speed.equals("1G")) {
- speedObject = new Speed1GBuilder().build();
- }
- else if (speed.equals("10G")) {
- speedObject = new Speed10GBuilder().build();
- }
- return speedObject;
- }
+ multiValued = false)
+ private String ingress = "1G";
public EvcAddShellCommand(IUnimgrConsoleProvider provider) {
this.provider = provider;
uniDestList.add(uniDest);
EvcAugmentation evcAug = new EvcAugmentationBuilder()
.setCosId(UnimgrConstants.EVC_PREFIX + 1)
- .setEgressBw((EgressBw) getSpeed(egress))
- .setIngressBw((IngressBw) getSpeed(ingress))
+ .setEgressBw(new EgressBwBuilder().setSpeed(Utils.getSpeed(egress)).build())
+ .setIngressBw(new IngressBwBuilder().setSpeed(Utils.getSpeed(ingress)).build())
.setUniDest(uniDestList)
.setUniSource(uniSourceList)
.build();
package org.opendaylight.unimgr.cli;
import java.math.BigInteger;
-
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.SpeedBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
aliases = { "--speed" },
description = "Spped.\n-s / --speed 10M/100M/1G/10G",
required = false,
- multiValued = true)
- private String speed = "";
+ multiValued = false)
+ private String speed = "1G";
@Option(name = "-ip",
aliases = { "--ipAddress" },
this.provider = provider;
}
- private Object getSpeed() {
- Object speedObject = null;
- if (speed.equals("10M")) {
- speedObject = new Speed10MBuilder().build();
- }
- else if (speed.equals("100M")) {
- speedObject = new Speed100MBuilder().build();
- }
- else if (speed.equals("1G")) {
- speedObject = new Speed1GBuilder().build();
- }
- else if (speed.equals("10G")) {
- speedObject = new Speed10GBuilder().build();
- }
- return speedObject;
- }
-
@Override
protected Object doExecute() throws Exception {
UniAugmentation uni = new UniAugmentationBuilder()
.setMode(mode)
.setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
.setPhysicalMedium(physicalMedium)
- .setSpeed((Speed) getSpeed())
+ .setSpeed(new SpeedBuilder().setSpeed(Utils.getSpeed(speed)).build())
.setType(type)
.setIpAddress(new IpAddress(ipAddress.toCharArray()))
.build();
-
if (provider.addUni(uni)) {
return new String("Uni with ip " +ipAddress+" created");
} else {
package org.opendaylight.unimgr.cli;
import java.math.BigInteger;
-
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.SpeedBuilder;
@Command(name = "uni-update",
scope = "uni",
description = "Updates an uni to the controller.")
public class UniUpdateShellCommand extends OsgiCommandSupport{
- protected IUnimgrConsoleProvider provider;
-
- @Option(name = "-pm",
- aliases = { "--physical-medium" },
- description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
- required = false,
+ @Option(name = "-ip",
+ aliases = { "--ipAddress" },
+ description = "IpAddress of the Uni",
+ required = true,
multiValued = false)
- private final String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
+ private String ipAddress = "any";
@Option(name = "-ma",
aliases = { "--mac-address" },
description = "The mac address.\n-ma / --mac-address <mac-address>",
required = true,
multiValued = false)
- private final String macAddress = "any";
-
- @Option(name = "-m",
- aliases = { "--mode" },
- description = "The mode.\n-m / --mode <mode>",
- required = false,
- multiValued = false)
- private final String mode = "Full Duplex";
+ private String macAddress = "any";
@Option(name = "-ml",
aliases = { "--mac-layer" },
description = "The mac layer.\n-ml / --mac-layer <mac-layer",
required = false,
multiValued = false)
- private final String macLayer = "IEEE 802.3-2005";
+ private String macLayer = "IEEE 802.3-2005";
- @Option(name = "-t",
- aliases = { "--type" },
- description = "The type.\n-t / --type <type>",
+ @Option(name = "-m",
+ aliases = { "--mode" },
+ description = "The mode.\n-m / --mode <mode>",
required = false,
multiValued = false)
- private final String type = "";
+ private String mode = "Full Duplex";
@Option(name = "-ms",
aliases = { "--mtu-size" },
description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
required = false,
multiValued = false)
- private final String mtuSize = "0";
+ private String mtuSize = "0";
+
+ @Option(name = "-pm",
+ aliases = { "--physical-medium" },
+ description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
+ required = false,
+ multiValued = false)
+ private String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
+
+ protected IUnimgrConsoleProvider provider;
@Option(name = "-s",
aliases = { "--speed" },
description = "Spped.\n-s / --speed 10M/100M/1G/10G",
required = false,
- multiValued = true)
- private final String speed = "";
+ multiValued = false)
+ private String speed = "";
- @Option(name = "-ip",
- aliases = { "--ipAddress" },
- description = "IpAddress of the Uni",
- required = true,
+ @Option(name = "-t",
+ aliases = { "--type" },
+ description = "The type.\n-t / --type <type>",
+ required = false,
multiValued = false)
- private final String ipAddress = "any";
+ private String type = "";
public UniUpdateShellCommand(IUnimgrConsoleProvider provider) {
this.provider = provider;
}
- private Object getSpeed() {
- Object speedObject = null;
- if (speed.equals("10M")) {
- speedObject = new Speed10MBuilder().build();
- }
- else if (speed.equals("100M")) {
- speedObject = new Speed100MBuilder().build();
- }
- else if (speed.equals("1G")) {
- speedObject = new Speed1GBuilder().build();
- }
- else if (speed.equals("10G")) {
- speedObject = new Speed10GBuilder().build();
- }
- return speedObject;
- }
-
@Override
protected Object doExecute() throws Exception {
final UniAugmentation uniAug = new UniAugmentationBuilder()
.setMode(mode)
.setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
.setPhysicalMedium(physicalMedium)
- .setSpeed((Speed) getSpeed())
+ .setSpeed(new SpeedBuilder().setSpeed(Utils.getSpeed(speed)).build())
.setType(type)
.setIpAddress(new IpAddress(ipAddress.toCharArray()))
.build();
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.cli;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.Speed;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.SpeedBuilder;
+
+public final class Utils {
+
+ private Utils() {
+
+ }
+
+ public static final Speed getSpeed(final String speed) {
+ Speed speedObject = null;
+ if (speed.equals("10M")) {
+ speedObject = new Speed10MBuilder().setSpeed10M(true)
+ .build();
+ }
+ else if (speed.equals("100M")) {
+ speedObject = new Speed100MBuilder().setSpeed100M(true)
+ .build();
+ }
+ else if (speed.equals("1G")) {
+ speedObject = new Speed1GBuilder().setSpeed1G(true)
+ .build();
+ }
+ else if (speed.equals("10G")) {
+ speedObject = new Speed10GBuilder().setSpeed10G(true)
+ .build();
+ }
+ return speedObject;
+ }
+
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.EgressBw;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.EgressBwBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.IngressBw;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.IngressBwBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestKey;
}
- /**
- * Test method for {@link org.opendaylight.unimgr.cli.EvcAddShellCommand#getSpeed()}.
- * @throws Exception
- */
- @Test
- public void testgetSpeed() throws Exception {
- // Test 10M
- String speed = "10M";
- final Speed10M speed10M = mock(Speed10M.class);
- final Speed10MBuilder speed10MBuilder = mock(Speed10MBuilder.class);
- when(speed10MBuilder.build()).thenReturn(speed10M);
- PowerMockito.whenNew(Speed10MBuilder.class).withNoArguments().thenReturn(speed10MBuilder);
- Object getSpeed = Whitebox.invokeMethod(evcAddShellCommand, "getSpeed", speed);
- assertEquals(speed10M, getSpeed);
-
- // Test 100M
- speed = "100M";
- final Speed100M speedObject100M = mock(Speed100M.class);
- final Speed100MBuilder speed100M = mock(Speed100MBuilder.class);
- PowerMockito.whenNew(Speed100MBuilder.class).withNoArguments().thenReturn(speed100M);
- when(speed100M.build()).thenReturn(speedObject100M);
- getSpeed = Whitebox.invokeMethod(evcAddShellCommand, "getSpeed", speed);
- assertEquals(speedObject100M, getSpeed);
-
- // Test 1G
- speed = "1G";
- final Speed1G speedObject1G = mock(Speed1G.class);
- final Speed1GBuilder speed1G = mock(Speed1GBuilder.class);
- PowerMockito.whenNew(Speed1GBuilder.class).withNoArguments().thenReturn(speed1G);
- when(speed1G.build()).thenReturn(speedObject1G);
- getSpeed = Whitebox.invokeMethod(evcAddShellCommand, "getSpeed", speed);
- assertEquals(speedObject1G, getSpeed);
-
- // Test 10G
- speed = "10G";
- final Speed10G speedObject10G = mock(Speed10G.class);
- final Speed10GBuilder speed10G = mock(Speed10GBuilder.class);
- PowerMockito.whenNew(Speed10GBuilder.class).withNoArguments().thenReturn(speed10G);
- when(speed10G.build()).thenReturn(speedObject10G);
- getSpeed = Whitebox.invokeMethod(evcAddShellCommand, "getSpeed", speed);
- assertEquals(speedObject10G, getSpeed);
-
- // Test other
- speed = "other";
- getSpeed = Whitebox.invokeMethod(evcAddShellCommand, "getSpeed", speed);
- assertEquals(null, getSpeed);
- }
-
/**
* Test method for {@link org.opendaylight.unimgr.cli.EvcAddShellCommand#doExecute()}.
* @throws Exception
*/
@Test
public void testDoExecute() throws Exception {
- final EgressBw egressBw100M = mock(EgressBw.class);
- final IngressBw ingressBw10M = mock(IngressBw.class);
final EvcAddShellCommand spyEvc = PowerMockito.spy(new EvcAddShellCommand(provider));
- PowerMockito.when(spyEvc, method(EvcAddShellCommand.class, "getSpeed", String.class))
- .withArguments("100M").thenReturn(egressBw100M);
- PowerMockito.when(spyEvc, method(EvcAddShellCommand.class, "getSpeed", String.class))
- .withArguments("10M").thenReturn(ingressBw10M);
Whitebox.setInternalState(spyEvc, "IPs", IPs);
Whitebox.setInternalState(spyEvc, "IPd", IPd);
Whitebox.setInternalState(spyEvc, "egress", egress);
uniDestList.add(uniDest);
final EvcAugmentation evcAug = new EvcAugmentationBuilder()
.setCosId(UnimgrConstants.EVC_PREFIX + 1)
- .setEgressBw((EgressBw) egressBw100M)
- .setIngressBw((IngressBw) ingressBw10M)
+ .setEgressBw(new EgressBwBuilder().setSpeed(Utils.getSpeed(egress)).build())
+ .setIngressBw(new IngressBwBuilder().setSpeed(Utils.getSpeed(ingress)).build())
.setUniDest(uniDestList)
.setUniSource(uniSourceList)
.build();
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.Speed;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100M;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10G;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1G;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.SpeedBuilder;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.api.support.membermodification.MemberModifier;
import org.powermock.core.classloader.annotations.PrepareForTest;
private final String type = "";
private final String mtuSize = "0";
private final String ipAddress = "192.168.1.1";
+ private final String speed = "1G";
private final UnimgrConsoleProviderTest provider = new UnimgrConsoleProviderTest();
Whitebox.setInternalState(uniAddShellCommand, "physicalMedium", physicalMedium);
Whitebox.setInternalState(uniAddShellCommand, "type", type);
Whitebox.setInternalState(uniAddShellCommand, "ipAddress", ipAddress);
- }
-
- /**
- * Test method for {@link org.opendaylight.unimgr.cli.UniAddShellCommand#getSpeed()}.
- * @throws Exception
- */
- @Test
- public void testgetSpeed() throws Exception {
- // Test 10M
- Whitebox.setInternalState(uniAddShellCommand, "speed", "10M");
- final Speed10M speed10M = mock(Speed10M.class);
- final Speed10MBuilder speed10MBuilder = mock(Speed10MBuilder.class);
- when(speed10MBuilder.build()).thenReturn(speed10M);
- PowerMockito.whenNew(Speed10MBuilder.class).withNoArguments().thenReturn(speed10MBuilder);
- Object getSpeed = Whitebox.invokeMethod(uniAddShellCommand, "getSpeed");
- assertEquals(speed10M, getSpeed);
-
- // Test 100M
- Whitebox.setInternalState(uniAddShellCommand, "speed", "100M");
- final Speed100M speedObject100M = mock(Speed100M.class);
- final Speed100MBuilder speed100M = mock(Speed100MBuilder.class);
- PowerMockito.whenNew(Speed100MBuilder.class).withNoArguments().thenReturn(speed100M);
- when(speed100M.build()).thenReturn(speedObject100M);
- getSpeed = Whitebox.invokeMethod(uniAddShellCommand, "getSpeed");
- assertEquals(speedObject100M, getSpeed);
-
- // Test 1G
- Whitebox.setInternalState(uniAddShellCommand, "speed", "1G");
- final Speed1G speedObject1G = mock(Speed1G.class);
- final Speed1GBuilder speed1G = mock(Speed1GBuilder.class);
- PowerMockito.whenNew(Speed1GBuilder.class).withNoArguments().thenReturn(speed1G);
- when(speed1G.build()).thenReturn(speedObject1G);
- getSpeed = Whitebox.invokeMethod(uniAddShellCommand, "getSpeed");
- assertEquals(speedObject1G, getSpeed);
-
- // Test 10G
- Whitebox.setInternalState(uniAddShellCommand, "speed", "10G");
- final Speed10G speedObject10G = mock(Speed10G.class);
- final Speed10GBuilder speed10G = mock(Speed10GBuilder.class);
- PowerMockito.whenNew(Speed10GBuilder.class).withNoArguments().thenReturn(speed10G);
- when(speed10G.build()).thenReturn(speedObject10G);
- getSpeed = Whitebox.invokeMethod(uniAddShellCommand, "getSpeed");
- assertEquals(speedObject10G, getSpeed);
-
- // Test other
- Whitebox.setInternalState(uniAddShellCommand, "speed", "other");
- getSpeed = Whitebox.invokeMethod(uniAddShellCommand, "getSpeed");
- assertEquals(null, getSpeed);
+ Whitebox.setInternalState(uniAddShellCommand, "speed", speed);
}
/**
*/
@Test
public void testDoExecute() throws Exception {
- Whitebox.setInternalState(uniAddShellCommand, "speed", "other");
final UniAugmentation uni = new UniAugmentationBuilder()
.setMacAddress(new MacAddress(macAddress))
.setMacLayer(macLayer)
.setMode(mode)
.setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
.setPhysicalMedium(physicalMedium)
- .setSpeed((Speed) null)
+ .setSpeed(new SpeedBuilder().setSpeed(Utils.getSpeed(speed)).build())
.setType(type)
.setIpAddress(new IpAddress(ipAddress.toCharArray()))
.build();
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.unimgr.cli;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.Speed;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100M;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10G;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10M;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1G;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
+
+public class UtilsTest {
+
+ @Test
+ public void testGetSpeed() {
+ // Test 10M
+ final Speed10M speed10M = new Speed10MBuilder().setSpeed10M(true).build();
+ Speed getSpeed = Utils.getSpeed("10M");
+ assertEquals(speed10M, getSpeed);
+
+ // Test 100M
+ final Speed100M speedObject100M = new Speed100MBuilder().setSpeed100M(true).build();
+ getSpeed = Utils.getSpeed("100M");
+ assertEquals(speedObject100M, getSpeed);
+
+ // Test 1G
+ final Speed1G speedObject1G = new Speed1GBuilder().setSpeed1G(true).build();
+ getSpeed = Utils.getSpeed("1G");
+ assertEquals(speedObject1G, getSpeed);
+
+ // Test 10G
+ final Speed10G speedObject10G = new Speed10GBuilder().setSpeed10G(true).build();
+ getSpeed = Utils.getSpeed("10G");
+ assertEquals(speedObject10G, getSpeed);
+
+ // Test other
+ getSpeed = Utils.getSpeed("1");
+ assertEquals(null, getSpeed);
+ }
+
+}
@Override
public UniAugmentation getUni(IpAddress ipAddress) {
- return UnimgrUtils.getUni(dataBroker, LogicalDatastoreType.CONFIGURATION, ipAddress);
+ return UnimgrUtils.getUni(dataBroker, LogicalDatastoreType.OPERATIONAL, ipAddress);
}
@Override
public boolean updateUni(UniAugmentation uni) {
// Remove the old UNI with IpAdress and create a new one with updated informations
- if (uni != null && uni.getOvsdbNodeRef() != null) {
+ if (uni != null) {
LOG.trace("UNI updated {}.", uni.getIpAddress().getIpv4Address());
final InstanceIdentifier<?> uniIID = UnimgrMapper.getUniIid(dataBroker,
uni.getIpAddress(), LogicalDatastoreType.OPERATIONAL);
ovsdbNode = optionalOvsdbNode.get();
}
UnimgrUtils.deleteNode(dataBroker, uniIID, LogicalDatastoreType.OPERATIONAL);
- return UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniIID,
- uni, ovsdbNode, dataBroker);
+ return (UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION, uniIID,
+ uni, ovsdbNode, dataBroker) && UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniIID,
+ uni, ovsdbNode, dataBroker));
}
return false;
}