1 17 18 19 20 package org.apache.lenya.cms.task; 21 22 import java.io.File ; 23 import java.io.FileFilter ; 24 import java.io.IOException ; 25 import java.util.GregorianCalendar ; 26 27 import junit.framework.Test; 28 import junit.framework.TestCase; 29 import junit.framework.TestSuite; 30 import junit.textui.TestRunner; 31 32 import org.apache.avalon.framework.configuration.ConfigurationException; 33 import org.apache.avalon.framework.parameters.ParameterException; 34 import org.apache.avalon.framework.parameters.Parameters; 35 import org.apache.lenya.cms.PublicationHelper; 36 import org.apache.lenya.cms.publication.Publication; 37 import org.xml.sax.SAXException ; 38 39 40 48 public class AntTaskTest extends TestCase { 49 private static String target = "test"; 50 51 56 public AntTaskTest(String test) { 57 super(test); 58 } 59 60 65 public static void main(String [] args) { 66 initialize(args); 67 TestRunner.run(getSuite()); 68 } 69 70 75 public static void initialize(String [] args) { 76 args = PublicationHelper.extractPublicationArguments(args); 77 78 if (args.length > 0) { 79 target = args[0]; 80 } 81 } 82 83 88 public static Test getSuite() { 89 return new TestSuite(AntTaskTest.class); 90 } 91 92 98 public final void testAntTask() throws Exception { 99 prepareTest(); 100 doTest(getTarget()); 101 evaluateTest(); 102 } 103 104 108 protected String getTarget() { 109 return target; 110 } 111 112 122 protected void doTest(String target) throws ExecutionException, ParameterException, ConfigurationException, SAXException , IOException { 123 System.out.println("Testing target [" + target + "]:"); 124 125 Publication publication = PublicationHelper.getPublication(); 126 127 TaskManager manager = new TaskManager(publication.getDirectory().getCanonicalPath()); 128 AntTask task = (AntTask) manager.getTask(TaskManager.ANT_TASK); 129 130 Parameters parameters = getTaskParameters(); 131 parameters.setParameter(AntTask.PARAMETER_PUBLICATION_ID, publication.getId()); 132 parameters.setParameter(AntTask.PARAMETER_CONTEXT_PREFIX, "/lenya"); 133 parameters.setParameter(AntTask.PARAMETER_SERVLET_CONTEXT, 134 publication.getServletContext().getCanonicalPath()); 135 parameters.setParameter(AntTask.TARGET, getTarget()); 136 task.parameterize(parameters); 137 138 final GregorianCalendar beforeExecution = new GregorianCalendar (); 139 140 task.execute(publication.getServletContext().getCanonicalPath()); 141 142 File logDirectory = new File (publication.getDirectory(), AntTask.LOG_PATH); 143 File [] logFiles = logDirectory.listFiles(new FileFilter () { 144 public boolean accept(File file) { 145 return file.lastModified() > beforeExecution.getTimeInMillis(); 146 } 147 }); 148 149 assertTrue(logFiles.length == 1); 150 151 File logFile = logFiles[0]; 152 } 153 154 159 protected Parameters getTaskParameters() { 160 return new Parameters(); 161 } 162 163 167 protected void prepareTest() throws Exception { 168 System.out.println("prepare"); 169 } 170 171 175 protected void evaluateTest() throws Exception { 176 System.out.println("evaluate"); 177 } 178 179 182 protected void setUp() throws Exception { 183 if (PublicationHelper.getPublication() == null) { 184 String [] args = { 185 "/home/egli/build/jakarta-tomcat-4.1.21-LE-jdk14/webapps/lenya", "test" 186 }; 187 PublicationHelper.extractPublicationArguments(args); 188 } 189 } 190 } 191 | Popular Tags |