blob: d1bfcfc5a8bf0c81c54d4457bfbac9fba92b61bb [file] [log] [blame]
/*
* 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.launchpad.webapp.integrationtest.servlets.post;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.sling.commons.testing.integration.HttpTestBase;
/** Test item copy support by @CopyFrom suffix (SLING-455) */
public class PostServletAtCopyTest extends HttpTestBase {
public static final String TEST_BASE_PATH = "/sling-at-copy-tests";
@Override
protected void setUp() throws Exception {
super.setUp();
}
public void testCopyNodeAbsolute() throws IOException {
final String testPath = TEST_BASE_PATH + "/abs/" + System.currentTimeMillis();
Map<String, String> props = new HashMap<String, String>();
props.put("text", "Hello");
testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
// assert content at source location
final String oldContent = getContent(HTTP_BASE_URL + testPath + "/src.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", oldContent, "out.println(data.text)");
// create dest with text set from src/text
props.clear();
props.put("src@CopyFrom", testPath + "/src");
testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
// assert content at new location
String content = getContent(HTTP_BASE_URL + testPath + "/dest.-1.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", content, "out.println(data.src.text)");
// assert content at old location
String contentOld = getContent(HTTP_BASE_URL + testPath + "/src.-1.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", contentOld, "out.println(data.text)");
}
public void testCopyNodeRelative() throws IOException {
final String testPath = TEST_BASE_PATH + "/rel/" + System.currentTimeMillis();
Map<String, String> props = new HashMap<String, String>();
props.put("text", "Hello");
testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
// assert content at source location
final String oldContent = getContent(HTTP_BASE_URL + testPath + "/src.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", oldContent, "out.println(data.text)");
// create dest with text set from src/text
props.clear();
props.put("src@CopyFrom", "../src");
testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
// assert content at new location
String content = getContent(HTTP_BASE_URL + testPath + "/dest.-1.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", content, "out.println(data.src.text)");
// assert content at old location
String contentOld = getContent(HTTP_BASE_URL + testPath + "/src.-1.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", contentOld, "out.println(data.text)");
}
public void testCopyPropertyAbsolute() throws IOException {
final String testPath = TEST_BASE_PATH + "/abs/" + System.currentTimeMillis();
Map<String, String> props = new HashMap<String, String>();
props.put("text", "Hello");
testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
// assert content at source location
final String oldContent = getContent(HTTP_BASE_URL + testPath + "/src.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", oldContent, "out.println(data.text)");
// create dest with text set from src/text
props.clear();
props.put("text@CopyFrom", testPath + "/src/text");
testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
// assert content at new location
String content = getContent(HTTP_BASE_URL + testPath + "/dest.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", content, "out.println(data.text)");
// assert content at old location
String contentOld = getContent(HTTP_BASE_URL + testPath + "/src.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", contentOld, "out.println(data.text)");
}
public void testCopyPropertyRelative() throws IOException {
final String testPath = TEST_BASE_PATH + "/rel/" + System.currentTimeMillis();
Map<String, String> props = new HashMap<String, String>();
props.put("text", "Hello");
testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
// assert content at source location
final String oldContent = getContent(HTTP_BASE_URL + testPath + "/src.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", oldContent, "out.println(data.text)");
// create dest with text set from src/text
props.clear();
props.put("text@CopyFrom", "../src/text");
testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
// assert content at new location
String content = getContent(HTTP_BASE_URL + testPath + "/dest.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", content, "out.println(data.text)");
// assert content at old location
String contentOld = getContent(HTTP_BASE_URL + testPath + "/src.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", contentOld, "out.println(data.text)");
}
public void testCopyNodeSourceMissing() throws IOException {
final String testPath = TEST_BASE_PATH + "/exist/" + System.currentTimeMillis();
Map<String, String> props = new HashMap<String, String>();
// create dest node
props.clear();
props.put("text", "Hello Destination");
testClient.createNode(HTTP_BASE_URL + testPath + "/dest/src", props);
props.clear();
props.put("src@CopyFrom", testPath + "/non_existing_source");
testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
// expect unmodified dest
String content = getContent(HTTP_BASE_URL + testPath + "/dest.-1.json", CONTENT_TYPE_JSON);
assertJavascript("Hello Destination", content, "out.println(data.src.text)");
}
public void testCopyNodeExistingReplace() throws IOException {
final String testPath = TEST_BASE_PATH + "/replace/" + System.currentTimeMillis();
Map<String, String> props = new HashMap<String, String>();
props.put("text", "Hello");
testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
// create dest node
props.clear();
props.put("text", "Hello Destination");
testClient.createNode(HTTP_BASE_URL + testPath + "/dest/src", props);
props.clear();
props.put("src@CopyFrom", "../src");
testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
// expect unmodified dest
String content = getContent(HTTP_BASE_URL + testPath + "/dest.-1.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", content, "out.println(data.src.text)");
}
public void testCopyNodeDeepRelative() throws IOException {
final String testPath = TEST_BASE_PATH + "/new/" + System.currentTimeMillis();
Map<String, String> props = new HashMap<String, String>();
props.put("text", "Hello");
testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
props.clear();
props.put("deep/new@CopyFrom", "../../src");
testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
// expect new data
String content = getContent(HTTP_BASE_URL + testPath + "/dest.-1.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", content, "out.println(data.deep['new'].text)");
}
public void testCopyNodeDeepAbsolute() throws IOException {
final String testPath = TEST_BASE_PATH + "/new_fail/" + System.currentTimeMillis();
Map<String, String> props = new HashMap<String, String>();
props.put("text", "Hello");
testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
props.clear();
props.put(testPath + "/some/not/existing/structure@CopyFrom", testPath + "/src");
testClient.createNode(HTTP_BASE_URL + testPath + "/*", props);
// expect new data
String content = getContent(HTTP_BASE_URL + testPath + "/some/not/existing/structure.json", CONTENT_TYPE_JSON);
assertJavascript("Hello", content, "out.println(data.text)");
}
}