Enhancing STC and cleaning up various test topos.

Change-Id: I7f5b349835ebf3d7da824be0aa2cddd860631f84
diff --git a/cli/src/main/java/org/onosproject/cli/UiViewListCommand.java b/cli/src/main/java/org/onosproject/cli/UiViewListCommand.java
new file mode 100644
index 0000000..33a85e6
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/UiViewListCommand.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.ui.UiExtension;
+import org.onosproject.ui.UiExtensionService;
+
+import java.util.List;
+
+/**
+ * Lists all UI views.
+ */
+@Command(scope = "onos", name = "ui-views",
+        description = "Lists all UI views")
+public class UiViewListCommand extends AbstractShellCommand {
+
+    private static final String FMT = "id=%s, category=%s, label=%s, icon=%s";
+
+    @Override
+    protected void execute() {
+        UiExtensionService service = get(UiExtensionService.class);
+        if (outputJson()) {
+            print("%s", json(service.getExtensions()));
+        } else {
+            service.getExtensions().forEach(ext -> ext.views()
+                    .forEach(v -> print(FMT, v.id(), v.category().label(),
+                                        v.label(), v.iconId())));
+        }
+    }
+
+    private JsonNode json(List<UiExtension> extensions) {
+        ObjectMapper mapper = new ObjectMapper();
+        ArrayNode node = mapper.createArrayNode();
+        extensions.forEach(ext -> ext.views()
+                .forEach(v -> node.add(mapper.createObjectNode()
+                                               .put("id", v.id())
+                                               .put("category", v.category().label())
+                                               .put("label", v.label())
+                                               .put("icon", v.iconId()))));
+        return node;
+    }
+
+}
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 9a4ffa8..e2f0764 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -59,6 +59,10 @@
         </command>
 
         <command>
+            <action class="org.onosproject.cli.UiViewListCommand"/>
+        </command>
+
+        <command>
             <action class="org.onosproject.cli.RolesCommand"/>
         </command>
         <command>
diff --git a/tools/test/bin/onos-check-apps b/tools/test/bin/onos-check-apps
index db5a473..8dfe9f0 100755
--- a/tools/test/bin/onos-check-apps
+++ b/tools/test/bin/onos-check-apps
@@ -3,6 +3,9 @@
 # Checks whether all and only the ONOS apps configured in ONOS_APPS are active.
 # -----------------------------------------------------------------------------
 
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
 aux=/tmp/stc-$$.log
 trap "rm -f $aux $aux.1 $aux.2 2>/dev/null" EXIT
 
diff --git a/tools/test/bin/onos-check-summary b/tools/test/bin/onos-check-summary
new file mode 100755
index 0000000..daa5253
--- /dev/null
+++ b/tools/test/bin/onos-check-summary
@@ -0,0 +1,18 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Checks ONOS summary data
+# -----------------------------------------------------------------------------
+
+aux=/tmp/stc-$$.log
+trap "rm -f $aux $aux.1 $aux.2 2>/dev/null" EXIT
+
+onos ${1:-$OCI} "onos:summary" > $aux
+cat $aux
+
+let status=0
+grep -q "nodes=$2" $aux || let status=status+1
+grep -q "devices=$3" $aux || let status=status+1
+grep -q "links=$4" $aux || let status=status+1
+grep -q "hosts=$5" $aux || let status=status+1
+
+exit $status
\ No newline at end of file
diff --git a/tools/test/bin/onos-check-views b/tools/test/bin/onos-check-views
new file mode 100755
index 0000000..9b43414
--- /dev/null
+++ b/tools/test/bin/onos-check-views
@@ -0,0 +1,17 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Checks whether all and only the ONOS apps configured in ONOS_APPS are active.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+aux=/tmp/stc-$$.log
+trap "rm -f $aux $aux.1 $aux.2 2>/dev/null" EXIT
+
+onos ${1} "onos:ui-views" > $aux
+cat $aux
+
+shift
+
+grep "$@" $aux
\ No newline at end of file
diff --git a/tools/test/bin/onos-wait-for-start b/tools/test/bin/onos-wait-for-start
index 106165a..93500f5 100755
--- a/tools/test/bin/onos-wait-for-start
+++ b/tools/test/bin/onos-wait-for-start
@@ -10,10 +10,14 @@
 
 ssh -t $remote "
     # Wait until we reach the run-level 100
-    running=""
-    while [ -z \$running ]; do
+    for i in \$(seq 1 30); do
         $ONOS_INSTALL_DIR/bin/onos bundle:list 2>/dev/null | \
-            grep -q 'START LEVEL 100' && running=1 || sleep 2
+            grep -q 'START LEVEL 100' && break || sleep 2
     done
 
+    # Wait until ApplicationManager is available
+    for i in \$(seq 1 5); do
+        grep -q \" ApplicationManager .* Started\" \
+            $ONOS_INSTALL_DIR/log/karaf.log && break || sleep 1
+    done
 "
diff --git a/tools/test/scenarios/archetypes.xml b/tools/test/scenarios/archetypes.xml
index f83879c..5913aeb 100644
--- a/tools/test/scenarios/archetypes.xml
+++ b/tools/test/scenarios/archetypes.xml
@@ -41,5 +41,10 @@
               exec="mvn clean install"/>
         <step name="Reinstall-App-With-UI" requires="^,~Verify-CLI"
               exec="onos-app ${OCI} reinstall! target/test-app-1.2.3.oar"/>
+        <step name="Verify-UI" requires="^"
+              exec="onos-check-views ${OCI} id=sample"/>
+
+        <step name="Uninstall-App" requires="^"
+              exec="onos-app ${OCI} uninstall org.foo.app"/>
     </group>
 </scenario>
diff --git a/tools/test/scenarios/basic-net.xml b/tools/test/scenarios/basic-net.xml
new file mode 100644
index 0000000..8d75d53
--- /dev/null
+++ b/tools/test/scenarios/basic-net.xml
@@ -0,0 +1,31 @@
+<!--
+  ~ Copyright 2015 Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<scenario name="basic-net" description="Basic network functionality test">
+    <group name="Basic-Net">
+        <step name="Install-Apps"
+              exec="onos ${OC1} app activate org.onosproject.proxyarp org.onosproject.fwd"/>
+        <step name="Check-Apps" requires="Install-Apps"
+              exec="onos-check-apps ${OC1} drivers,openflow,proxyarp,fwd"/>
+
+        <step name="Config-Topo"
+              exec="onos-topo-cfg ${OC1} ${ONOS_ROOT}/tools/test/topos/attmpls.json"/>
+        <step name="Check-Summary" requires="Config-Topo"
+              exec="onos-check-summary ${OC1} [0-9]* 25 0 25"/>
+
+        <step name="Start-Mininet" requires="Install-Apps,Check-Summary"
+              exec="echo onos-start-mininet not implemented yet"/>
+    </group>
+</scenario>
\ No newline at end of file
diff --git a/tools/test/scenarios/setup.xml b/tools/test/scenarios/setup.xml
index 1a8d754..8fefb81 100644
--- a/tools/test/scenarios/setup.xml
+++ b/tools/test/scenarios/setup.xml
@@ -20,10 +20,10 @@
         <parallel var="${OC#}">
             <step name="Push-Bits-${#}" exec="onos-push-bits ${OC#}" unless="${OCT}"/>
             <step name="Uninstall-${#}" exec="onos-uninstall ${OC#}"/>
-            <step name="Kill-${#}" env="~" exec="onos-kill ${OC#}"/>
+            <step name="Kill-${#}" env="~" exec="onos-kill ${OC#}" requires="Uninstall-${#}"/>
 
             <step name="Install-${#}" exec="onos-install ${OC#}"
-                  requires="Uninstall-${#},Push-Bits-${#},Push-Bits"/>
+                  requires="Kill-${#},Push-Bits-${#},Push-Bits"/>
 
             <step name="Wait-for-Start-${#}" exec="onos-wait-for-start ${OC#}"
                   requires="Install-${#}"/>
@@ -31,9 +31,9 @@
             <step name="Check-Logs-${#}" exec="onos-check-logs ${OC#}"
                   requires="~Wait-for-Start-${#}"/>
             <step name="Check-Components-${#}" exec="onos-check-components ${OC#}"
-                  requires="~Wait-for-Start-${#},~Check-Logs-${#}"/>
+                  requires="~Wait-for-Start-${#},"/>
             <step name="Check-Apps-${#}" exec="onos-check-apps ${OC#}"
-                  requires="~Wait-for-Start-${#},~Check-Logs-${#}"/>
+                  requires="~Wait-for-Start-${#}"/>
         </parallel>
     </group>
 </scenario>
diff --git a/tools/test/scenarios/tar-setup.xml b/tools/test/scenarios/tar-setup.xml
index 87ba8cd..b91cbf8 100644
--- a/tools/test/scenarios/tar-setup.xml
+++ b/tools/test/scenarios/tar-setup.xml
@@ -20,10 +20,10 @@
         <parallel var="${OC#}">
             <step name="Push-Bits-${#}" exec="onos-push-bits ${OC#}" unless="${OCT}"/>
             <step name="Uninstall-${#}" exec="onos-uninstall ${OC#}"/>
-            <step name="Kill-${#}" env="~" exec="onos-kill ${OC#}"/>
+            <step name="Kill-${#}" env="~" exec="onos-kill ${OC#}" requires="Uninstall-${#}"/>
 
             <step name="Untar-And-Run-${#}" exec="onos-untar-and-run ${OC#}"
-                  requires="Uninstall-${#},Push-Bits-${#},Push-Bits"/>
+                  requires="Kill-${#},Push-Bits-${#},Push-Bits"/>
 
             <step name="Wait-for-Start-${#}" exec="onos-wait-for-start ${OC#}"
                   requires="Untar-And-Run-${#}"/>
@@ -31,12 +31,12 @@
             <step name="Check-Logs-${#}" exec="onos-check-logs ${OC#}"
                   requires="~Wait-for-Start-${#}"/>
             <step name="Check-Components-${#}" exec="onos-check-components ${OC#}"
-                  requires="~Wait-for-Start-${#},~Check-Logs-${#}"/>
+                  requires="~Wait-for-Start-${#}"/>
             <step name="Check-Apps-${#}" exec="onos-check-apps ${OC#} drivers"
-                  requires="~Wait-for-Start-${#},~Check-Logs-${#}"/>
+                  requires="~Wait-for-Start-${#}"/>
 
             <step name="Check-Nodes-${#}" exec="onos-check-nodes ${OC#} ${OC#}"
-                  requires="~Wait-for-Start-${#},~Check-Logs-${#}"/>
+                  requires="~Wait-for-Start-${#}"/>
         </parallel>
     </group>
 
@@ -49,12 +49,12 @@
             <step name="Check-Logs-Again-${#}" exec="onos-check-logs ${OC#}"
                   requires="~Wait-for-Start-Again-${#}"/>
             <step name="Check-Components-Again-${#}" exec="onos-check-components ${OC#}"
-                  requires="~Wait-for-Start-Again-${#},~Check-Logs-Again-${#}"/>
+                  requires="~Wait-for-Start-Again-${#}"/>
             <step name="Check-Apps-Again-${#}" exec="onos-check-apps ${OC#} drivers"
-                  requires="~Wait-for-Start-Again-${#},~Check-Logs-Again-${#}"/>
+                  requires="~Wait-for-Start-Again-${#}"/>
 
             <step name="Check-Nodes-Again-${#}" exec="onos-check-nodes ${OC#}"
-                  requires="~Wait-for-Start-Again-${#},~Check-Logs-Again-${#}"/>
+                  requires="~Wait-for-Start-Again-${#}"/>
         </parallel>
     </group>
 
diff --git a/tools/test/topos/att-onos.py b/tools/test/topos/att-onos.py
index c19b0f1..a3376ae 100644
--- a/tools/test/topos/att-onos.py
+++ b/tools/test/topos/att-onos.py
@@ -26,6 +26,7 @@
     ctrl_count = 0
     for controllerIP in controllers:
         net.addController( 'c%d' % ctrl_count, RemoteController, ip=controllerIP )
+        ctrl_count = ctrl_count + 1
     net.build()
     net.start()
     CLI( net )
diff --git a/tools/test/topos/attmplsext.json b/tools/test/topos/attmplsext.json
deleted file mode 100644
index f94e7bc..0000000
--- a/tools/test/topos/attmplsext.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
-  "devices": [
-    { "alias": "s11", "uri": "of:0000001000000001", "mac": "001000000001", "annotations": { "name": "MINE", "latitude": 44.977862, "longitude":  -93.265427 }, "type": "SWITCH" },
-    { "alias": "s12", "uri": "of:0000001000000002", "mac": "001000000002", "annotations": { "name": "BISM", "latitude": 46.817887, "longitude": -100.786109 }, "type": "SWITCH" },
-    { "alias": "s13", "uri": "of:0000001000000003", "mac": "001000000003", "annotations": { "name": "BOIS", "latitude": 43.617834, "longitude": -116.216903 }, "type": "SWITCH" },
-    { "alias": "s14", "uri": "of:0000001000000004", "mac": "001000000004", "annotations": { "name": "RENO", "latitude": 39.533310, "longitude": -119.796940 }, "type": "SWITCH" },
-    { "alias": "s15", "uri": "of:0000001000000005", "mac": "001000000005", "annotations": { "name": "ALBU", "latitude": 35.109657, "longitude": -106.626698 }, "type": "SWITCH" }
-  ],
-
-  "hosts": [
-    { "alias": "h31", "mac": "00:10:00:00:00:01", "vlan": -1, "location": "of:0000001000000001/1", "ip": "10.0.0.31", "annotations": { "name": "MINE", "latitude": 46.509021, "longitude":  -93.820777 } },
-    { "alias": "h32", "mac": "00:10:00:00:00:02", "vlan": -1, "location": "of:0000001000000002/1", "ip": "10.0.0.32", "annotations": { "name": "BISM", "latitude": 48.169551, "longitude": -101.866954 } },
-    { "alias": "h33", "mac": "00:10:00:00:00:03", "vlan": -1, "location": "of:0000001000000003/1", "ip": "10.0.0.33", "annotations": { "name": "BOIS", "latitude": 44.617834, "longitude": -117.216903 } },
-    { "alias": "h34", "mac": "00:10:00:00:00:04", "vlan": -1, "location": "of:0000001000000004/1", "ip": "10.0.0.34", "annotations": { "name": "RENO", "latitude": 40.686744, "longitude": -117.886514 } },
-    { "alias": "h35", "mac": "00:10:00:00:00:05", "vlan": -1, "location": "of:0000001000000005/1", "ip": "10.0.0.35", "annotations": { "name": "ALBU", "latitude": 35.486729, "longitude": -104.231201 } }
-  ]
-
-}
diff --git a/tools/test/topos/attmplsext.py b/tools/test/topos/attmplsext.py
deleted file mode 100644
index c658f52..0000000
--- a/tools/test/topos/attmplsext.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env python
-
-"""
-"""
-from mininet.topo import Topo
-from mininet.net import Mininet
-from mininet.node import RemoteController
-from mininet.node import Node
-from mininet.node import CPULimitedHost
-from mininet.link import TCLink
-from mininet.cli import CLI
-from mininet.log import setLogLevel
-from mininet.util import dumpNodeConnections
-
-class AttMplsTopoExt( Topo ):
-    "Internet Topology Zoo Specimen."
-
-    def __init__( self ):
-        "Create a topology."
-
-        # Initialize Topology
-        Topo.__init__( self )
-
-        # add nodes, switches first...
-        MINE = self.addSwitch( 's31', dpid='0000001000000001')  # 44.977862, -93.265427
-        BISM = self.addSwitch( 's32', dpid='0000001000000002')  # 46.817887, -100.786109
-        BOIS = self.addSwitch( 's33', dpid='0000001000000003')  # 43.617834, -116.216903
-        RENO = self.addSwitch( 's34', dpid='0000001000000004')  # 39.533310, -119.796940
-        ALBU = self.addSwitch( 's35', dpid='0000001000000005')  # 35.109657, -106.626698
-
-        # ... and now hosts
-        MINE_host = self.addHost( 'h31', mac='00:10:00:00:00:01' )
-        BISM_host = self.addHost( 'h32', mac='00:10:00:00:00:02'  )
-        BOIS_host = self.addHost( 'h33', mac='00:10:00:00:00:03'  )
-        RENO_host = self.addHost( 'h34', mac='00:10:00:00:00:04'  )
-        ALBU_host = self.addHost( 'h35', mac='00:10:00:00:00:05'  )
-
-        # add edges between switch and corresponding host
-        self.addLink( MINE , MINE_host )
-        self.addLink( BISM , BISM_host )
-        self.addLink( BOIS , BOIS_host )
-        self.addLink( RENO , RENO_host )
-        self.addLink( ALBU , ALBU_host )
-
-        # add edges between switches
-        self.addLink( MINE , BISM, bw=10, delay='0.979030824185ms')
-        self.addLink( BISM , BOIS, bw=10, delay='0.806374975652ms')
-        self.addLink( BOIS , RENO, bw=10, delay='0.686192970166ms')
-        self.addLink( BOIS , ALBU, bw=10, delay='0.605826192092ms')
-        self.addLink( RENO , ALBU, bw=10, delay='1.4018238197ms')
-        self.addLink( RENO , MINE, bw=10, delay='0.232315346482ms')
-        self.addLink( BISM , ALBU, bw=10, delay='1.07297714274ms')
-
-topos = { 'att': ( lambda: AttMplsTopoExt() ) }
diff --git a/tools/test/topos/attmpls-fast.py b/tools/test/topos/attmplsfast.py
similarity index 100%
rename from tools/test/topos/attmpls-fast.py
rename to tools/test/topos/attmplsfast.py