You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ch...@apache.org on 2014/05/15 23:20:32 UTC

git commit: allow configuration of wiremock ports for cli tests

Repository: incubator-stratos
Updated Branches:
  refs/heads/master 92d8d32db -> d1954f6f0


allow configuration of wiremock ports for cli tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/d1954f6f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/d1954f6f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/d1954f6f

Branch: refs/heads/master
Commit: d1954f6f0ee3c6df8ad3da217d2844548f1277d1
Parents: 92d8d32
Author: Chris Snow <ch...@apache.org>
Authored: Thu May 15 21:19:48 2014 +0000
Committer: Chris Snow <ch...@apache.org>
Committed: Thu May 15 21:19:48 2014 +0000

----------------------------------------------------------------------
 components/org.apache.stratos.cli/pom.xml       |  6 ++++
 .../src/test/python/README.md                   | 34 +++++++++++++++++++-
 .../src/test/python/test_common.py              |  8 ++---
 .../src/test/python/test_interactive.py         |  4 ++-
 .../src/test/python/test_noninteractive.py      |  4 ++-
 .../src/test/python/wiremock.py                 | 19 ++++++++---
 6 files changed, 64 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d1954f6f/components/org.apache.stratos.cli/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/pom.xml b/components/org.apache.stratos.cli/pom.xml
index 8abe1b9..1643665 100644
--- a/components/org.apache.stratos.cli/pom.xml
+++ b/components/org.apache.stratos.cli/pom.xml
@@ -220,6 +220,8 @@
 										<PYTHONPATH>../../main/python:${project.build.directory}/pexpect-3.2:$PYTHONPATH</PYTHONPATH>
 										<CLI_JAR>${project.build.directory}/${project.build.finalName}.jar</CLI_JAR>
 										<WIREMOCK_JAR>${project.build.directory}/dependency/wiremock-${wiremock.version}-standalone.jar</WIREMOCK_JAR>
+										<WIREMOCK_HTTP_PORT>8080</WIREMOCK_HTTP_PORT>
+										<WIREMOCK_HTTPS_PORT>9443</WIREMOCK_HTTPS_PORT>
 									</environmentVariables>
 								</configuration>
 								<id>python-test-common</id>
@@ -240,6 +242,8 @@
 										<PYTHONPATH>../../main/python:${project.build.directory}/pexpect-3.2:$PYTHONPATH</PYTHONPATH>
 										<CLI_JAR>${project.build.directory}/${project.build.finalName}.jar</CLI_JAR>
 										<WIREMOCK_JAR>${project.build.directory}/dependency/wiremock-${wiremock.version}-standalone.jar</WIREMOCK_JAR>
+										<WIREMOCK_HTTP_PORT>8080</WIREMOCK_HTTP_PORT>
+										<WIREMOCK_HTTPS_PORT>9443</WIREMOCK_HTTPS_PORT>
 									</environmentVariables>
 								</configuration>
 								<id>python-test-interactive</id>
@@ -260,6 +264,8 @@
 										<PYTHONPATH>../../main/python:${project.build.directory}/pexpect-3.2:$PYTHONPATH</PYTHONPATH>
 										<CLI_JAR>${project.build.directory}/${project.build.finalName}.jar</CLI_JAR>
 										<WIREMOCK_JAR>${project.build.directory}/dependency/wiremock-${wiremock.version}-standalone.jar</WIREMOCK_JAR>
+										<WIREMOCK_HTTP_PORT>8080</WIREMOCK_HTTP_PORT>
+										<WIREMOCK_HTTPS_PORT>9443</WIREMOCK_HTTPS_PORT>
 									</environmentVariables>
 								</configuration>
 								<id>python-test-noninteractive</id>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d1954f6f/components/org.apache.stratos.cli/src/test/python/README.md
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/test/python/README.md b/components/org.apache.stratos.cli/src/test/python/README.md
index e9130fa..ec88cef 100644
--- a/components/org.apache.stratos.cli/src/test/python/README.md
+++ b/components/org.apache.stratos.cli/src/test/python/README.md
@@ -14,7 +14,7 @@ You will need python installed and be running a unix like operating system
 
 Run 'mvn -P cli-test integration-test' to download the test dependencies.
 
-Set the environment variables CLI_JAR, PYTHONPATH and WIREMOCK_JAR. For example:
+Set the environment variables CLI_JAR, PYTHONPATH and WIREMOCK_JAR, WIREMOCK_HTTP_PORT, WIREMOCK_HTTPS_PORT. For example:
 
 ```
 # the stratos CLI_JAR
@@ -25,6 +25,12 @@ export PYTHONPATH=$PYTHONPATH:~/incubator-stratos/components/org.apache.stratos.
 
 # the wiremock application
 export WIREMOCK_JAR=~/incubator-stratos/components/org.apache.stratos.cli/target/dependency/wiremock-1.46-standalone.jar
+
+# wiremock's http port 
+export WIREMOCK_HTTP_PORT=8080
+
+# wiremock's https port 
+export WIREMOCK_HTTPS_PORT=9443
 ```
 
 The tests are split into three areas:
@@ -48,3 +54,29 @@ The tests depend on wiremock (www.wiremock.org) for simulating the Statos REST s
 The python class wiremock.py is a simple wrapper to start/stop wiremock and provides utility methods so the tests can call wiremock's APIs to retrieve information about the requests that wiremock received.
 
 The response that wiremock chooses to return for a particular request is defined in the 'mappings' folder.  A mapping usually has a response body that can be found in the '__files' folder
+
+#### Wiremock REST recording
+
+Wiremock can record REST requests and responses between the CLI and Stratos.  To setup recording, run wiremock wth the following command line:
+
+```
+java -jar $WIREMOCK_JAR --record-mappings --proxy-all="https://stratos_address:stratos_port" --port 8181 --https-port 9441
+```
+
+Choose values for the http and https ports that are free on your system.
+
+Set the STRATOS_URL:
+
+```
+export STRATOS_URL="https://localhost:9441"  # use the https-port you ran wiremock with
+```
+
+Then run the CLI, and perform the action that you want wiremock to record:
+
+```
+java -jar $CLI_JAR
+```
+
+Wiremock will have recorded the requests and responses from the CLI to Stratos in the 'mappings' and '__files' folders.
+
+You can stop wiremock on the command line and create a test case using pexpect.

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d1954f6f/components/org.apache.stratos.cli/src/test/python/test_common.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/test/python/test_common.py b/components/org.apache.stratos.cli/src/test/python/test_common.py
index 407a178..a8ab3c3 100755
--- a/components/org.apache.stratos.cli/src/test/python/test_common.py
+++ b/components/org.apache.stratos.cli/src/test/python/test_common.py
@@ -65,17 +65,17 @@ class TestCommon(unittest.TestCase):
         child.expect (pexpect.EOF)
 
     def test_error_if_context_path_is_provided_in_stratos_url(self):
-        os.environ["STRATOS_URL"] = "https://localhost:9443/somecontext/" # context path
+        os.environ["STRATOS_URL"] = "https://localhost:1234/somecontext/" # context path
         child = pexpect.spawn(TestCommon.cli_cmd)
-        child.expect ('The "STRATOS_URL" variable in your environment is not a valid URL. You have provided "https://localhost:9443/somecontext/"')
+        child.expect ('The "STRATOS_URL" variable in your environment is not a valid URL. You have provided "https://localhost:1234/somecontext/"')
         child.expect ('Please provide the Stratos Controller URL as follows')
         child.expect ('https://<host>:<port>')
         child.expect (pexpect.EOF)
 
     def test_error_if_non_https_scheme_is_provided_in_stratos_url(self):
-        os.environ["STRATOS_URL"] = "http://localhost:9443" # http scheme
+        os.environ["STRATOS_URL"] = "http://localhost:1234" # http scheme
         child = pexpect.spawn(TestCommon.cli_cmd)
-        child.expect ('The "STRATOS_URL" variable in your environment is not a valid URL. You have provided "http://localhost:9443"')
+        child.expect ('The "STRATOS_URL" variable in your environment is not a valid URL. You have provided "http://localhost:1234"')
         child.expect ('Please provide the Stratos Controller URL as follows')
         child.expect ('https://<host>:<port>')
         child.expect (pexpect.EOF)

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d1954f6f/components/org.apache.stratos.cli/src/test/python/test_interactive.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/test/python/test_interactive.py b/components/org.apache.stratos.cli/src/test/python/test_interactive.py
index cf1bb3e..5a0d8e7 100755
--- a/components/org.apache.stratos.cli/src/test/python/test_interactive.py
+++ b/components/org.apache.stratos.cli/src/test/python/test_interactive.py
@@ -33,6 +33,8 @@ class TestInteractive(unittest.TestCase):
 
     cli_cmd = "java -jar " + os.environ["CLI_JAR"]
 
+    WIREMOCK_HTTPS_PORT = os.environ["WIREMOCK_HTTPS_PORT"]
+
     @classmethod
     def setUpClass(cls):
         TestInteractive.wiremock = WiremockClient()
@@ -44,7 +46,7 @@ class TestInteractive(unittest.TestCase):
 
     def setUp(self):
         # set default STRATOS_URL
-        os.environ["STRATOS_URL"] = "https://localhost:9443" 
+        os.environ["STRATOS_URL"] = "https://localhost:" + TestInteractive.WIREMOCK_HTTPS_PORT 
         # ensure other env vars not set
         if 'STRATOS_USERNAME' in os.environ: del os.environ["STRATOS_USERNAME"] # unset env var
         if 'STRATOS_PASSWORD' in os.environ: del os.environ["STRATOS_PASSWORD"] # unset env var

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d1954f6f/components/org.apache.stratos.cli/src/test/python/test_noninteractive.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/test/python/test_noninteractive.py b/components/org.apache.stratos.cli/src/test/python/test_noninteractive.py
index 8379165..2633520 100755
--- a/components/org.apache.stratos.cli/src/test/python/test_noninteractive.py
+++ b/components/org.apache.stratos.cli/src/test/python/test_noninteractive.py
@@ -33,6 +33,8 @@ class TestNonInteractive(unittest.TestCase):
 
     cli_cmd = "java -jar " + os.environ["CLI_JAR"]
 
+    WIREMOCK_HTTPS_PORT = os.environ["WIREMOCK_HTTPS_PORT"]
+
     @classmethod
     def setUpClass(cls):
         TestNonInteractive.wiremock = WiremockClient()
@@ -44,7 +46,7 @@ class TestNonInteractive(unittest.TestCase):
 
     def setUp(self):
         # set default STRATOS_URL
-        os.environ["STRATOS_URL"] = "https://localhost:9443" 
+        os.environ["STRATOS_URL"] = "https://localhost:" + TestNonInteractive.WIREMOCK_HTTPS_PORT
         # ensure other env vars not set
         if 'STRATOS_USERNAME' in os.environ: del os.environ["STRATOS_USERNAME"] # unset env var
         if 'STRATOS_PASSWORD' in os.environ: del os.environ["STRATOS_PASSWORD"] # unset env var

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d1954f6f/components/org.apache.stratos.cli/src/test/python/wiremock.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/test/python/wiremock.py b/components/org.apache.stratos.cli/src/test/python/wiremock.py
index aa81e7f..2990860 100755
--- a/components/org.apache.stratos.cli/src/test/python/wiremock.py
+++ b/components/org.apache.stratos.cli/src/test/python/wiremock.py
@@ -29,11 +29,22 @@ import base64
 
 class WiremockClient():
 
-    reset_url = 'http://localhost:8080/__admin/mappings/reset'
+    HTTP_PORT = os.environ["WIREMOCK_HTTP_PORT"]
 
-    find_url = 'http://localhost:8080/__admin/requests/find'
+    HTTPS_PORT = os.environ["WIREMOCK_HTTPS_PORT"]
 
-    count_url = 'http://localhost:8080/__admin/requests/count'
+    WIREMOCK_JAR = os.environ["WIREMOCK_JAR"]
+
+    if 'WIREMOCK_OPTS' in os.environ: 
+       WIREMOCK_OPTS = os.environ["WIREMOCK_OPTS"]
+    else:
+       WIREMOCK_OPTS = ""
+
+    reset_url = 'http://localhost:' + HTTP_PORT + '/__admin/mappings/reset'
+
+    find_url = 'http://localhost:' + HTTP_PORT + '/__admin/requests/find'
+
+    count_url = 'http://localhost:' + HTTP_PORT + '/__admin/requests/count'
 
     cookies_req_json = '{ "method": "GET", "url": "/stratos/admin/cookie" }'
 
@@ -43,7 +54,7 @@ class WiremockClient():
 
     tenant_deactivate_req_json = '{ "method": "POST", "url": "/stratos/admin/tenant/deactivate/tenant.com" }'
 
-    wiremock = "java -jar " + os.environ["WIREMOCK_JAR"] + " --https-port 9443"
+    wiremock = "java -jar " + WIREMOCK_JAR + " --port " + HTTP_PORT + " --https-port " + HTTPS_PORT + " " + WIREMOCK_OPTS
 
     def start(self):
         # execute wiremock and return handle so it can be torn down