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.publication;
019:
020: import java.io.File;
021: import java.util.Arrays;
022: import java.util.HashSet;
023: import java.util.Set;
024:
025: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
026:
027: /**
028: * Publication test.
029: */
030: public class PublicationTest extends AbstractAccessControlTest {
031:
032: /**
033: * Tests the publication functionality.
034: * @throws Exception
035: */
036: public void testPublication() throws Exception {
037:
038: PublicationManager pubMgr = null;
039: try {
040: pubMgr = (PublicationManager) getManager().lookup(
041: PublicationManager.ROLE);
042:
043: Publication[] pubs = pubMgr.getPublications(getFactory());
044: for (int i = 0; i < pubs.length; i++) {
045: doTestPublication(pubs[i]);
046: }
047:
048: } finally {
049: if (pubMgr != null) {
050: getManager().release(pubMgr);
051: }
052: }
053:
054: }
055:
056: protected void doTestPublication(Publication pub)
057: throws PublicationException {
058: String contentDirPath = pub.getContentDir();
059: assertNotNull(contentDirPath);
060:
061: File contentDir = new File(contentDirPath);
062:
063: assertTrue(pub.exists());
064:
065: String[] areaNames = pub.getAreaNames();
066: for (int i = 0; i < areaNames.length; i++) {
067: Area area = pub.getArea(areaNames[i]);
068: if (area.getDocuments().length > 0) {
069: File areaContentDir = pub
070: .getContentDirectory(areaNames[i]);
071: assertTrue(areaContentDir.isDirectory());
072: assertEquals(new File(contentDir, areaNames[i]),
073: areaContentDir);
074: }
075: }
076:
077: String[] languages = pub.getLanguages();
078: assertTrue(languages.length > 0);
079:
080: assertNotNull(pub.getDefaultLanguage());
081: assertTrue(Arrays.asList(languages).contains(
082: pub.getDefaultLanguage()));
083:
084: String[] types = pub.getResourceTypeNames();
085: assertTrue(types.length > 0);
086:
087: Set typeSet = new HashSet(Arrays.asList(types));
088:
089: String[] templateIds = pub.getTemplateIds();
090: for (int i = 0; i < templateIds.length; i++) {
091: Publication template = pub.getFactory().getPublication(
092: templateIds[i]);
093: String[] templateTypes = template.getResourceTypeNames();
094: for (int t = 0; t < templateTypes.length; t++) {
095: assertTrue(typeSet.contains(templateTypes[i]));
096: }
097: }
098:
099: }
100:
101: }
|