You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2018/09/04 14:25:57 UTC

[sling-whiteboard] branch master updated: Factor out credentials and cleanup

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new ccc39c5  Factor out credentials and cleanup
ccc39c5 is described below

commit ccc39c5522762a2ecb0884d06d23db0e704bb293
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Sep 4 16:25:48 2018 +0200

    Factor out credentials and cleanup
---
 .../java/sling/filestorage/uploadImage.feature     | 33 ++++++----------------
 .../createcontent/createContent.feature            | 33 ++++++----------------
 .../createcontent/importContent.feature            | 19 +++++++------
 .../src/test/java/sling/util/basic-auth-header.js  |  5 ----
 .../src/test/java/util/basic-auth-header.js        |  9 ++++++
 .../test/java/util/cleanup-test-content.feature    | 25 ++++++++++++++++
 .../src/test/java/util/sling-ready.feature         | 19 +++++++++++++
 7 files changed, 81 insertions(+), 62 deletions(-)

diff --git a/karate-http-testing/src/test/java/sling/filestorage/uploadImage.feature b/karate-http-testing/src/test/java/sling/filestorage/uploadImage.feature
index 9a1f1cd..f16f310 100644
--- a/karate-http-testing/src/test/java/sling/filestorage/uploadImage.feature
+++ b/karate-http-testing/src/test/java/sling/filestorage/uploadImage.feature
@@ -9,18 +9,14 @@ Background:
 * url baseURL
 
 # Use admin credentials for all requests
-* configure headers = call read('classpath:sling/util/basic-auth-header.js') { username: 'admin', password: 'admin' }
+* configure headers = call read('classpath:util/basic-auth-header.js')
 
 * def testID = '' + java.util.UUID.randomUUID()
 * def testFolderPath = '/uploadImageTest/folder_' + testID
 * def filename = 'file_' + testID
 
-# ------------------------------------------------------------------------
-Scenario: Check access to the Sling instance under test
-# ------------------------------------------------------------------------
-Given path '/.json'
-When method GET
-Then status 200
+# Sling instance ready?
+* def unused = call read('classpath:util/sling-ready.feature')
 
 # ------------------------------------------------------------------------
 Scenario: Upload an image, read back and check
@@ -45,20 +41,9 @@ And match response.name == filename
 And match response.file.jcr:primaryType == 'nt:resource'
 And match response.file.jcr:mimeType == 'application/octet-stream'
 
-# Delete and verify that the resource is gone
-Given path imagePath
-When method DELETE
-Then status 204
-
-Given path imagePath
-When method GET
-Then status 404
-
-# Cleanup test folder
-Given path testFolderPath
-When method DELETE
-Then status 204
-
-Given path testFolderPath
-When method GET
-Then status 404
\ No newline at end of file
+# Cleanup test content
+* table paths
+  | path |
+  | imagePath |
+  | testFolderPath |
+* def result = call read('classpath:util/cleanup-test-content.feature') paths
\ No newline at end of file
diff --git a/karate-http-testing/src/test/java/sling/postservlet/createcontent/createContent.feature b/karate-http-testing/src/test/java/sling/postservlet/createcontent/createContent.feature
index d5164b0..fefece0 100644
--- a/karate-http-testing/src/test/java/sling/postservlet/createcontent/createContent.feature
+++ b/karate-http-testing/src/test/java/sling/postservlet/createcontent/createContent.feature
@@ -9,17 +9,13 @@ Background:
 * url baseURL
 
 # Use admin credentials for all requests
-* configure headers = call read('classpath:sling/util/basic-auth-header.js') { username: 'admin', password: 'admin' }
+* configure headers = call read('classpath:util/basic-auth-header.js')
 
 * def testID = '' + java.util.UUID.randomUUID()
 * def testFolderPath = '/createContentTest/' + testID
 
-# ------------------------------------------------------------------------
-Scenario: Check access to the Sling instance under test
-# ------------------------------------------------------------------------
-Given path '/.json'
-When method GET
-Then status 200
+# Sling instance ready?
+* def unused = call read('classpath:util/sling-ready.feature')
 
 # ------------------------------------------------------------------------
 Scenario: Create a resource, update, read back, delete
@@ -57,20 +53,9 @@ And match response.f1 == 'v1A' + testID
 And match response.f2 == 'v2B'
 And match response.f3 == 'v3B'
 
-# Delete and verify that the resource is gone
-Given path resourcePath
-When method DELETE
-Then status 204
-
-Given path resourcePath
-When method GET
-Then status 404
-
-# Cleanup test folder
-Given path testFolderPath
-When method DELETE
-Then status 204
-
-Given path testFolderPath
-When method GET
-Then status 404
\ No newline at end of file
+# Cleanup test content
+* table paths
+  | path |
+  | resourcePath |
+  | testFolderPath |
+* def result = call read('classpath:util/cleanup-test-content.feature') paths
\ No newline at end of file
diff --git a/karate-http-testing/src/test/java/sling/postservlet/createcontent/importContent.feature b/karate-http-testing/src/test/java/sling/postservlet/createcontent/importContent.feature
index 05fa7e0..3cebd0b 100644
--- a/karate-http-testing/src/test/java/sling/postservlet/createcontent/importContent.feature
+++ b/karate-http-testing/src/test/java/sling/postservlet/createcontent/importContent.feature
@@ -6,11 +6,14 @@ Background:
 * url baseURL
 
 # Use admin credentials for all requests
-* configure headers = call read('classpath:sling/util/basic-auth-header.js') { username: 'admin', password: 'admin' }
+* configure headers = call read('classpath:util/basic-auth-header.js')
 
 * def testID = '' + java.util.UUID.randomUUID()
 * def testFolderPath = 'importContentTest/' + testID
 
+# Sling instance ready?
+* def unused = call read('classpath:util/sling-ready.feature')
+
 # ------------------------------------------------------------------------
 Scenario: Create the parent folder, import JSON content, verify and delete
 # ------------------------------------------------------------------------
@@ -47,11 +50,9 @@ Then status 200
 And match $ == newContent
 And match $.p2[2] == testID
 
-# Delete parent folder
-Given path testFolderPath, testID
-When method DELETE
-Then status 204
-
-Given path testFolderPath, testID
-When method GET
-Then status 404
\ No newline at end of file
+# Cleanup test content
+* table paths
+  | path |
+  | testFolderPath + '/' + testID |
+  | testFolderPath |
+* def result = call read('classpath:util/cleanup-test-content.feature') paths
\ No newline at end of file
diff --git a/karate-http-testing/src/test/java/sling/util/basic-auth-header.js b/karate-http-testing/src/test/java/sling/util/basic-auth-header.js
deleted file mode 100644
index a1b93f6..0000000
--- a/karate-http-testing/src/test/java/sling/util/basic-auth-header.js
+++ /dev/null
@@ -1,5 +0,0 @@
-function(creds) {
-  var temp = creds.username + ':' + creds.password;
-  var encoded = Java.type('java.util.Base64').getEncoder().encodeToString(temp.bytes);
-  return { 'Authorization' : 'Basic ' + encoded }
-}
diff --git a/karate-http-testing/src/test/java/util/basic-auth-header.js b/karate-http-testing/src/test/java/util/basic-auth-header.js
new file mode 100644
index 0000000..472c3f2
--- /dev/null
+++ b/karate-http-testing/src/test/java/util/basic-auth-header.js
@@ -0,0 +1,9 @@
+function(creds) {
+  // Return Authorization header with basic auth, defaults to admin/admin
+  if(!creds) {
+    creds = { username: 'admin', password: 'admin' }
+  }
+  var temp = creds.username + ':' + creds.password
+  var encoded = Java.type('java.util.Base64').getEncoder().encodeToString(temp.bytes);
+  return { 'Authorization' : 'Basic ' + encoded }
+}
diff --git a/karate-http-testing/src/test/java/util/cleanup-test-content.feature b/karate-http-testing/src/test/java/util/cleanup-test-content.feature
new file mode 100644
index 0000000..b55c399
--- /dev/null
+++ b/karate-http-testing/src/test/java/util/cleanup-test-content.feature
@@ -0,0 +1,25 @@
+# ------------------------------------------------------------------------
+Feature: Cleanup content by DELETEing a set of paths
+# The 'path' parameter must be passed in when calling, optionally
+# using a table to delete multiple paths
+# ------------------------------------------------------------------------
+
+# ------------------------------------------------------------------------
+Background:
+# ------------------------------------------------------------------------
+
+* url baseURL
+
+# Use admin credentials for all requests
+* configure headers = call read('classpath:util/basic-auth-header.js')
+
+# ------------------------------------------------------------------------
+Scenario: Delete a given path and verify that it's gone
+# ------------------------------------------------------------------------
+Given path path
+When method DELETE
+Then status 204
+
+Given path path
+When method GET
+Then status 404
diff --git a/karate-http-testing/src/test/java/util/sling-ready.feature b/karate-http-testing/src/test/java/util/sling-ready.feature
new file mode 100644
index 0000000..947be66
--- /dev/null
+++ b/karate-http-testing/src/test/java/util/sling-ready.feature
@@ -0,0 +1,19 @@
+# ------------------------------------------------------------------------
+Feature: Check access to the Sling instance under test
+# ------------------------------------------------------------------------
+
+# ------------------------------------------------------------------------
+Background:
+# ------------------------------------------------------------------------
+
+* url baseURL
+
+# Use admin credentials for all requests
+* configure headers = call read('classpath:util/basic-auth-header.js')
+
+# ------------------------------------------------------------------------
+Scenario: Check access to HTTP root
+# ------------------------------------------------------------------------
+Given path '/.json'
+When method GET
+Then status 200