KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > staticexport > TestExportFile


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/staticexport/TestExportFile.java,v $
3  * Date : $Date: 2005/06/27 23:22:25 $
4  * Version: $Revision: 1.14 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

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 JavaDoc;
41 import java.io.FileInputStream JavaDoc;
42
43 import junit.extensions.TestSetup;
44 import junit.framework.Test;
45 import junit.framework.TestSuite;
46
47 /**
48  * @author Carsten Weinholz
49  *
50  * @version $Revision: 1.14 $
51  *
52  * @since 6.0.0
53  */

54 public class TestExportFile extends OpenCmsTestCase {
55
56     /**
57      * Default JUnit constructor.<p>
58      *
59      * @param arg0 JUnit parameters
60      */

61     public TestExportFile(String JavaDoc arg0) {
62         super(arg0);
63     }
64
65     /**
66      * Test suite for this test class.<p>
67      *
68      * @return the test suite
69      */

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     /**
93      * Tests the file export.<p>
94      *
95      * @throws Throwable if something goes wrong
96      */

97     public void testStaticexportFile() throws Throwable JavaDoc {
98         
99         CmsObject cms = getCmsObject();
100         echo("Testing file export");
101         
102         // set the export mode to export immediately after publishing resources
103
OpenCms.getStaticExportManager().setHandler("org.opencms.staticexport.CmsAfterPublishStaticExportHandler");
104         
105         String JavaDoc resourcename = "/file1.txt";
106         String JavaDoc content = "this is a test content";
107         
108         // create a file in the root directory
109
cms.createResource(resourcename, CmsResourceTypePlain.getStaticTypeId(), content.getBytes(), null);
110         cms.unlockResource(resourcename);
111         
112         // read and check the content
113
this.assertContent(cms, resourcename, content.getBytes());
114         
115         // now publish (and export) the resource
116
cms.publishProject();
117         
118         // now read the exported file in the file system and check its content
119
File JavaDoc f = new File JavaDoc(getTestDataPath("export/sites/default" + resourcename));
120         assertTrue(f.exists());
121         
122         // check the exported content
123
byte[] exportContent = new byte[(int)f.length()];
124         FileInputStream JavaDoc fileStream = new FileInputStream JavaDoc(f);
125         fileStream.read(exportContent);
126         
127         this.assertContent(cms, resourcename, exportContent);
128         
129     }
130 }
131
Popular Tags