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.linking;
19:
20: import java.util.Arrays;
21:
22: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
23: import org.apache.lenya.cms.publication.Area;
24: import org.apache.lenya.cms.publication.Document;
25: import org.apache.lenya.cms.publication.Publication;
26: import org.apache.lenya.cms.site.SiteStructure;
27:
28: /**
29: * Test for link functionality.
30: */
31: public class LinkTest extends AbstractAccessControlTest {
32:
33: /**
34: * Link test.
35: * @throws Exception
36: */
37: public void testLinks() throws Exception {
38:
39: Publication pub = getPublication("test");
40: Area area = pub.getArea("authoring");
41: SiteStructure site = area.getSite();
42:
43: Document source = site.getNode("/index").getLink("en")
44: .getDocument();
45: Document target = site.getNode("/tutorial").getLink("en")
46: .getDocument();
47:
48: LinkManager linkManager = null;
49: LinkResolver resolver = null;
50: try {
51: linkManager = (LinkManager) getManager().lookup(
52: LinkManager.ROLE);
53: resolver = (LinkResolver) getManager().lookup(
54: LinkResolver.ROLE);
55:
56: Link[] links = linkManager.getLinksFrom(source);
57:
58: boolean matched = false;
59: for (int i = 0; i < links.length; i++) {
60: LinkTarget linkTarget = resolver.resolve(source,
61: links[i].getUri());
62: if (linkTarget.exists()
63: && linkTarget.getDocument().equals(target)) {
64: matched = true;
65: }
66: }
67:
68: assertTrue(matched);
69:
70: Document[] references = linkManager
71: .getReferencingDocuments(target);
72: assertTrue(Arrays.asList(references).contains(source));
73: } finally {
74: if (linkManager != null) {
75: getManager().release(linkManager);
76: }
77: if (resolver != null) {
78: getManager().release(resolver);
79: }
80: }
81:
82: }
83:
84: }
|