Merge pull request #28 from nwspeete-ibm/pushPackageStructure

WIP (work in progress) - Addition of gitignore, travis yml, build.sh,README travis status badg…
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..11cd881
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+tests/credentials.json
+openwhisk
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..15dbdff
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,27 @@
+sudo: required
+
+language: scala
+
+scala:
+  - 2.11.6
+
+services:
+  - docker
+
+env:
+  global:
+    - TERM=dumb
+
+notifications:
+  email: false
+
+install: true
+
+before_install:
+  - openssl aes-256-cbc -K $encrypted_ff5bbb6225c5_key -iv $encrypted_ff5bbb6225c5_iv -in tests/credentials.json.enc -out tests/credentials.json -d
+  - git clone https://github.com/openwhisk/openwhisk.git
+  - cd openwhisk
+  - ./tools/travis/setup.sh
+
+script:
+  - ../tools/travis/build.sh
diff --git a/README.md b/README.md
index 23e158a..c894a9b 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 
 
 # Using the Push package
-
+[![Build Status](https://travis-ci.org/openwhisk/openwhisk-package-pushnotifications?branch=master)](https://travis-ci.org/openwhisk/openwhisk-package-pushnotifications)
 The `/whisk.system/pushnotifications` package enables you to use Push Notification service with Whisk. It includes the following action and feed.
 
 | Entity | Type | Parameters | Description |
diff --git a/sendMessage.js b/actions/sendMessage.js
similarity index 100%
rename from sendMessage.js
rename to actions/sendMessage.js
diff --git a/webhook.js b/feeds/webhook.js
similarity index 100%
rename from webhook.js
rename to feeds/webhook.js
diff --git a/install.sh b/install.sh
index d610eaf..fc93fc9 100644
--- a/install.sh
+++ b/install.sh
@@ -1,35 +1,43 @@
 #!/bin/bash
+
+#/
+# Copyright 2015-2016 IBM Corporation
 #
-# use the command line interface to install standard actions deployed
-# automatically
+# 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
 #
-# To run this command
-# ./install.sh <apihost> <authkey> <pathtowskcli>
-# ./install.sh APIHOST="$EDGE_HOST" AUTH="$AUTH_KEY" WSK_CLI="$OPENWHISK_HOME/bin/wsk"
-# API_HOST and AUTH_KEY are found in $HOME/.wskprops
+# 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.
+#/
 
 set -e
 set -x
 
 if [ $# -eq 0 ]
 then
-echo "Usage: ./install.sh <apihost> <authkey> <pathtowskcli>"
+    echo "Usage: ./install.sh <apihost> <authkey> <pathtowskcli>"
 fi
 
-APIHOST="$1"
-AUTH="$2"
-WSK_CLI="$3"
+APIHOST=$1
+AUTH=$2
+WSK_CLI=$3
 
-# pushnotifications actions
+PACKAGE_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
 echo Installing pushnotifications package.
 
-$WSK_CLI --apihost "$APIHOST"  package update --auth "$AUTH"  --shared yes pushnotifications \
+$WSK_CLI --apihost $APIHOST  package update --auth $AUTH  --shared yes pushnotifications \
 -a description "This package supports sending push notifications to your mobile device, using the IBM Bluemix Push Notifications service." \
 -a parameters '[ {"name":"appId", "required":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"}]' \
 -a prettyName "Push Notifications"
 
-$WSK_CLI --apihost "$APIHOST" action update --auth "$AUTH" --shared yes pushnotifications/webhook "webhook.js" \
+$WSK_CLI --apihost $APIHOST action update --auth $AUTH --shared yes pushnotifications/webhook $PACKAGE_HOME/feeds/webhook.js \
 -a feed true \
 -a description 'pushnotifications feed' \
 -a parameters '[ {"name":"appId", "required":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"},{"name":"events", "required":true, "description":"Name of the event user want to subscribe"} ]' \
@@ -37,7 +45,7 @@
 -a sampleOutput '{"tagName": "tagName","eventType": "onDeviceRegister","applicationId": "xxx-xxx-xx"}'
 
 
-$WSK_CLI --apihost "$APIHOST" action update --auth "$AUTH" --shared yes pushnotifications/sendMessage "sendMessage.js" \
+$WSK_CLI --apihost $APIHOST action update --auth $AUTH --shared yes pushnotifications/sendMessage $PACKAGE_HOME/actions/sendMessage.js \
 -a description 'Send push notification to all application users or to a specific set of devices' \
 -a parameters '[ {"name":"appId", "required":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"}, {"name":"text", "required":true, "description":"The notification message to be shown to the user"}, {"name":"url", "required":false, "description":"An optional URL that can be sent along with the alert"}, {"name":"deviceIds", "required":false, "description":"Array of device IDs"}, {"name":"platforms", "required":false, "description":"Array of device platform"},{"name":"tagNames", "required":false, "description":"Array of tag names"},{"name":"gcmPayload", "required":false, "description":"Additional payload"},{"name":"gcmSound", "required":false, "description":"Sound file name"},{"name":"gcmCollapseKey", "required":false, "description":"This parameter identifies a group of messages"},{"name":"gcmDelayWhileIdle", "required":false, "description":"Send message when device is active"}, {"name":"gcmPriority", "required":false, "description":"Sets the priority of the message"}, {"name":"gcmTimeToLive", "required":false, "description":"Time limit for message to be delievered"}, {"name":"apnsBadge", "required":false, "description":"Value for Badge"}, {"name":"apnsCategory", "required":false, "description":"The category name"}, {"name":"apnsIosActionKey", "required":false, "description":"Title for the push notification action Key"},{"name":"apnsPayload", "required":false, "description":"Additional payload"},{"name":"apnsType", "required":false, "description":"Push notification type name"},{"name":"apnsSound", "required":false, "description":"APNS sound name"}]' \
 -a sampleInput '{"appId":"xxx-xxx-xx", "appSecret":"yyy-yyy-yyy", "text":"hi there"}' \
diff --git a/tests/credentials.json.enc b/tests/credentials.json.enc
new file mode 100644
index 0000000..6d1d605
--- /dev/null
+++ b/tests/credentials.json.enc
Binary files differ
diff --git a/tests/PushNotificationsTests.scala b/tests/src/PushNotificationsTests.scala
similarity index 100%
rename from tests/PushNotificationsTests.scala
rename to tests/src/PushNotificationsTests.scala
diff --git a/tests/template_credentials.json b/tests/template_credentials.json
new file mode 100644
index 0000000..4849df0
--- /dev/null
+++ b/tests/template_credentials.json
@@ -0,0 +1,20 @@
+{
+    "template_service": [{
+        "name": "Service x",
+        "label": "service-x",
+        "credentials": {
+            "apiKey": "XXXXXXXX",
+            "apiToken": "YYYYYYY",
+            "base_uri": "https://openwhisk.ng.bluemix.net/api/v1",
+        }
+    }],
+    "another_service": [{
+        "name": "Service y",
+        "label": "service-y",
+        "credentials": {
+            "apiKey": "ZZZZZZZZZZ",
+            "apiToken": "MMMMMMMMMM",
+            "base_uri": "https://openwhisk.ng.bluemix.net/api/v1",
+        }
+    }]
+}
diff --git a/tools/travis/build.sh b/tools/travis/build.sh
new file mode 100755
index 0000000..8fda47b
--- /dev/null
+++ b/tools/travis/build.sh
@@ -0,0 +1,48 @@
+# Build script for Travis-CI.
+
+SCRIPTDIR=$(cd $(dirname "$0") && pwd)
+ROOTDIR="$SCRIPTDIR/../../openwhisk"
+
+cd $ROOTDIR
+
+cp $ROOTDIR/../tests/src/* $ROOTDIR/tests/src/packages/
+
+tools/build/scanCode.py .
+
+cd $ROOTDIR/ansible
+
+ANSIBLE_CMD="ansible-playbook -i environments/travis"
+
+$ANSIBLE_CMD setup.yml
+$ANSIBLE_CMD prereq.yml
+$ANSIBLE_CMD couchdb.yml
+$ANSIBLE_CMD initdb.yml
+
+cd $ROOTDIR
+
+./gradlew distDocker
+
+cd $ROOTDIR/ansible
+
+$ANSIBLE_CMD openwhisk.yml
+
+cd $ROOTDIR
+
+VCAP_SERVICES_FILE="$(readlink -f $ROOTDIR/../tests/credentials.json)"
+
+#update whisk.properties to add tests/credentials.json file to vcap.services.file, which is needed in tests
+WHISKPROPS_FILE="$ROOTDIR/whisk.properties"
+sed -i 's:^[ \t]*vcap.services.file[ \t]*=\([ \t]*.*\)$:vcap.services.file='$VCAP_SERVICES_FILE':'  $WHISKPROPS_FILE
+cat whisk.properties
+
+WSK_CLI=$ROOTDIR/bin/wsk
+AUTH_KEY=$(cat $ROOTDIR/ansible/files/auth.whisk.system)
+EDGE_HOST=$(grep '^edge.host=' $WHISKPROPS_FILE | cut -d'=' -f2) 
+
+# Install the package
+source $ROOTDIR/../install.sh $EDGE_HOST $AUTH_KEY $WSK_CLI
+
+#Test only the test cases classes in tests/src (Openwhisk dependencies are needed)
+X="./gradlew :tests:test "
+for f in $(ls $ROOTDIR/../tests/src | sed -e 's/\..*$//'); do X="$X --tests \"packages.$f\""; done
+eval $X
diff --git a/uninstall.sh b/uninstall.sh
new file mode 100755
index 0000000..2f6ee35
--- /dev/null
+++ b/uninstall.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+#/
+# Copyright 2015-2016 IBM Corporation
+#
+# 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.
+#/
+
+set -e
+set -x
+
+if [ $# -eq 0 ]
+then
+    echo "Usage: ./uninstall.sh <apihost> <authkey> <pathtowskcli>"
+fi
+
+APIHOST=$1
+AUTH=$2
+WSK_CLI=$3
+
+PACKAGE_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+echo Uninstalling pushnotifications package \
+
+$WSK_CLI --apihost $APIHOST action delete --auth $AUTH pushnotifications/webhook
+
+$WSK_CLI --apihost $APIHOST action delete --auth $AUTH pushnotifications/sendMessage
+
+$WSK_CLI --apihost $APIHOST package delete --auth $AUTH pushnotifications