Enhancing STC and scenarios.

Change-Id: I57a4d25b7fb726a1242073055474ff5c7c3c1087
diff --git a/tools/dev/bin/onos-create-app b/tools/dev/bin/onos-create-app
index 9546b1d..279ec06 100755
--- a/tools/dev/bin/onos-create-app
+++ b/tools/dev/bin/onos-create-app
@@ -8,8 +8,10 @@
 
 type=${1:-bundle}
 
+[ $type = app ] && archetype=bundle || archetype=$type
+
 if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then
-    echo "usage: $(basename $0) {bundle|ui|cli|api} groupId artifactId version package mvn-options"
+    echo "usage: $(basename $0) {app|bundle|ui|cli|api} groupId artifactId version package mvn-options"
     echo "        All arguments are optional"
     exit 1
 fi
@@ -17,10 +19,16 @@
 otherOptions=""
 [ -n "$1" ] && shift
 [ -n "$1" ] && otherOptions="$otherOptions -DgroupId=$1" && shift
-[ -n "$1" ] && otherOptions="$otherOptions -DartifactId=$1" && shift
+[ -n "$1" ] && otherOptions="$otherOptions -DartifactId=$1" && dir=$1 && shift
 [ -n "$1" ] && otherOptions="$otherOptions -Dversion=$1" && shift
 [ -n "$1" ] && otherOptions="$otherOptions -Dpackage=$1" && shift
 
 mvn archetype:generate -DarchetypeGroupId=org.onosproject \
-    -DarchetypeArtifactId=onos-$type-archetype -DarchetypeVersion=$ONOS_POM_VERSION \
-    $otherOptions "$@"
\ No newline at end of file
+    -DarchetypeArtifactId=onos-$archetype-archetype \
+    -DarchetypeVersion=$ONOS_POM_VERSION $otherOptions "$@"
+
+# Patch the pom.xml file to make this an app.
+if [ $type = app -a -d $dir ]; then
+    egrep -v "        (<!--|-->)" $dir/pom.xml > $dir/pom.app.xml
+    mv $dir/pom.app.xml $dir/pom.xml
+fi
\ No newline at end of file
diff --git a/tools/package/archetypes/bundle/src/main/resources/archetype-resources/pom.xml b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/pom.xml
index 2b9a2b6..c6505ac 100644
--- a/tools/package/archetypes/bundle/src/main/resources/archetype-resources/pom.xml
+++ b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/pom.xml
@@ -108,7 +108,7 @@
             <plugin>
                 <groupId>org.onosproject</groupId>
                 <artifactId>onos-maven-plugin</artifactId>
-                <version>1.4-SNAPSHOT</version>
+                <version>1.4</version>
                 <executions>
                     <execution>
                         <id>cfg</id>
diff --git a/tools/test/bin/ogroup-opts b/tools/test/bin/ogroup-opts
index e9b030c..3b4248c 100644
--- a/tools/test/bin/ogroup-opts
+++ b/tools/test/bin/ogroup-opts
@@ -1,14 +1,43 @@
-# tab completion settings for onos-group.
 
-# options available to onos-group
-GOPTS='install kill patch-vm push-keys uninstall'
-
+# Tab completion settings for onos-group.
 function _ogroup-opts () {
   local cur=${COMP_WORDS[COMP_CWORD]}
-
   if [ $COMP_CWORD -eq 1 ]; then
-    COMPREPLY=( $( compgen -W "$GOPTS help" -- $cur ) )
+    COMPREPLY=( $( compgen -W "install kill patch-vm push-keys uninstall help" -- $cur ) )
   fi
 }
 
 complete -F _ogroup-opts onos-group
+
+
+# Tab completion settings for stc
+function _stc-opts () {
+  local cur=${COMP_WORDS[COMP_CWORD]}
+  if [ $COMP_CWORD -eq 1 ]; then
+    COMPREPLY=( $( compgen -W "$(cd $ONOS_ROOT/tools/test/scenarios && ls -1 | sed 's/.xml//g')" -- $cur ) )
+  fi
+}
+
+complete -F _stc-opts stc
+
+
+# Tab completion settings for cell
+function _cell-opts () {
+  local cur=${COMP_WORDS[COMP_CWORD]}
+  if [ $COMP_CWORD -eq 1 ]; then
+    COMPREPLY=( $( compgen -W "$(cd $ONOS_ROOT/tools/test/cells && ls -1)" -- $cur ) )
+  fi
+}
+
+complete -F _cell-opts cell
+
+
+# Tab completion settings for onos-create-app.
+function _ocapp-opts () {
+  local cur=${COMP_WORDS[COMP_CWORD]}
+  if [ $COMP_CWORD -eq 1 ]; then
+    COMPREPLY=( $( compgen -W "bundle ui cli" -- $cur ) )
+  fi
+}
+
+complete -F _ocapp-opts onos-create-app
diff --git a/tools/test/bin/onos-check-bits b/tools/test/bin/onos-check-bits
index 0cf5fe5..0423c34 100755
--- a/tools/test/bin/onos-check-bits
+++ b/tools/test/bin/onos-check-bits
@@ -6,4 +6,4 @@
 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
 . $ONOS_ROOT/tools/build/envDefaults
 
-test -f $ONOS_TAR
+ls -l $ONOS_TAR && cksum $ONOS_TAR
diff --git a/tools/test/bin/onos-check-components b/tools/test/bin/onos-check-components
index 38fb9a3..f4c2df2 100755
--- a/tools/test/bin/onos-check-components
+++ b/tools/test/bin/onos-check-components
@@ -8,4 +8,10 @@
 
 onos ${1:-$OCI} scr:list > $aux
 cat $aux
-grep -q UNSATISFIED $aux && exit 1 || exit 0
+grep -q UNSATISFIED $aux && exit 1
+
+if [ -n "$2" ]; then
+    echo "Searching for ACTIVE $2"
+    egrep "ACTIVE.*$2" $aux || exit 1
+fi
+exit 0
\ No newline at end of file
diff --git a/tools/test/bin/stc b/tools/test/bin/stc
index 9dfa38f..fd201b6 100755
--- a/tools/test/bin/stc
+++ b/tools/test/bin/stc
@@ -3,11 +3,14 @@
 #   System Test Coordinator
 #-------------------------------------------------------------------------------
 
-STC_ROOT=${STC_ROOT:-$(dirname $0)/..}
-cd $STC_ROOT
 VER=1.2.0-SNAPSHOT
+JAR=~/.m2/repository/org/onosproject/onlab-stc/$VER/onlab-stc-$VER.jar
+SCENARIOS=$ONOS_ROOT/tools/test/scenarios
 
-PATH=$PWD/bin:$PATH
+scenario=${1:-smoke}
 
-java -jar ~/.m2/repository/org/onosproject/onlab-stc/$VER/onlab-stc-$VER.jar \
-    "${@:-$ONOS_ROOT/tools/test/scenarios/smoke.xml}"
+[ ! -f $scenario ] && scenario=$SCENARIOS/$scenario
+[ ! -f $scenario ] && scenario=$scenario.xml
+[ ! -f $scenario ] && echo "Scenario $scenario file not found" && exit 1
+
+java -jar $JAR $scenario
diff --git a/tools/test/bin/stc-launcher b/tools/test/bin/stc-launcher
index 3ef661e..d5da4f1 100755
--- a/tools/test/bin/stc-launcher
+++ b/tools/test/bin/stc-launcher
@@ -2,4 +2,22 @@
 #-------------------------------------------------------------------------------
 #   System Test Coordinator process launcher
 #-------------------------------------------------------------------------------
+
+env=$1 && shift
+cwd=$1 && shift
+
+if [ $env != "-" -a $env != "~" ]; then
+    [ ! -f $env ] && echo "$env file not found" && exit 1
+    source $env
+fi
+
+if [ $cwd != "-" ]; then
+    [ ! -d $cwd ] && echo "$cwd directory not found" && exit 1
+    cd $cwd
+fi
+
 "$@" 2>&1
+status=$?
+
+[ $env != "~" ] && exit $status
+exit 0
diff --git a/tools/test/scenarios/archetypes.xml b/tools/test/scenarios/archetypes.xml
new file mode 100644
index 0000000..42c4ffb
--- /dev/null
+++ b/tools/test/scenarios/archetypes.xml
@@ -0,0 +1,45 @@
+<!--
+  ~ 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="archetypes-test" description="ONOS archetypes test">
+    <group name="Archetypes" cwd="${WORKSPACE}/tmp/test-app">
+        <step name="Clean-Up" cwd="${WORKSPACE}/tmp" env="~"
+              exec="rm -r test-app"/>
+
+        <step name="Create-App" cwd="${WORKSPACE}/tmp" requires="Clean-Up"
+              exec="onos-create-app app org.test.app test-app 1.2.3 org.test.app -DinteractiveMode=false"/>
+        <step name="Build-App" requires="Create-App" exec="mvn clean install"/>
+        <step name="Install-App" requires="Build-App"
+              exec="onos-app ${OCI} install! target/test-app-1.2.3.oar"/>
+        <step name="Verify-App" requires="Install-App"
+              exec="onos-check-components ${OCI} org.test.app.AppComponent"/>
+
+        <step name="Create-App-CLI-Overlay" requires="Install-App"
+              exec="onos-create-app cli org.test.app test-app 1.2.3 org.test.app -DinteractiveMode=false"/>
+        <step name="Build-App-With-CLI" requires="Create-App-CLI-Overlay"
+              exec="mvn clean install"/>
+        <step name="Reinstall-App-With-CLI" requires="Build-App-With-CLI,-Verify-App"
+              exec="onos-app ${OCI} reinstall! target/test-app-1.2.3.oar"/>
+        <step name="Verify-CLI" requires="Reinstall-App-With-CLI"
+              exec="onos ${OCI} sample"/>
+
+        <step name="Create-App-UI-Overlay" requires="Reinstall-App-With-CLI"
+              exec="onos-create-app ui org.test.app test-app 1.2.3 org.test.app -DinteractiveMode=false"/>
+        <step name="Build-App-With-UI" requires="Create-App-UI-Overlay"
+              exec="mvn clean install"/>
+        <step name="Reinstall-App-With-UI" requires="Build-App-With-UI,-Verify-CLI"
+              exec="onos-app ${OCI} reinstall! target/test-app-1.2.3.oar"/>
+    </group>
+</scenario>