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
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;
+