Merge pull request #35 from apache/SLING-11364-more-precise-exceptions-2

SLING-11364 introduce dedicated exception types to separate validation failures, setup failures and IO errors.
diff --git a/src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java b/src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java
index 924f838..1f39545 100644
--- a/src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java
+++ b/src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java
@@ -26,6 +26,8 @@
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.protocol.HttpContext;
+import org.apache.sling.testing.clients.exceptions.TestingIOException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 import org.apache.sling.testing.clients.util.HttpUtils;
 import org.slf4j.LoggerFactory;
 
@@ -224,13 +226,13 @@
      * @throws ClientException if client can't be instantiated
      */
     @SuppressWarnings("unchecked")
-    public <T extends AbstractSlingClient> T adaptTo(Class<T> clientClass) throws ClientException {
+    public <T extends AbstractSlingClient> T adaptTo(Class<T> clientClass) throws TestingValidationException {
         T client;
         try {
             Constructor cons = clientClass.getConstructor(CloseableHttpClient.class, SlingClientConfig.class);
             client = (T) cons.newInstance(this.http, this.config);
         } catch (Exception e) {
-            throw new ClientException("Could not initialize client: '" + clientClass.getCanonicalName() + "'.", e);
+            throw new TestingValidationException("Could not initialize client: '" + clientClass.getCanonicalName() + "'.", e);
         }
         return client;
     }
@@ -338,7 +340,7 @@
 
             return response;
         } catch (IOException e) {
-            throw new ClientException("Could not execute http request", e, request, response);
+            throw new TestingIOException("Could not execute http request", e, request, response);
         }
     }
 
@@ -391,7 +393,7 @@
 
             return response;
         } catch (IOException e) {
-            throw new ClientException("Could not execute http request", e);
+            throw new TestingIOException("Could not execute http request", e);
         }
     }
 
diff --git a/src/main/java/org/apache/sling/testing/clients/ClientException.java b/src/main/java/org/apache/sling/testing/clients/ClientException.java
index e89dbc9..b267561 100644
--- a/src/main/java/org/apache/sling/testing/clients/ClientException.java
+++ b/src/main/java/org/apache/sling/testing/clients/ClientException.java
@@ -19,7 +19,17 @@
 import org.apache.http.client.methods.HttpUriRequest;
 
 /**
- * An exception thrown when something went wrong with using the sling testing clients
+ * An exception thrown when something went wrong with using the sling testing clients.
+ * 
+ * This class will be turned into an abstract class eventually, so do use the specialized
+ * sub-classes instead:
+ * <ul>
+ *   <li>TestingIOException to indicate network and IO problems</li>
+ *   <li>TestingValidationException to indicate a mismatch between expecation and result</li>
+ *   <li>TestingSetupException to indicate problems in the test setup (incorrect parameters etc)</li>
+ * </ul>
+ * 
+ * 
  */
 public class ClientException extends Exception {
 
@@ -28,23 +38,55 @@
     private HttpUriRequest request;
     private SlingHttpResponse response;
 
+    /**
+     * @deprecated use a constructor of one of the subclasses
+     * @param message
+     */
+    @Deprecated
     public ClientException(String message) {
         this(message, null);
     }
 
+    /**
+     * @deprecated use a constructor of one of the subclasses
+     * @param message
+     * @param throwable
+     */
+    @Deprecated
     public ClientException(String message, Throwable throwable) {
         this(message, -1, throwable);
     }
 
+    /**
+     * @deprecated use a constructor of one of the subclasses
+     * @param message
+     * @param httpStatusCode
+     */
+    @Deprecated
     public ClientException(String message, int httpStatusCode) {
         this(message, httpStatusCode, null);
     }
 
+    /**
+     * @deprecated use a constructor of one of the subclasses
+     * @param message
+     * @param httpStatusCode
+     * @param throwable
+     */
+    @Deprecated
     public ClientException(String message, int httpStatusCode, Throwable throwable) {
         super(message, throwable);
         this.httpStatusCode = httpStatusCode;
     }
 
+    /**
+     * @deprecated use a constructor of one of the subclasses
+     * @param message
+     * @param throwable
+     * @param request
+     * @param response
+     */
+    @Deprecated
     public ClientException(String message, Throwable throwable, HttpUriRequest request, SlingHttpResponse response) {
         this(message, throwable);
         this.request = request;
diff --git a/src/main/java/org/apache/sling/testing/clients/SlingClient.java b/src/main/java/org/apache/sling/testing/clients/SlingClient.java
index d0d1bc8..6230857 100644
--- a/src/main/java/org/apache/sling/testing/clients/SlingClient.java
+++ b/src/main/java/org/apache/sling/testing/clients/SlingClient.java
@@ -46,6 +46,7 @@
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.cookie.BasicClientCookie;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 import org.apache.sling.testing.clients.interceptors.DelayRequestInterceptor;
 import org.apache.sling.testing.clients.interceptors.HttpRequestResponseInterceptor;
 import org.apache.sling.testing.clients.interceptors.TestDescriptionInterceptor;
@@ -249,7 +250,7 @@
      */
     @Deprecated
     public void waitUntilExists(final String path, final long waitMillis, int retryCount)
-            throws ClientException, InterruptedException {
+            throws TestingValidationException, InterruptedException {
         AbstractPoller poller =  new AbstractPoller(waitMillis, retryCount) {
             boolean found = false;
             public boolean call() {
@@ -269,7 +270,7 @@
 
         boolean found = poller.callUntilCondition();
         if (!found) {
-            throw new ClientException("path " + path + " does not exist after " + retryCount + " retries");
+            throw new TestingValidationException("path " + path + " does not exist after " + retryCount + " retries");
         }
     }
 
diff --git a/src/main/java/org/apache/sling/testing/clients/SlingClientConfig.java b/src/main/java/org/apache/sling/testing/clients/SlingClientConfig.java
index eb39829..c4a90a6 100644
--- a/src/main/java/org/apache/sling/testing/clients/SlingClientConfig.java
+++ b/src/main/java/org/apache/sling/testing/clients/SlingClientConfig.java
@@ -30,7 +30,7 @@
 import org.apache.http.impl.client.BasicAuthCache;
 import org.apache.http.impl.client.BasicCookieStore;
 import org.apache.http.impl.client.BasicCredentialsProvider;
-
+import org.apache.sling.testing.clients.exceptions.TestingSetupException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Map;
@@ -210,12 +210,12 @@
 
         public SlingClientConfig build() throws ClientException {
             if (!this.url.isAbsolute()) {
-                throw new ClientException("Url must be absolute: " + url);
+                throw new TestingSetupException("Url must be absolute: " + url);
             }
 
             HttpHost targetHost = URIUtils.extractHost(this.url);
             if (targetHost == null) {
-                throw new ClientException("Failed to extract hostname from url " + url);
+                throw new TestingSetupException("Failed to extract hostname from url " + url);
             }
 
             // Create default CredentialsProvider if not set
diff --git a/src/main/java/org/apache/sling/testing/clients/SlingHttpResponse.java b/src/main/java/org/apache/sling/testing/clients/SlingHttpResponse.java
index 4b2404c..6bb813b 100644
--- a/src/main/java/org/apache/sling/testing/clients/SlingHttpResponse.java
+++ b/src/main/java/org/apache/sling/testing/clients/SlingHttpResponse.java
@@ -31,6 +31,7 @@
 import org.apache.http.StatusLine;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.util.EntityUtils;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 
 public class SlingHttpResponse implements CloseableHttpResponse {
 
@@ -79,9 +80,9 @@
      * @param expected the expected http status
      * @throws ClientException if the response does not match the expected
      */
-    public void checkStatus(int expected) throws ClientException {
+    public void checkStatus(int expected) throws TestingValidationException {
         if (this.getStatusLine().getStatusCode() != expected) {
-            throw new ClientException(this + " has wrong response status ("
+            throw new TestingValidationException(this + " has wrong response status ("
                     + this.getStatusLine().getStatusCode() + "). Expected " + expected);
         }
     }
@@ -92,7 +93,7 @@
      * @param expected the expected content type
      * @throws ClientException if the response content type does not match the expected
      */
-    public void checkContentType(String expected) throws ClientException {
+    public void checkContentType(String expected) throws TestingValidationException {
         // Remove whatever follows semicolon in content-type
         String contentType = this.getEntity().getContentType().getValue();
         if (contentType != null) {
@@ -101,7 +102,7 @@
 
         // check for match
         if (!contentType.equals(expected)) {
-            throw new ClientException(this + " has wrong content type (" + contentType + "). Expected " + expected);
+            throw new TestingValidationException(this + " has wrong content type (" + contentType + "). Expected " + expected);
         }
     }
 
@@ -112,7 +113,7 @@
      * @param regexp list of regular expressions
      * @throws ClientException if the response content does not match one of the regexp
      */
-    public void checkContentRegexp(String... regexp) throws ClientException {
+    public void checkContentRegexp(String... regexp) throws TestingValidationException {
         for(String expr : regexp) {
             final Pattern p = Pattern.compile(".*" + expr + ".*");
             boolean matched = false;
@@ -127,7 +128,7 @@
             }
 
             if (!matched) {
-                throw new ClientException("Pattern " + p + " didn't match any line in content. Content is: \n\n" + getContent());
+                throw new TestingValidationException("Pattern " + p + " didn't match any line in content. Content is: \n\n" + getContent());
             }
         }
     }
@@ -138,10 +139,10 @@
      * @param expected list of expected strings
      * @throws ClientException @throws ClientException if the response content does not match one of the strings
      */
-    public void checkContentContains(String... expected) throws ClientException {
+    public void checkContentContains(String... expected) throws TestingValidationException {
         for (String s : expected) {
             if (!this.getContent().contains(s)) {
-                throw new ClientException("Content does not contain string " + s + ". Content is: \n\n" + getContent());
+                throw new TestingValidationException("Content does not contain string " + s + ". Content is: \n\n" + getContent());
             }
         }
     }
diff --git a/src/main/java/org/apache/sling/testing/clients/email/SlingEmailClient.java b/src/main/java/org/apache/sling/testing/clients/email/SlingEmailClient.java
index 8a235e9..969b125 100644
--- a/src/main/java/org/apache/sling/testing/clients/email/SlingEmailClient.java
+++ b/src/main/java/org/apache/sling/testing/clients/email/SlingEmailClient.java
@@ -27,6 +27,7 @@
 import org.apache.sling.testing.clients.SlingClient;
 import org.apache.sling.testing.clients.SlingClientConfig;
 import org.apache.sling.testing.clients.SlingHttpResponse;
+import org.apache.sling.testing.clients.exceptions.TestingIOException;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -74,7 +75,7 @@
             JsonNode configNode = mapper.readTree(mockEmailConfig.getContent());
             return configNode.get("bindPort").intValue();
         } catch (IOException e) {
-            throw new ClientException("Failed retrieving configuration", e);
+            throw new TestingIOException("Failed retrieving configuration", e);
         }
     }
 
@@ -104,7 +105,7 @@
                 emails.add(msg);
             }
         } catch (IOException e) {
-            throw new ClientException("Failed retrieving email messages", e);
+            throw new TestingIOException("Failed retrieving email messages", e);
         }
 
 
diff --git a/src/main/java/org/apache/sling/testing/clients/exceptions/TestingIOException.java b/src/main/java/org/apache/sling/testing/clients/exceptions/TestingIOException.java
new file mode 100644
index 0000000..2d4ec6a
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/clients/exceptions/TestingIOException.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.sling.testing.clients.exceptions;
+
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.SlingHttpResponse;
+
+/**
+ * Use this exception to indicate any problems with networking (typically manifested as 
+ * IOException).
+ */
+public class TestingIOException extends ClientException {
+
+    public TestingIOException(String message) {
+        super(message);
+    }
+
+    public TestingIOException(String message, Throwable throwable) {
+        super(message, throwable);
+    }
+
+    public TestingIOException(String message, int httpStatusCode) {
+        super(message, httpStatusCode);
+    }
+
+    public TestingIOException(String message, int httpStatusCode, Throwable throwable) {
+        super(message, httpStatusCode, throwable);
+    }
+
+    public TestingIOException(String message, Throwable throwable, HttpUriRequest request, SlingHttpResponse response) {
+        super(message, throwable, request, response);
+    }
+}
diff --git a/src/main/java/org/apache/sling/testing/clients/exceptions/TestingSetupException.java b/src/main/java/org/apache/sling/testing/clients/exceptions/TestingSetupException.java
new file mode 100644
index 0000000..a75330f
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/clients/exceptions/TestingSetupException.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.sling.testing.clients.exceptions;
+
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.SlingHttpResponse;
+
+/**
+ * Use this exception to signal problems in the test setup, e.g. incorrect or missing
+ * parameters.
+ */
+public class TestingSetupException extends ClientException {
+
+    public TestingSetupException(String message) {
+        super(message);
+    }
+
+    public TestingSetupException(String message, Throwable throwable) {
+        super(message, throwable);
+    }
+
+    public TestingSetupException(String message, int httpStatusCode) {
+        super(message, httpStatusCode);
+    }
+
+    public TestingSetupException(String message, int httpStatusCode, Throwable throwable) {
+        super(message, httpStatusCode, throwable);
+    }
+
+    public TestingSetupException(String message, Throwable throwable, HttpUriRequest request, SlingHttpResponse response) {
+        super(message, throwable, request, response);
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/testing/clients/exceptions/TestingValidationException.java b/src/main/java/org/apache/sling/testing/clients/exceptions/TestingValidationException.java
new file mode 100644
index 0000000..0627c69
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/clients/exceptions/TestingValidationException.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.sling.testing.clients.exceptions;
+
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.SlingHttpResponse;
+
+/**
+ * Use this exception to indicate any mismatch between expectations and the actual
+ * test result. This exception typically indicates "real" test failures.
+ *
+ */
+public class TestingValidationException extends ClientException {
+
+    public TestingValidationException(String message) {
+        super(message);
+    }
+
+    public TestingValidationException(String message, Throwable throwable) {
+        super(message, throwable);
+    }
+
+    public TestingValidationException(String message, int httpStatusCode) {
+        super(message, httpStatusCode);
+    }
+
+    public TestingValidationException(String message, int httpStatusCode, Throwable throwable) {
+        super(message, httpStatusCode, throwable);
+    }
+
+    public TestingValidationException(String message, Throwable throwable, HttpUriRequest request, SlingHttpResponse response) {
+        super(message, throwable, request, response);
+    }
+}
diff --git a/src/main/java/org/apache/sling/testing/clients/exceptions/package-info.java b/src/main/java/org/apache/sling/testing/clients/exceptions/package-info.java
new file mode 100644
index 0000000..30161fe
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/clients/exceptions/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+@Version("1.0.0")
+package org.apache.sling.testing.clients.exceptions;
+
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/testing/clients/indexing/IndexingClient.java b/src/main/java/org/apache/sling/testing/clients/indexing/IndexingClient.java
index 1af1e4a..ad7e211 100644
--- a/src/main/java/org/apache/sling/testing/clients/indexing/IndexingClient.java
+++ b/src/main/java/org/apache/sling/testing/clients/indexing/IndexingClient.java
@@ -23,6 +23,7 @@
 import org.apache.sling.testing.clients.ClientException;
 import org.apache.sling.testing.clients.SlingClient;
 import org.apache.sling.testing.clients.SlingClientConfig;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 import org.apache.sling.testing.clients.osgi.OsgiConsoleClient;
 import org.apache.sling.testing.clients.query.QueryClient;
 import org.apache.sling.testing.clients.util.poller.Polling;
@@ -190,7 +191,7 @@
      * Else, retrieves configured lanes on the instance
      *
      * @return list of lane names
-     * @throws ClientException if the request fails
+     * @throws ClientException 
      */
     public List<String> getLaneNames() throws ClientException {
         List<String> configuredLanes = getConfiguredLaneNames();
@@ -202,7 +203,7 @@
         if (configs instanceof String[]) {
             return Stream.of((String[]) configs).map(e -> e.split(":")[0]).collect(Collectors.toList());
         } else {
-            throw new ClientException("Cannot retrieve config from AsyncIndexerService, asyncConfigs is not a String[]");
+            throw new TestingValidationException("Cannot retrieve config from AsyncIndexerService, asyncConfigs is not a String[]");
         }
     }
 
diff --git a/src/main/java/org/apache/sling/testing/clients/osgi/BundleInfo.java b/src/main/java/org/apache/sling/testing/clients/osgi/BundleInfo.java
index 1d8d0b5..ffef1a2 100644
--- a/src/main/java/org/apache/sling/testing/clients/osgi/BundleInfo.java
+++ b/src/main/java/org/apache/sling/testing/clients/osgi/BundleInfo.java
@@ -18,7 +18,7 @@
 package org.apache.sling.testing.clients.osgi;
 
 import com.fasterxml.jackson.databind.JsonNode;
-import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -28,15 +28,15 @@
 
     private JsonNode bundle;
 
-    public BundleInfo(JsonNode root) throws ClientException {
+    public BundleInfo(JsonNode root) throws TestingValidationException {
         if (root.get("id") != null) {
             if (root.get("id") == null) {
-                throw new ClientException("No Bundle Info returned");
+                throw new TestingValidationException("No Bundle Info returned");
             }
             bundle = root;
         } else {
             if (root.get("data") == null && root.get("data").size() < 1) {
-                throw new ClientException("No Bundle Info returned");
+                throw new TestingValidationException("No Bundle Info returned");
             }
             bundle = root.get("data").get(0);
         }
diff --git a/src/main/java/org/apache/sling/testing/clients/osgi/BundlesInfo.java b/src/main/java/org/apache/sling/testing/clients/osgi/BundlesInfo.java
index eb47093..23e802e 100644
--- a/src/main/java/org/apache/sling/testing/clients/osgi/BundlesInfo.java
+++ b/src/main/java/org/apache/sling/testing/clients/osgi/BundlesInfo.java
@@ -19,6 +19,7 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 
 import java.util.Iterator;
 
@@ -37,13 +38,13 @@
      * @param root the root JSON node of the bundles info.
      * @throws ClientException if the json does not contain the proper info
      */
-    public BundlesInfo(JsonNode root) throws ClientException {
+    public BundlesInfo(JsonNode root) throws TestingValidationException {
         this.root = root;
         // some simple sanity checks
         if (root.get("s") == null)
-            throw new ClientException("No Status Info returned!");
+            throw new TestingValidationException("No Status Info returned!");
         if (root.get("s").size() != 5)
-            throw new ClientException("Wrong number of status numbers listed!");
+            throw new TestingValidationException("Wrong number of status numbers listed!");
         status = root.get("s");
     }
 
@@ -51,9 +52,9 @@
      * @return the status message of the bundle context
      * @throws ClientException if the request cannot be completed
      */
-    public String getStatusMessage() throws ClientException {
+    public String getStatusMessage() throws TestingValidationException {
         if (root.get("status") == null)
-            throw new ClientException("No Status message returned!");
+            throw new TestingValidationException("No Status message returned!");
         return root.get("status").asText();
     }
 
diff --git a/src/main/java/org/apache/sling/testing/clients/osgi/BundlesInstaller.java b/src/main/java/org/apache/sling/testing/clients/osgi/BundlesInstaller.java
index bf342a6..06efc63 100644
--- a/src/main/java/org/apache/sling/testing/clients/osgi/BundlesInstaller.java
+++ b/src/main/java/org/apache/sling/testing/clients/osgi/BundlesInstaller.java
@@ -17,6 +17,7 @@
 package org.apache.sling.testing.clients.osgi;
 
 import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 import org.apache.sling.testing.clients.util.poller.Polling;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -59,7 +60,7 @@
             return false;
         } catch (IOException e) {
             log.debug("Failed to retrieve bundle symbolic name from file. ", e);
-            throw new ClientException("Failed to retrieve bundle symbolic name from file. ", e);
+            throw new TestingValidationException("Failed to retrieve bundle symbolic name from file. ", e);
         }
     }
 
diff --git a/src/main/java/org/apache/sling/testing/clients/osgi/ComponentInfo.java b/src/main/java/org/apache/sling/testing/clients/osgi/ComponentInfo.java
index 50b7e9d..1618ad0 100644
--- a/src/main/java/org/apache/sling/testing/clients/osgi/ComponentInfo.java
+++ b/src/main/java/org/apache/sling/testing/clients/osgi/ComponentInfo.java
@@ -19,20 +19,21 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 
 public class ComponentInfo {
 
     private JsonNode component;
 
-    public ComponentInfo(JsonNode root) throws ClientException {
+    public ComponentInfo(JsonNode root) throws TestingValidationException {
         if (root.get("id") != null) {
             if (root.get("id") == null) {
-                throw new ClientException("No Component Info returned");
+                throw new TestingValidationException("No Component Info returned");
             }
             component = root;
         } else {
             if (root.get("data") == null && root.get("data").size() < 1) {
-                throw new ClientException("No Component Info returned");
+                throw new TestingValidationException("No Component Info returned");
             }
             component = root.get("data").get(0);
         }
diff --git a/src/main/java/org/apache/sling/testing/clients/osgi/ComponentsInfo.java b/src/main/java/org/apache/sling/testing/clients/osgi/ComponentsInfo.java
index 9770cc1..20420f7 100644
--- a/src/main/java/org/apache/sling/testing/clients/osgi/ComponentsInfo.java
+++ b/src/main/java/org/apache/sling/testing/clients/osgi/ComponentsInfo.java
@@ -19,6 +19,7 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 
 import java.util.Iterator;
 
@@ -36,7 +37,7 @@
      * @param rootNode the root JSON node of the components info.
      * @throws ClientException if the info cannot be retrieved
      */
-    public ComponentsInfo(JsonNode rootNode) throws ClientException {
+    public ComponentsInfo(JsonNode rootNode) {
         this.root = rootNode;
     }
 
@@ -44,9 +45,9 @@
      * @return the number of installed components
      * @throws ClientException if the info cannot be retrieved
      */
-    public int getNumberOfInstalledComponents() throws ClientException {
+    public int getNumberOfInstalledComponents() throws TestingValidationException {
         if (root.get("status") == null)
-            throw new ClientException("Number of installed Components not defined!");
+            throw new TestingValidationException("Number of installed Components not defined!");
         return Integer.parseInt(root.get("status").asText());
     }
 
@@ -55,7 +56,7 @@
      * @return the ComponentInfo for a component with the identifier {@code id}
      * @throws ClientException if the info cannot be retrieved
      */
-    public ComponentInfo forId(String id) throws ClientException {
+    public ComponentInfo forId(String id) throws TestingValidationException {
         JsonNode component = findBy("id", id);
         return (component != null) ? new ComponentInfo(component) : null;
     }
@@ -65,7 +66,7 @@
      * @return the ComponentInfo for a component with the name {@code name}
      * @throws ClientException if the info cannot be retrieved
      */
-    public ComponentInfo forName(String name) throws ClientException {
+    public ComponentInfo forName(String name) throws TestingValidationException {
         JsonNode component = findBy("name", name);
         return (component != null) ? new ComponentInfo(component) : null;
     }
@@ -75,7 +76,7 @@
      * @return the ComponentInfo for a component with the pid {@code pid}
      * @throws ClientException if the info cannot be retrieved
      */
-    public ComponentInfo forPid(String pid) throws ClientException {
+    public ComponentInfo forPid(String pid) throws TestingValidationException {
         JsonNode component = findBy("pid", pid);
         return (component != null) ? new ComponentInfo(component) : null;
     }
diff --git a/src/main/java/org/apache/sling/testing/clients/osgi/OsgiConsoleClient.java b/src/main/java/org/apache/sling/testing/clients/osgi/OsgiConsoleClient.java
index b3fdfea..303bf20 100644
--- a/src/main/java/org/apache/sling/testing/clients/osgi/OsgiConsoleClient.java
+++ b/src/main/java/org/apache/sling/testing/clients/osgi/OsgiConsoleClient.java
@@ -25,6 +25,8 @@
 import org.apache.sling.testing.clients.SlingClient;
 import org.apache.sling.testing.clients.SlingClientConfig;
 import org.apache.sling.testing.clients.SlingHttpResponse;
+import org.apache.sling.testing.clients.exceptions.TestingIOException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 import org.apache.sling.testing.clients.util.FormEntityBuilder;
 import org.apache.sling.testing.clients.util.HttpUtils;
 import org.apache.sling.testing.clients.util.JsonUtils;
@@ -388,12 +390,12 @@
      */
     @Deprecated
     public Map<String, Object> getConfigurationWithWait(long waitCount, String pid, int... expectedStatus)
-            throws ClientException, InterruptedException {
+            throws TestingValidationException, InterruptedException {
         ConfigurationPoller poller = new ConfigurationPoller(pid, expectedStatus);
         try {
             poller.poll(500L * waitCount, 500);
         } catch (TimeoutException e) {
-            throw new ClientException("Cannot retrieve configuration.", e);
+            throw new TestingValidationException("Cannot retrieve configuration.", e);
         }
         return poller.getConfig();
     }
@@ -626,7 +628,7 @@
         try {
             return this.checkBundleInstalled(OsgiConsoleClient.getBundleSymbolicName(f), waitTime, retries);
         } catch (IOException e) {
-            throw new ClientException("Cannot get bundle symbolic name", e);
+            throw new TestingIOException("Cannot get bundle symbolic name", e);
         }
     }
 
@@ -648,7 +650,7 @@
         try {
             waitBundleInstalled(getBundleSymbolicName(f), timeout, delay);
         } catch (IOException e) {
-            throw new ClientException("Cannot get bundle symbolic name", e);
+            throw new TestingIOException("Cannot get bundle symbolic name", e);
         }
     }
 
@@ -724,7 +726,7 @@
         final JsonNode idNode = bundle.get(JSON_KEY_ID);
 
         if (idNode == null) {
-            throw new ClientException("Cannot get id from bundle json");
+            throw new TestingValidationException("Cannot get id from bundle json");
         }
 
         return idNode.longValue();
@@ -741,7 +743,7 @@
         final JsonNode versionNode = bundle.get(JSON_KEY_VERSION);
 
         if (versionNode == null) {
-            throw new ClientException("Cannot get version from bundle json");
+            throw new TestingValidationException("Cannot get version from bundle json");
         }
 
         return versionNode.textValue();
@@ -758,7 +760,7 @@
         final JsonNode stateNode = bundle.get(JSON_KEY_STATE);
 
         if (stateNode == null) {
-            throw new ClientException("Cannot get state from bundle json");
+            throw new TestingValidationException("Cannot get state from bundle json");
         }
 
         return stateNode.textValue();
@@ -871,17 +873,17 @@
         final JsonNode root = JsonUtils.getJsonNodeFromString(content);
 
         if (root.get(JSON_KEY_DATA) == null) {
-            throw new ClientException(path + " does not provide '" + JSON_KEY_DATA + "' element, JSON content=" + content);
+            throw new TestingValidationException(path + " does not provide '" + JSON_KEY_DATA + "' element, JSON content=" + content);
         }
 
         Iterator<JsonNode> data = root.get(JSON_KEY_DATA).elements();
         if (!data.hasNext()) {
-            throw new ClientException(path + "." + JSON_KEY_DATA + " is empty, JSON content=" + content);
+            throw new TestingValidationException(path + "." + JSON_KEY_DATA + " is empty, JSON content=" + content);
         }
 
         final JsonNode bundle = data.next();
         if (bundle.get(JSON_KEY_STATE) == null) {
-            throw new ClientException(path + ".data[0].state missing, JSON content=" + content);
+            throw new TestingValidationException(path + ".data[0].state missing, JSON content=" + content);
         }
 
         return bundle;
diff --git a/src/main/java/org/apache/sling/testing/clients/osgi/ServiceInfo.java b/src/main/java/org/apache/sling/testing/clients/osgi/ServiceInfo.java
index 6fcb050..e19f3fb 100644
--- a/src/main/java/org/apache/sling/testing/clients/osgi/ServiceInfo.java
+++ b/src/main/java/org/apache/sling/testing/clients/osgi/ServiceInfo.java
@@ -19,6 +19,7 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 
 import java.util.List;
 
@@ -26,12 +27,12 @@
 
     private JsonNode service;
 
-    public ServiceInfo(JsonNode root) throws ClientException {
+    public ServiceInfo(JsonNode root) throws TestingValidationException {
         if(root.get("id") != null) {
             service = root;
         } else {
             if(root.get("data") == null && root.get("data").size() < 1) {
-                throw new ClientException("No service info returned");
+                throw new TestingValidationException("No service info returned");
             }
             service = root.get("data").get(0);
         }
diff --git a/src/main/java/org/apache/sling/testing/clients/osgi/ServicesInfo.java b/src/main/java/org/apache/sling/testing/clients/osgi/ServicesInfo.java
index ce25aed..e99f329 100644
--- a/src/main/java/org/apache/sling/testing/clients/osgi/ServicesInfo.java
+++ b/src/main/java/org/apache/sling/testing/clients/osgi/ServicesInfo.java
@@ -18,7 +18,7 @@
 package org.apache.sling.testing.clients.osgi;
 
 import com.fasterxml.jackson.databind.JsonNode;
-import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -40,13 +40,13 @@
      * @param root the root JSON node of the bundles info.
      * @throws ClientException if the json does not contain the proper info
      */
-    public ServicesInfo(JsonNode root) throws ClientException {
+    public ServicesInfo(JsonNode root) throws TestingValidationException {
         this.root = root;
         // some simple sanity checks
         if (root.get("status") == null)
-            throw new ClientException("No Status returned!");
+            throw new TestingValidationException("No Status returned!");
         if (root.get("serviceCount") == null)
-            throw new ClientException("No serviceCount returned!");
+            throw new TestingValidationException("No serviceCount returned!");
     }
 
     /**
@@ -63,7 +63,7 @@
      * @return the BundleInfo
      * @throws ClientException if the info could not be retrieved
      */
-    public ServiceInfo forId(String id) throws ClientException {
+    public ServiceInfo forId(String id) throws TestingValidationException {
         JsonNode serviceInfo = findBy("id", id);
         return (serviceInfo != null) ? new ServiceInfo(serviceInfo) : null;
     }
@@ -75,7 +75,7 @@
      * @return a Collection of {@link ServiceInfo}s of all services with the given type. Might be empty, never {@code null}
      * @throws ClientException if the info cannot be retrieved
      */
-    public Collection<ServiceInfo> forType(String type) throws ClientException {
+    public Collection<ServiceInfo> forType(String type)throws TestingValidationException {
         List<ServiceInfo> results = new LinkedList<>();
         List<JsonNode> serviceInfoNodes = findAllContainingValueInArray("types", type);
         for (JsonNode serviceInfoNode : serviceInfoNodes) {
diff --git a/src/main/java/org/apache/sling/testing/clients/query/QueryClient.java b/src/main/java/org/apache/sling/testing/clients/query/QueryClient.java
index f81eaee..229e029 100644
--- a/src/main/java/org/apache/sling/testing/clients/query/QueryClient.java
+++ b/src/main/java/org/apache/sling/testing/clients/query/QueryClient.java
@@ -23,6 +23,8 @@
 import org.apache.sling.testing.clients.SlingClient;
 import org.apache.sling.testing.clients.SlingClientConfig;
 import org.apache.sling.testing.clients.SlingHttpResponse;
+import org.apache.sling.testing.clients.exceptions.TestingIOException;
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 import org.apache.sling.testing.clients.osgi.OsgiConsoleClient;
 import org.apache.sling.testing.clients.query.servlet.QueryServlet;
 import org.apache.sling.testing.clients.util.JsonUtils;
@@ -203,9 +205,9 @@
 
             LOG.info("query servlet installed at {}", getUrl(QueryServlet.SERVLET_PATH));
         } catch (IOException e) {
-            throw new ClientException("Failed to create the query servlet bundle", e);
+            throw new TestingIOException("Failed to create the query servlet bundle", e);
         } catch (TimeoutException e) {
-            throw new ClientException("The query servlet bundle did not successfully start", e);
+            throw new TestingValidationException("The query servlet bundle did not successfully start", e);
         }
 
         return this;
diff --git a/src/main/java/org/apache/sling/testing/clients/util/HttpUtils.java b/src/main/java/org/apache/sling/testing/clients/util/HttpUtils.java
index ba17460..c4bff07 100644
--- a/src/main/java/org/apache/sling/testing/clients/util/HttpUtils.java
+++ b/src/main/java/org/apache/sling/testing/clients/util/HttpUtils.java
@@ -20,7 +20,7 @@
 import org.apache.http.HttpResponse;
 import org.apache.sling.testing.clients.ClientException;
 import org.apache.sling.testing.clients.SlingHttpResponse;
-
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
 
 import java.net.URI;
 
@@ -35,7 +35,7 @@
      * @param expectedStatus List of acceptable HTTP Statuses
      * @throws ClientException if status is not expected
      */
-    public static void verifyHttpStatus(SlingHttpResponse response, int... expectedStatus) throws ClientException {
+    public static void verifyHttpStatus(SlingHttpResponse response, int... expectedStatus) throws TestingValidationException {
         if (!checkStatus(response, expectedStatus)) {
             throwError(response, buildDefaultErrorMessage(response), expectedStatus);
         }
@@ -50,14 +50,13 @@
      * @throws ClientException if status is not expected
      */
     public static void verifyHttpStatus(HttpResponse response, String errorMessage, int... expectedStatus)
-            throws ClientException {
+            throws TestingValidationException {
         if (!checkStatus(response, expectedStatus)) {
             throwError(response, errorMessage, expectedStatus);
         }
     }
 
-    private static boolean checkStatus(HttpResponse response, int... expectedStatus)
-            throws ClientException {
+    private static boolean checkStatus(HttpResponse response, int... expectedStatus) {
 
         // if no HttpResponse was given
         if (response == null) {
@@ -83,7 +82,7 @@
     }
 
     private static boolean throwError(HttpResponse response, String errorMessage, int... expectedStatus)
-            throws ClientException {
+            throws TestingValidationException {
         // build error message
         String errorMsg = "Expected HTTP Status: ";
         for (int expected : expectedStatus) {
@@ -99,7 +98,7 @@
         }
 
         // throw the exception
-        throw new ClientException(errorMsg, givenStatus);
+        throw new TestingValidationException(errorMsg, givenStatus);
     }
 
 
@@ -133,7 +132,7 @@
      * @return The HTTP Status of the response
      * @throws ClientException never (kept for uniformity)
      */
-    public static int getHttpStatus(HttpResponse response) throws ClientException {
+    public static int getHttpStatus(HttpResponse response) {
         return response.getStatusLine().getStatusCode();
     }
 
@@ -144,8 +143,8 @@
      * @return the location path
      * @throws ClientException never (kept for uniformity)
      */
-    public static String getLocationHeader(HttpResponse response) throws ClientException {
-        if (response == null) throw new ClientException("Response must not be null!");
+    public static String getLocationHeader(HttpResponse response) throws TestingValidationException {
+        if (response == null) throw new TestingValidationException("Response must not be null!");
 
         String locationPath = null;
         Header locationHeader = response.getFirstHeader("Location");
@@ -156,7 +155,7 @@
         }
 
         if (locationPath == null) {
-            throw new ClientException("not able to determine location path");
+            throw new TestingValidationException("not able to determine location path");
         }
         return locationPath;
     }
diff --git a/src/main/java/org/apache/sling/testing/clients/util/InputStreamBodyWithLength.java b/src/main/java/org/apache/sling/testing/clients/util/InputStreamBodyWithLength.java
index 36361ef..19b24e2 100644
--- a/src/main/java/org/apache/sling/testing/clients/util/InputStreamBodyWithLength.java
+++ b/src/main/java/org/apache/sling/testing/clients/util/InputStreamBodyWithLength.java
@@ -19,6 +19,7 @@
 import org.apache.http.entity.ContentType;
 import org.apache.http.entity.mime.content.InputStreamBody;
 import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.exceptions.TestingIOException;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -47,7 +48,7 @@
      * @param resourcePath path to the file
      * @return the size of the resource
      */
-    private static long getResourceStreamLength(String resourcePath) throws ClientException {
+    private static long getResourceStreamLength(String resourcePath) throws TestingIOException {
         int streamLength = 0;
         InputStream stream = ResourceUtil.getResourceAsStream(resourcePath);
         try {
@@ -56,12 +57,12 @@
                 stream.skip(avail);
             }
         } catch (IOException e) {
-            throw new ClientException("Could not read " + resourcePath + "!", e);
+            throw new TestingIOException("Could not read " + resourcePath + "!", e);
         } finally {
             try {
                 stream.close();
             } catch (IOException e) {
-                throw new ClientException("Could not close Inputstream for " + resourcePath + "!", e);
+                // ignore
             }
         }
         return streamLength;
diff --git a/src/main/java/org/apache/sling/testing/clients/util/JsonUtils.java b/src/main/java/org/apache/sling/testing/clients/util/JsonUtils.java
index 6007f96..d77d833 100644
--- a/src/main/java/org/apache/sling/testing/clients/util/JsonUtils.java
+++ b/src/main/java/org/apache/sling/testing/clients/util/JsonUtils.java
@@ -19,6 +19,7 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.exceptions.TestingIOException;
 
 import java.io.IOException;
 
@@ -30,12 +31,12 @@
      * @return A {@link JsonNode} that is the root node of the JSON structure.
      * @throws ClientException if error occurs while reading json string
      */
-    public static JsonNode getJsonNodeFromString(String jsonString) throws ClientException {
+    public static JsonNode getJsonNodeFromString(String jsonString) throws TestingIOException {
         try {
             ObjectMapper mapper = new ObjectMapper();
             return mapper.readTree(jsonString);
         } catch (IOException e) {
-            throw new ClientException("Could not read json node.", e);
+            throw new TestingIOException("Could not read json node.", e);
         }
     }
 }
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/testing/clients/SlingClientExceptions.java b/src/test/java/org/apache/sling/testing/clients/SlingClientExceptions.java
new file mode 100644
index 0000000..153956c
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/clients/SlingClientExceptions.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You 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.apache.sling.testing.clients;
+
+import java.io.IOException;
+
+import org.apache.sling.testing.clients.exceptions.TestingValidationException;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+public class SlingClientExceptions {
+
+    private static final String ERROR_PATH = "/content/missingResource.json";
+
+    @ClassRule
+    public static HttpServerRule httpServer = new HttpServerRule() {
+        @Override
+        protected void registerHandlers() throws IOException {
+            serverBootstrap.registerHandler( ERROR_PATH, (request, response, context) -> {
+                response.setStatusCode(500);
+            });
+        }
+    };
+
+    @Test(expected = TestingValidationException.class)
+    public void testDoGetError() throws Exception {
+        SlingClient c = new SlingClient(httpServer.getURI(), "user", "pass");
+        c.doGet(ERROR_PATH, 200);
+    }
+
+}
\ No newline at end of file