You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/20 14:44:25 UTC

[sling-org-apache-sling-testing-clients] 06/37: SLING-5793 Add client that can leverage hapi client in testing http clients

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

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

commit 0d733dd4eccd337c23a23026f12efc96be98e2e8
Author: Andrei Dulvac <du...@apache.org>
AuthorDate: Thu Jun 16 12:36:48 2016 +0000

    SLING-5793 Add client that can leverage hapi client in testing http clients
    
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1748709 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  6 ++
 .../testing/clients/html/MicrodataClient.java      | 81 ++++++++++++++++++++++
 .../sling/testing/clients/html/package-info.java   | 24 +++++++
 3 files changed, 111 insertions(+)

diff --git a/pom.xml b/pom.xml
index 83e0533..026f356 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,7 @@
                     <instructions>
                         <Export-Package>
                             org.apache.sling.testing.clients,
+                            org.apache.sling.testing.clients.html,
                             org.apache.sling.testing.clients.instance,
                             org.apache.sling.testing.clients.interceptors,
                             org.apache.sling.testing.clients.osgi,
@@ -153,5 +154,10 @@
             <version>4.12</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.hapi.client</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/testing/clients/html/MicrodataClient.java b/src/main/java/org/apache/sling/testing/clients/html/MicrodataClient.java
new file mode 100644
index 0000000..810a28c
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/clients/html/MicrodataClient.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.html;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.sling.hapi.client.HtmlClient;
+import org.apache.sling.hapi.client.microdata.MicrodataDocument;
+import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.SlingClient;
+import org.apache.sling.testing.clients.SlingClientConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.URI;
+
+public class MicrodataClient extends SlingClient implements HtmlClient {
+    protected static final Logger LOG = LoggerFactory.getLogger(MicrodataClient.class);
+
+    public MicrodataClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException {
+        super(http, config);
+    }
+
+    public MicrodataClient(URI url, String user, String password) throws ClientException {
+        super(url, user, password);
+    }
+
+    @Override
+    public MicrodataDocument enter(String url) throws org.apache.sling.hapi.client.ClientException {
+        return get(url);
+    }
+
+    @Override
+    public MicrodataDocument get(String url) throws org.apache.sling.hapi.client.ClientException {
+        try {
+            return newDocument(doGet(url).getContent());
+        } catch (ClientException e) {
+            throw new org.apache.sling.hapi.client.ClientException("Cannot create Microdata document", e);
+        }
+    }
+
+    @Override
+    public MicrodataDocument post(String url, HttpEntity entity) throws org.apache.sling.hapi.client.ClientException {
+        try {
+            return newDocument(doPost(url, entity).getContent());
+        } catch (ClientException e) {
+            throw new org.apache.sling.hapi.client.ClientException("Cannot create Microdata document", e);
+        }
+    }
+
+    @Override
+    public MicrodataDocument delete(String url) throws org.apache.sling.hapi.client.ClientException {
+        try {
+            return newDocument(doDelete(url, null, null).getContent());
+        } catch (ClientException e) {
+            throw new org.apache.sling.hapi.client.ClientException("Cannot create Microdata document", e);
+        }
+    }
+
+    @Override
+    public MicrodataDocument newDocument(String html) {
+        return new MicrodataDocument(html, this, this.getUrl().toString());
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/clients/html/package-info.java b/src/main/java/org/apache/sling/testing/clients/html/package-info.java
new file mode 100644
index 0000000..705d7ac
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/clients/html/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.html;
+
+import aQute.bnd.annotation.Version;
+

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.