[ 
https://issues.apache.org/jira/browse/SLING-7511?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16378678#comment-16378678
 ] 

ASF GitHub Bot commented on SLING-7511:
---------------------------------------

rombert commented on a change in pull request #6: SLING-7511: Add importContent 
to SlingClient
URL: 
https://github.com/apache/sling-org-apache-sling-testing-clients/pull/6#discussion_r170942118
 
 

 ##########
 File path: 
src/test/java/org/apache/sling/testing/clients/SlingClientImportContentTest.java
 ##########
 @@ -0,0 +1,118 @@
+/*
+ * 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 org.apache.http.*;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpRequestHandler;
+import org.codehaus.jackson.node.JsonNodeFactory;
+import org.codehaus.jackson.node.ObjectNode;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.util.List;
+
+import static org.apache.http.HttpStatus.SC_BAD_REQUEST;
+import static org.apache.http.HttpStatus.SC_CREATED;
+import static org.apache.http.HttpStatus.SC_OK;
+
+public class SlingClientImportContentTest {
+    private static final String IMPORT_PATH = "/test/import/parent";
+
+    @ClassRule
+    public static HttpServerRule httpServer = new HttpServerRule() {
+        @Override
+        protected void registerHandlers() throws IOException {
+            serverBootstrap.registerHandler(IMPORT_PATH, new 
HttpRequestHandler() {
+                @Override
+                public void handle(HttpRequest request, HttpResponse response, 
HttpContext context) throws HttpException, IOException {
+                    String operation = null;
+                    String content = null;
+                    if (request instanceof HttpEntityEnclosingRequest) {
+                        HttpEntity entity = ((HttpEntityEnclosingRequest) 
request).getEntity();
+                        List<NameValuePair> params = 
URLEncodedUtils.parse(entity);
+                        for (NameValuePair param : params) {
+                            if (param.getName().equals(":operation")) {
+                                operation = param.getValue();
+                            }
+
+                            if (param.getName().equals(":content")) {
+                                content = param.getValue();
+                            }
+                        }
+                    }
+
+                    if (!"import".equals(operation)) {
+                        response.setStatusCode(SC_BAD_REQUEST);
+                        return;
+                    }
+
+                    if 
(!"{\"something\":{\"prop1\":\"val1\"}}".equals(content)) {
+                        System.out.println("Unexpected content: " + content);
+                        response.setStatusCode(SC_BAD_REQUEST);
+                        return;
+                    }
+
+                    response.setStatusCode(SC_CREATED);
+                }
+            });
+        }
+    };
+
+    @Test
+    public void testImportContent() throws Exception {
+        SlingClient c = new SlingClient(httpServer.getURI(), "user", "pass");
+        SlingHttpResponse res = c.importContent(IMPORT_PATH, "json", 
"{\"something\":{\"prop1\":\"val1\"}}");
+    }
+
+    @Test
+    public void testImportJson() throws Exception {
+        ObjectNode node = JsonNodeFactory.instance.objectNode();
+        ObjectNode props = JsonNodeFactory.instance.objectNode();
+        props.put("prop1", "val1");
+
+        node.put("something", props);
+        SlingClient c = new SlingClient(httpServer.getURI(), "user", "pass");
+        SlingHttpResponse res = c.importJson(IMPORT_PATH, node);
+    }
+
+    @Test
+    @Ignore
+    public void testImportRemote() throws ClientException {
 
 Review comment:
   Please don't add ignored tests

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Add importContent to SlingClient
> --------------------------------
>
>                 Key: SLING-7511
>                 URL: https://issues.apache.org/jira/browse/SLING-7511
>             Project: Sling
>          Issue Type: Improvement
>          Components: Apache Sling Testing Clients
>            Reporter: Valentin Olteanu
>            Priority: Major
>
> Add operations specific to 
> [http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#importing-content-structures]
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to