001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.lenya.cms.site.usecases;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import org.apache.lenya.cms.publication.Area;
024: import org.apache.lenya.cms.publication.Document;
025: import org.apache.lenya.cms.publication.DocumentLocator;
026: import org.apache.lenya.cms.publication.DocumentManager;
027: import org.apache.lenya.cms.site.SiteNode;
028: import org.apache.lenya.cms.site.SiteStructure;
029: import org.apache.lenya.cms.usecase.AbstractUsecaseTest;
030:
031: /**
032: * Test class for moving subsites to a different area.
033: */
034: public class MoveSubsiteTest extends AbstractUsecaseTest {
035:
036: protected static final String PATH = "/foo/bar/baz";
037: protected static final String DELETE_URL = "/test/authoring" + PATH
038: + ".html";
039: protected static final String TARGET_URL = "/test/authoring/foo_de.html";
040: protected static final String SOURCE_PATH = "/tutorial";
041:
042: protected String getUsecaseName() {
043: return "sitemanagement.delete";
044: }
045:
046: protected void checkPostconditions() throws Exception {
047:
048: assertTrue(getTargetUrl().startsWith(TARGET_URL));
049:
050: super .checkPostconditions();
051:
052: Area authoring = getPublication("test").getArea("authoring");
053: SiteStructure authoringSite = authoring.getSite();
054: assertFalse(authoringSite.contains(PATH));
055:
056: Area trash = getPublication("test").getArea("trash");
057: SiteStructure trashSite = trash.getSite();
058: assertTrue(trashSite.contains(PATH));
059: String trashUuid = trashSite.getNode(PATH).getUuid();
060: assertNotNull(trashUuid);
061: assertEquals(trashUuid, this .uuid);
062:
063: }
064:
065: protected Map getParameters() {
066: Map params = new HashMap();
067: params.put("private.sourceUrl", DELETE_URL);
068: return params;
069: }
070:
071: private String uuid;
072:
073: protected void prepareUsecase() throws Exception {
074: super .prepareUsecase();
075: Area authoring = getPublication("test").getArea("authoring");
076:
077: SiteStructure authoringSite = authoring.getSite();
078: SiteNode node = authoringSite.getNode(SOURCE_PATH);
079: Document doc = node.getLink("en").getDocument();
080:
081: DocumentManager docMgr = null;
082: try {
083: docMgr = (DocumentManager) getManager().lookup(
084: DocumentManager.ROLE);
085:
086: String pubId = doc.getPublication().getId();
087: String area = doc.getArea();
088: DocumentLocator loc = DocumentLocator.getLocator(pubId,
089: area, PATH, doc.getLanguage());
090:
091: authoringSite.add("/foo");
092: authoringSite.add("/foo/bar");
093:
094: docMgr.copy(doc, loc);
095:
096: // add an ancestor language version to test the method
097: // MoveSubSite.getTargetURL()
098: DocumentLocator ancestorLoc = DocumentLocator.getLocator(
099: pubId, area, "/foo", "de");
100: docMgr.copy(doc, ancestorLoc);
101:
102: SiteNode childNode = authoringSite.getNode(PATH);
103: this.uuid = childNode.getUuid();
104: } finally {
105: if (docMgr != null) {
106: getManager().release(docMgr);
107: }
108: }
109: }
110:
111: }
|