1 17 18 19 20 package org.apache.lenya.cms.publication; 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 29 30 35 public class DefaultDocumentTest extends TestCase { 36 40 public DefaultDocumentTest(String test) { 41 super(test); 42 } 43 44 50 public static void main(String [] args) { 51 PublicationHelper.extractPublicationArguments(args); 52 TestRunner.run(getSuite()); 53 } 54 55 59 public static Test getSuite() { 60 return new TestSuite(DefaultDocumentTest.class); 61 } 62 63 protected static final DocumentTestSet[] testSets = { 64 new DocumentTestSet("/index.html", "/index", Publication.AUTHORING_AREA, "en", "html"), 65 new DocumentTestSet("/index_en.htm", "/index", Publication.AUTHORING_AREA, "en", "htm"), 66 new DocumentTestSet("/index_de.html", "/index", Publication.AUTHORING_AREA, "de", "html") 67 }; 68 69 74 protected void doDocumentTest(DocumentTestSet testSet) 75 throws DocumentBuildException { 76 Document document = getDocument(testSet); 77 System.out.println("ID: " + document.getId()); 78 System.out.println("Area: " + document.getArea()); 79 System.out.println("Language: " + document.getLanguage()); 80 System.out.println("Document URL: " + document.getDocumentURL()); 81 System.out.println("Complete URL: " + document.getCompleteURL()); 82 System.out.println("Extension: " + document.getExtension()); 83 84 Publication publication = PublicationHelper.getPublication(); 85 assertEquals(document.getPublication(), publication); 86 assertEquals(document.getId(), testSet.getId()); 87 assertEquals(document.getArea(), testSet.getArea()); 88 assertEquals(document.getLanguage(), testSet.getLanguage()); 89 assertEquals(document.getDocumentURL(), testSet.getUrl()); 90 assertEquals(document.getCompleteURL(), 91 "/" + publication.getId() + "/" + document.getArea() + testSet.getUrl()); 92 assertEquals(document.getExtension(), testSet.getExtension()); 93 94 System.out.println("-----------------------------------------------"); 95 } 96 97 101 public void testDefaultDocument() throws DocumentBuildException { 102 for (int i = 0; i < testSets.length; i++) { 103 doDocumentTest(testSets[i]); 104 } 105 } 106 107 113 protected Document getDocument(DocumentTestSet testSet) 114 throws DocumentBuildException { 115 DefaultDocument document = new DefaultDocument(PublicationHelper.getPublication(), 116 testSet.getId(), testSet.getArea()); 117 document.setDocumentURL(testSet.getUrl()); 118 document.setLanguage(testSet.getLanguage()); 119 document.setExtension(testSet.getExtension()); 120 121 return document; 122 } 123 124 127 protected static class DocumentTestSet { 128 private String url; 129 private String id; 130 private String extension; 131 private String area; 132 private String language; 133 134 142 public DocumentTestSet(String url, String id, String area, String language, String extension) { 143 this.url = url; 144 this.id = id; 145 this.area = area; 146 this.language = language; 147 this.extension = extension; 148 } 149 150 153 public String getArea() { 154 return area; 155 } 156 157 160 public String getExtension() { 161 return extension; 162 } 163 164 167 public String getId() { 168 return id; 169 } 170 171 174 public String getLanguage() { 175 return language; 176 } 177 178 181 public String getUrl() { 182 return url; 183 } 184 } 185 186 189 protected void setUp() throws Exception { 190 if (PublicationHelper.getPublication() == null) { 191 String [] args = { "D:\\Development\\build\\tomcat-4.1.24\\webapps\\lenya", "test" }; 192 PublicationHelper.extractPublicationArguments(args); 193 } 194 } 195 } 196 | Popular Tags |