001/* JUnit test the ExportToWeb mechanism. 002 003 Copyright (c) 2011-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028 029package ptolemy.vergil.basic.export.html.test.junit; 030 031import java.io.File; 032 033import ptolemy.util.FileUtilities; 034import ptolemy.vergil.basic.export.ExportModel; 035 036/////////////////////////////////////////////////////////////////// 037//// ExportToWebUnitTest 038/** 039 * Test out export to web facility. 040 * 041 * @author Christopher Brooks 042 * @version $Id$ 043 * @since Ptolemy II 10.0 044 * @Pt.ProposedRating Red (cxh) 045 * @Pt.AcceptedRating Red (cxh) 046 */ 047public class ExportToWebJUnitTest { 048 049 /** Test the ExportToWeb facility. 050 * 051 * <p>To run, use:</p> 052 * 053 * <pre> 054 * java -classpath \ 055 * $PTII:${PTII}/lib/junit-4.8.2.jar:${PTII}/lib/JUnitParams-0.3.0.jar \ 056 * ptolemy.vergil.basic.export.html.test.junit.ExportToWebJUnitTest 057 * </pre> 058 * 059 * @param args Not used. 060 */ 061 public static void main(String args[]) { 062 org.junit.runner.JUnitCore.main( 063 "ptolemy.vergil.basic.export.html.test.junit.ExportToWebJUnitTest"); 064 } 065 066 /** Test the export the Butterfly model. 067 * @exception Exception If there is a problem reading or laying 068 * out a model. 069 */ 070 @org.junit.Test 071 public void exportButterfly() throws Exception { 072 _exportToWebTest( 073 "$CLASSPATH/ptolemy/domains/sdf/demo/Butterfly/Butterfly.xml", 074 "Butterfly"); 075 } 076 077 /////////////////////////////////////////////////////////////////// 078 //// protected methods //// 079 080 /** 081 * Test the ExportToWeb facility by reading in a model, and exporting it. 082 * 083 * <p>This is the main entry point for ExportToWeb tests.</p> 084 * 085 * <p>The caller of this method need <b>not</b>be in the Swing 086 * Event Thread.</p> 087 * 088 * @param modelFileName The file name of the test model. 089 * @param directoryName The name of the directory. 090 * @exception Exception If the file name cannot be read or exported 091 */ 092 protected void _exportToWebTest(final String modelFileName, 093 final String directoryName) throws Exception { 094 FileUtilities.deleteDirectory(new File(directoryName)); 095 String args[] = new String[3]; 096 args[0] = "-run"; 097 args[1] = modelFileName; 098 args[2] = directoryName; 099 // Export.main(args) calls System.exit() unless we set this property. 100 System.setProperty("ptolemy.ptII.doNotExit", "true"); 101 ExportModel.main(args); 102 FileUtilities.deleteDirectory(new File(directoryName)); 103 } 104}