01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.export;
19:
20: import java.io.File;
21:
22: import org.apache.avalon.framework.service.ServiceException;
23: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
24: import org.apache.lenya.cms.linking.Link;
25: import org.apache.lenya.cms.linking.LinkManager;
26: import org.apache.lenya.cms.publication.Area;
27: import org.apache.lenya.cms.publication.Document;
28: import org.apache.lenya.cms.publication.Publication;
29: import org.apache.lenya.cms.publication.PublicationException;
30: import org.apache.lenya.cms.repository.Session;
31: import org.apache.lenya.cms.site.SiteStructure;
32:
33: /**
34: * Import example content into test publication.
35: */
36: public class ImportTest extends AbstractAccessControlTest {
37:
38: /**
39: * @throws Exception if an error occurs.
40: */
41: public void testImport() throws Exception {
42:
43: Session session = login("lenya");
44:
45: Publication pub = getPublication(session, "test");
46: Area area = pub.getArea("authoring");
47:
48: if (area.getDocuments().length == 0) {
49: Publication defaultPub = getPublication(session, "default");
50: Area defaultArea = defaultPub.getArea("authoring");
51: String pubPath = defaultArea.getPublication()
52: .getDirectory().getAbsolutePath();
53: String path = pubPath.replace(File.separatorChar, '/')
54: + "/example-content";
55: Importer importer = new Importer(getManager(), getLogger());
56: importer.importContent(defaultPub, area, path);
57:
58: assertTrue(area.getSite().contains("/tutorial"));
59: checkLinks(area);
60:
61: session.commit();
62: }
63:
64: Session aliceSession = login("alice");
65: Publication alicePub = getPublication(aliceSession, "test");
66: assertTrue(alicePub.getArea("authoring").getSite().contains(
67: "/tutorial"));
68:
69: }
70:
71: protected void checkLinks(Area area) throws PublicationException,
72: ServiceException {
73: SiteStructure site = area.getSite();
74: Document source = site.getNode("/index").getLink("en")
75: .getDocument();
76:
77: LinkManager linkManager = null;
78: try {
79: linkManager = (LinkManager) getManager().lookup(
80: LinkManager.ROLE);
81: Link[] links = linkManager.getLinksFrom(source);
82: assertTrue(links.length > 0);
83: } finally {
84: if (linkManager != null) {
85: getManager().release(linkManager);
86: }
87: }
88:
89: }
90:
91: }
|