1 17 18 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 42 public class FilePublicationTest extends TestCase { 43 44 48 public FilePublicationTest(String test) { 49 super(test); 50 } 51 52 58 public static void main(String [] args) { 59 PublicationHelper.extractPublicationArguments(args); 60 TestRunner.run(getSuite()); 61 } 62 63 67 public static Test getSuite() { 68 return new TestSuite(FilePublicationTest.class); 69 } 70 71 public static final String sourceDocumentId = "/tutorial"; 72 public static final String destinationDocumentId = "/doctypes/simple-document"; 73 public static final String sourceLanguage = "en"; 74 public static final String destinationLanguage = "en"; 75 76 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 107 public void testCopyDocument( 108 String sourceArea, 109 String sourceDocumentId, 110 String sourceLanguage, 111 String destinationArea, 112 String destinationDocumentId, 113 String 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 sourceUrl = 128 builder.buildCanonicalUrl(publication, sourceArea, sourceDocumentId, sourceLanguage); 129 Document sourceDocument = builder.buildDocument(publication, sourceUrl); 130 String 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 |