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:
019: /* $Id: DefaultDocumentTest.java 570957 2007-08-29 22:31:41Z andreas $ */
020:
021: package org.apache.lenya.cms.publication;
022:
023: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
024:
025: /**
026: *
027: * To change the template for this generated type comment go to Window>Preferences>Java>Code
028: * Generation>Code and Comments
029: */
030: public class DefaultDocumentTest extends AbstractAccessControlTest {
031:
032: protected static final DocumentTestSet[] testSets = {
033: new DocumentTestSet("/index.html", "/index",
034: Publication.AUTHORING_AREA, "en", "html"),
035: new DocumentTestSet("/index_de.html", "/index",
036: Publication.AUTHORING_AREA, "de", "html") };
037:
038: /**
039: * Tests a document test set.
040: * @param testSet The test set.
041: * @throws PublicationException
042: */
043: protected void doDocumentTest(DocumentTestSet testSet)
044: throws PublicationException {
045: Document document = getDocument(testSet);
046: getLogger().info("UUID: " + document.getUUID());
047: getLogger().info("Area: " + document.getArea());
048: getLogger().info("Language: " + document.getLanguage());
049: getLogger().info(
050: "Document URL: " + document.getCanonicalDocumentURL());
051: getLogger().info(
052: "Complete URL: " + document.getCanonicalWebappURL());
053: getLogger().info("Extension: " + document.getExtension());
054:
055: Publication publication = getPublication("test");
056: assertEquals(document.getPublication(), publication);
057: assertEquals(document.getPath(), testSet.getPath());
058: assertEquals(document.getArea(), testSet.getArea());
059: assertEquals(document.getLanguage(), testSet.getLanguage());
060: assertEquals(document.getCanonicalDocumentURL(), testSet
061: .getUrl());
062: assertEquals(document.getCanonicalWebappURL(), "/"
063: + publication.getId() + "/" + document.getArea()
064: + testSet.getUrl());
065: assertEquals(document.getExtension(), testSet.getExtension());
066:
067: getLogger().info(
068: "-----------------------------------------------");
069: }
070:
071: /**
072: * Tests the default document.
073: * @throws PublicationException
074: */
075: public void testDefaultDocument() throws PublicationException {
076: for (int i = 0; i < testSets.length; i++) {
077: doDocumentTest(testSets[i]);
078: }
079: }
080:
081: /**
082: * Returns the test document for a given test set.
083: * @param testSet A document test set.
084: * @return A document.
085: * @throws PublicationException
086: */
087: protected Document getDocument(DocumentTestSet testSet)
088: throws PublicationException {
089:
090: Publication pub = getPublication("test");
091: String uuid = pub.getArea(testSet.getArea()).getSite().getNode(
092: testSet.getPath()).getUuid();
093: DocumentIdentifier id = new DocumentIdentifier(pub.getId(),
094: testSet.getArea(), uuid, testSet.getLanguage());
095: DocumentImpl document = new DocumentImpl(getManager(),
096: getFactory(), id, -1, getLogger());
097: document.setExtension(testSet.getExtension());
098:
099: return document;
100: }
101:
102: /**
103: * Utility class to store test data for a document.
104: */
105: protected static class DocumentTestSet {
106: private String url;
107: private String path;
108: private String extension;
109: private String area;
110: private String language;
111:
112: /**
113: * Ctor.
114: * @param _url The url.
115: * @param _path The path.
116: * @param _area The area.
117: * @param _language The language.
118: * @param _extension The extension.
119: */
120: public DocumentTestSet(String _url, String _path, String _area,
121: String _language, String _extension) {
122: this .url = _url;
123: this .path = _path;
124: this .area = _area;
125: this .language = _language;
126: this .extension = _extension;
127: }
128:
129: /**
130: * @return The area.
131: */
132: public String getArea() {
133: return this .area;
134: }
135:
136: /**
137: * @return The extension.
138: */
139: public String getExtension() {
140: return this .extension;
141: }
142:
143: /**
144: * @return The path.
145: */
146: public String getPath() {
147: return this .path;
148: }
149:
150: /**
151: * @return The language.
152: */
153: public String getLanguage() {
154: return this .language;
155: }
156:
157: /**
158: * @return The URL.
159: */
160: public String getUrl() {
161: return this.url;
162: }
163: }
164:
165: }
|