1
2
3
4
5
6
7
8
9
10 package org.astrogrid.mySpace.installationtest;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.util.Properties;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18
19 import org.astrogrid.AstroGridException;
20 import org.astrogrid.mySpace.mySpaceManager.MMC;
21 import org.astrogrid.mySpace.mySpaceServer.MSC;
22
23 import junit.framework.TestCase;
24
25 /***
26 * This test ensures that MySpace can find its configuration file
27 * @author john taylor
28 * @TODO do we require tests to located the template files?
29 *
30 */
31 public class ConfFileLocatedTest extends TestCase {
32 /*** Logger */
33 private static Log log = LogFactory.getLog(ConfFileLocatedTest.class);
34 /***
35 * Constructor for ConfFileLocatedTest.
36 * @param arg0 test name
37 */
38 public ConfFileLocatedTest(final String arg0) {
39 super(arg0);
40 }
41 /***
42 * Fire up the text ui.
43 * @param args ignored
44 */
45 public static void main(final String[] args) {
46 junit.textui.TestRunner.run(ConfFileLocatedTest.class);
47 }
48
49 /***
50 * There's one file for MySpaceManager
51 * @throws AstroGridException if trouble finding config file
52 */
53 public final void testGotMySpaceManagerConfig() throws AstroGridException {
54 MMC.getInstance().checkPropertiesLoaded();
55 }
56
57 /***
58 * There's one file for MySpaceServer
59 * @throws AstroGridException if trouble finding config file
60 */
61
62 public final void testGotMySpaceServerConfig() throws AstroGridException {
63 MSC.getInstance().checkPropertiesLoaded();
64 }
65
66 /***
67 * The *.properties files should be on the classpath
68 * @throws IOException if there's trouble
69 */
70 public final void testGotPropertiesFiles() throws IOException {
71 checkProperties(MMC.getProperty("INSTALLATION.BASENAME", "MESSAGES"));
72 checkProperties(MSC.getProperty("INSTALLATION.BASENAME", "MESSAGES"));
73 }
74
75 /***
76 * Look for the messages properties file
77 * @param baseName the properties file will be \<baseName>.properties
78 * @throws IOException if there's trouble
79 */
80 private void checkProperties(final String baseName) throws IOException {
81 log.debug("Checking properties file: "+baseName);
82 Properties messages = new Properties();
83 final String messageFile = "/" + baseName + ".properties";
84 InputStream is = this.getClass().getResourceAsStream(messageFile);
85 assertNotNull(messageFile + " file not found", is);
86 messages.load(is);
87 }
88 }