fix add and update commands 91/34491/1
authormelserngawy <melserngawy@inocybe.com>
Wed, 10 Feb 2016 18:40:54 +0000 (13:40 -0500)
committerAlexis de Talhouët <adetalhouet@inocybe.com>
Thu, 11 Feb 2016 18:27:38 +0000 (18:27 +0000)
Change-Id: I73c68be97d8b763f674f7734f3fe7dc063f52f82
Signed-off-by: melserngawy <melserngawy@inocybe.com>
(cherry picked from commit 4289604e12e398c0c52dc8bb5658184b27074a71)

cli/src/main/java/org/opendaylight/unimgr/cli/EvcAddShellCommand.java
cli/src/main/java/org/opendaylight/unimgr/cli/UniAddShellCommand.java
cli/src/main/java/org/opendaylight/unimgr/cli/UniUpdateShellCommand.java
cli/src/main/java/org/opendaylight/unimgr/cli/Utils.java [new file with mode: 0644]
cli/src/test/java/org/opendaylight/unimgr/cli/EvcAddShellCommandTest.java
cli/src/test/java/org/opendaylight/unimgr/cli/UniAddShellCommandTest.java
cli/src/test/java/org/opendaylight/unimgr/cli/UtilsTest.java [new file with mode: 0644]
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrProvider.java

index 84107cec9389b2549e3edf9b33f45d4daeedb862..62aab62f1b15cd54beef6f58d5e91e63235d0f25 100644 (file)
@@ -8,12 +8,10 @@
 
 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;
@@ -22,19 +20,14 @@ import org.opendaylight.unimgr.impl.UnimgrConstants;
 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;
 
@@ -65,32 +58,15 @@ public class EvcAddShellCommand extends OsgiCommandSupport {
             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;
@@ -117,8 +93,8 @@ public class EvcAddShellCommand extends OsgiCommandSupport {
         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();
index 8de1a77513f14d9096b9c946edb940fbdaa74d2a..3b22513820cc243a2f0bdcd7010f22296c2b7609 100755 (executable)
@@ -8,7 +8,6 @@
 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;
@@ -17,11 +16,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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;
 
@@ -79,8 +74,8 @@ public class UniAddShellCommand extends OsgiCommandSupport {
             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" },
@@ -93,23 +88,6 @@ public class UniAddShellCommand extends OsgiCommandSupport {
         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()
@@ -118,11 +96,10 @@ public class UniAddShellCommand extends OsgiCommandSupport {
                         .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 {
index 4618080ef3399b0095a60b0bf74a74d3374b156f..e498585076e2787e510ec09e5c0faed2d9b5a2f4 100644 (file)
@@ -8,7 +8,6 @@
 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;
@@ -17,95 +16,74 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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()
@@ -114,7 +92,7 @@ public class UniUpdateShellCommand extends OsgiCommandSupport{
                 .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();
diff --git a/cli/src/main/java/org/opendaylight/unimgr/cli/Utils.java b/cli/src/main/java/org/opendaylight/unimgr/cli/Utils.java
new file mode 100644 (file)
index 0000000..bbfc70e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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;
+    }
+
+}
index 4dd6a81922ab9f897f1b65e89848b8d466a34736..d1b038415662e77bd155ccb25629a6c6d16ba231 100644 (file)
@@ -25,7 +25,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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;
@@ -66,67 +68,13 @@ public class EvcAddShellCommandTest {
 
     }
 
-    /**
-     * 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);
@@ -150,8 +98,8 @@ public class EvcAddShellCommandTest {
         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();
index f024441e71a2da6211b439a1450bd3f0b7bffbdc..9ebc2e478cb8e45bdeb588c898c0d8cfb83bf213 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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;
@@ -30,7 +31,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.r
 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;
@@ -48,6 +49,7 @@ public class UniAddShellCommandTest {
     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();
 
@@ -65,54 +67,7 @@ public class UniAddShellCommandTest {
         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);
     }
 
     /**
@@ -121,14 +76,13 @@ public class UniAddShellCommandTest {
      */
     @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();
diff --git a/cli/src/test/java/org/opendaylight/unimgr/cli/UtilsTest.java b/cli/src/test/java/org/opendaylight/unimgr/cli/UtilsTest.java
new file mode 100644 (file)
index 0000000..e453c3a
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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);
+    }
+
+}
index 8e6415944ae69bd20863f2ef0a93022c9a734202..d239a3e83d8ef7ce681c9e34a70f7799a92a93c7 100755 (executable)
@@ -157,7 +157,7 @@ public class UnimgrProvider implements BindingAwareProvider, AutoCloseable, IUni
 
     @Override
     public UniAugmentation getUni(IpAddress ipAddress) {
-        return UnimgrUtils.getUni(dataBroker, LogicalDatastoreType.CONFIGURATION, ipAddress);
+        return UnimgrUtils.getUni(dataBroker, LogicalDatastoreType.OPERATIONAL, ipAddress);
     }
 
 
@@ -193,7 +193,7 @@ public class UnimgrProvider implements BindingAwareProvider, AutoCloseable, IUni
     @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);
@@ -210,8 +210,9 @@ public class UnimgrProvider implements BindingAwareProvider, AutoCloseable, IUni
                 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;
     }