1 31 32 package org.opencms.staticexport; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.types.CmsResourceTypePlain; 36 import org.opencms.main.OpenCms; 37 import org.opencms.test.OpenCmsTestCase; 38 import org.opencms.test.OpenCmsTestProperties; 39 40 import java.io.File ; 41 import java.io.FileInputStream ; 42 43 import junit.extensions.TestSetup; 44 import junit.framework.Test; 45 import junit.framework.TestSuite; 46 47 54 public class TestExportFile extends OpenCmsTestCase { 55 56 61 public TestExportFile(String arg0) { 62 super(arg0); 63 } 64 65 70 public static Test suite() { 71 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 72 73 TestSuite suite = new TestSuite(); 74 suite.setName(TestExportFile.class.getName()); 75 76 suite.addTest(new TestExportFile("testStaticexportFile")); 77 78 TestSetup wrapper = new TestSetup(suite) { 79 80 protected void setUp() { 81 setupOpenCms(null, null, true); 82 } 83 84 protected void tearDown() { 85 removeOpenCms(); 86 } 87 }; 88 89 return wrapper; 90 } 91 92 97 public void testStaticexportFile() throws Throwable { 98 99 CmsObject cms = getCmsObject(); 100 echo("Testing file export"); 101 102 OpenCms.getStaticExportManager().setHandler("org.opencms.staticexport.CmsAfterPublishStaticExportHandler"); 104 105 String resourcename = "/file1.txt"; 106 String content = "this is a test content"; 107 108 cms.createResource(resourcename, CmsResourceTypePlain.getStaticTypeId(), content.getBytes(), null); 110 cms.unlockResource(resourcename); 111 112 this.assertContent(cms, resourcename, content.getBytes()); 114 115 cms.publishProject(); 117 118 File f = new File (getTestDataPath("export/sites/default" + resourcename)); 120 assertTrue(f.exists()); 121 122 byte[] exportContent = new byte[(int)f.length()]; 124 FileInputStream fileStream = new FileInputStream (f); 125 fileStream.read(exportContent); 126 127 this.assertContent(cms, resourcename, exportContent); 128 129 } 130 } 131 | Popular Tags |