1 //
2 // Copyright (c) 2003-2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
14 // nor the names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 // POSSIBILITY OF SUCH DAMAGE.
27 //
28
29 package org.objectledge.external;
30
31 import java.io.File;
32 import java.io.IOException;
33
34 import org.objectledge.filesystem.FileSystem;
35 import org.objectledge.utils.LedgeTestCase;
36
37 /***
38 * Test for the ScriptDirectory class.
39 *
40 * @author <a href="rafal@caltha.pl">RafaĆ Krzewski</a>
41 * @version $Id: ScriptDirectoryTest.java,v 1.1 2006/03/24 14:27:39 rafal Exp $
42 */
43 public class ScriptDirectoryTest
44 extends LedgeTestCase
45 {
46 static boolean linux;
47
48 static
49 {
50 if(System.getProperty("os.name").equals("Linux"))
51 {
52 linux = true;
53 }
54 }
55
56 public void testLedgeFS() throws IOException
57 {
58 ScriptDirectory scriptDir = new ScriptDirectory(getFileSystem(),
59 ScriptDirectory.DEFAULT_PROVIDER,
60 "external",
61 linux ? ScriptDirectory.DEFAULT_PATH_PATTERN : null,
62 ScriptDirectory.DEFAULT_COMMAND);
63
64 assertTrue(new File(scriptDir.getPath("test.sh")).exists());
65
66 if(linux)
67 {
68 Runtime.getRuntime().exec(scriptDir.getPath("test.sh"));
69 }
70 }
71
72 public void testHostFS() throws Exception
73 {
74 ScriptDirectory scriptDir = new ScriptDirectory(new File("src/test/resources/external"),
75 linux ? ScriptDirectory.DEFAULT_PATH_PATTERN : null, ScriptDirectory.DEFAULT_COMMAND);
76
77 assertTrue(new File(scriptDir.getPath("test.sh")).exists());
78
79 if(linux)
80 {
81 Runtime.getRuntime().exec(scriptDir.getPath("test.sh"));
82 }
83 }
84
85 public void testConifg()
86 throws Exception
87 {
88 checkSchema("config/org.objectledge.external.ScriptDirectory.xml",
89 "org/objectledge/external/ScriptDirectory.rng");
90 final FileSystem fs = getFileSystem();
91 ScriptDirectory scriptDir = new ScriptDirectory(fs, getConfig(fs,
92 "config/org.objectledge.external.ScriptDirectory.xml"));
93 }
94 }