KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > file > FilePublicationTest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: FilePublicationTest.java 160152 2005-04-05 09:59:45Z michi $ */
19
20 package org.apache.lenya.cms.publication.file;
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25 import junit.textui.TestRunner;
26
27 import org.apache.lenya.cms.PublicationHelper;
28 import org.apache.lenya.cms.publication.Document;
29 import org.apache.lenya.cms.publication.DocumentBuilder;
30 import org.apache.lenya.cms.publication.DocumentException;
31 import org.apache.lenya.cms.publication.Label;
32 import org.apache.lenya.cms.publication.Publication;
33 import org.apache.lenya.cms.publication.PublicationException;
34 import org.apache.lenya.cms.publication.SiteTree;
35 import org.apache.lenya.cms.publication.SiteTreeException;
36 import org.apache.lenya.cms.publication.SiteTreeNode;
37
38 /**
39  * To change the template for this generated type comment go to
40  * Window>Preferences>Java>Code Generation>Code and Comments
41  */

42 public class FilePublicationTest extends TestCase {
43
44     /**
45      * Constructor.
46      * @param test The test.
47      */

48     public FilePublicationTest(String JavaDoc test) {
49         super(test);
50     }
51
52     /**
53      * The main program.
54      * The parameters are set from the command line arguments.
55      *
56      * @param args The command line arguments.
57      */

58     public static void main(String JavaDoc[] args) {
59         PublicationHelper.extractPublicationArguments(args);
60         TestRunner.run(getSuite());
61     }
62
63     /**
64      * Returns the test suite.
65      * @return A test suite.
66      */

67     public static Test getSuite() {
68         return new TestSuite(FilePublicationTest.class);
69     }
70
71     public static final String JavaDoc sourceDocumentId = "/tutorial";
72     public static final String JavaDoc destinationDocumentId = "/doctypes/simple-document";
73     public static final String JavaDoc sourceLanguage = "en";
74     public static final String JavaDoc destinationLanguage = "en";
75
76     /**
77      * Tests copying a document.
78      * @throws PublicationException when something went wrong.
79      */

80     public void testCopyDocument() throws PublicationException, DocumentException, SiteTreeException {
81         testCopyDocument(
82             Publication.AUTHORING_AREA,
83             sourceDocumentId,
84             sourceLanguage,
85             Publication.AUTHORING_AREA,
86             destinationDocumentId,
87             destinationLanguage);
88         testCopyDocument(
89             Publication.AUTHORING_AREA,
90             sourceDocumentId,
91             sourceLanguage,
92             Publication.LIVE_AREA,
93             sourceDocumentId,
94             sourceLanguage);
95     }
96
97     /**
98      * Tests copying a document.
99      * @param sourceArea The source area.
100      * @param sourceDocumentId The source document ID.
101      * @param sourceLanguage The source language.
102      * @param destinationArea The destination area.
103      * @param destinationDocumentId The destination document ID.
104      * @param destinationLanguage The destination language.
105      * @throws PublicationException when something went wrong.
106      */

107     public void testCopyDocument(
108         String JavaDoc sourceArea,
109         String JavaDoc sourceDocumentId,
110         String JavaDoc sourceLanguage,
111         String JavaDoc destinationArea,
112         String JavaDoc destinationDocumentId,
113         String JavaDoc destinationLanguage)
114         throws PublicationException, DocumentException, SiteTreeException {
115             
116         System.out.println("Copy document");
117         System.out.println(" Source area: [" + sourceArea + "]");
118         System.out.println(" Source document ID: [" + sourceDocumentId + "]");
119         System.out.println(" Source language: [" + sourceLanguage + "]");
120         System.out.println(" Destination area: [" + destinationArea + "]");
121         System.out.println(" Destination document ID: [" + destinationDocumentId + "]");
122         System.out.println(" Destination language: [" + destinationLanguage + "]");
123             
124         Publication publication = PublicationHelper.getPublication();
125         DocumentBuilder builder = publication.getDocumentBuilder();
126         
127         String JavaDoc sourceUrl =
128             builder.buildCanonicalUrl(publication, sourceArea, sourceDocumentId, sourceLanguage);
129         Document sourceDocument = builder.buildDocument(publication, sourceUrl);
130         String JavaDoc destinationUrl =
131             builder.buildCanonicalUrl(
132                 publication,
133                 destinationArea,
134                 destinationDocumentId,
135                 destinationLanguage);
136         Document destinationDocument = builder.buildDocument(publication, destinationUrl);
137         
138         publication.copyDocument(sourceDocument, destinationDocument);
139         
140         assertTrue(destinationDocument.exists());
141         
142         SiteTree destinationTree = publication.getTree(destinationArea);
143         SiteTreeNode destinationNode = destinationTree.getNode(destinationDocumentId);
144         assertNotNull(destinationNode);
145         Label destinationLabel = destinationNode.getLabel(destinationLanguage);
146         assertNotNull(destinationLabel);
147         
148         SiteTreeNode sourceNode = destinationTree.getNode(sourceDocumentId);
149         Label sourceLabel = sourceNode.getLabel(sourceLanguage);
150         
151         assertTrue(destinationLabel.getLabel().equals(sourceLabel.getLabel()));
152         
153     }
154 }
155
Popular Tags