|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package org.jconfig.server; |
|
8 |
| |
|
9 |
| import java.io.File; |
|
10 |
| import java.io.InputStream; |
|
11 |
| |
|
12 |
| import junit.framework.TestCase; |
|
13 |
| |
|
14 |
| import org.jconfig.Configuration; |
|
15 |
| import org.jconfig.handler.ConfigServerHandler; |
|
16 |
| import org.jconfig.utils.ConfigurationUtils; |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| public class ConfigServerTest extends TestCase { |
|
27 |
| |
|
28 |
| private static ConfigurationServer cs; |
|
29 |
| private static final String URL = "jconfig://localhost:8766"; |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
0
| public ConfigServerTest(String arg0) {
|
|
35 |
0
| super(arg0);
|
|
36 |
| } |
|
37 |
| |
|
38 |
0
| public static void main(String[] args) {
|
|
39 |
0
| File file = ConfigurationUtils.getFileFromInputStream("config.xml");
|
|
40 |
0
| String documentRoot = file.getPath();
|
|
41 |
0
| documentRoot = documentRoot.substring(0,documentRoot.indexOf("config.xml"));
|
|
42 |
0
| cs = new ConfigurationServer(8766,documentRoot);
|
|
43 |
0
| junit.textui.TestRunner.run(ConfigServerTest.class);
|
|
44 |
0
| cs.shutdown();
|
|
45 |
0
| System.exit(0);
|
|
46 |
| } |
|
47 |
| |
|
48 |
0
| public void setUp() throws Exception {
|
|
49 |
| } |
|
50 |
| |
|
51 |
0
| public void testStartServer() {
|
|
52 |
0
| java.net.URL jcfURL = null;
|
|
53 |
0
| InputStream is = null;
|
|
54 |
0
| try {
|
|
55 |
0
| ConfigServerHandler urlHandler = new ConfigServerHandler();
|
|
56 |
0
| urlHandler.setURL(URL+"/config");
|
|
57 |
0
| Configuration config = urlHandler.load();
|
|
58 |
0
| assertNotNull(config);
|
|
59 |
0
| assertEquals("testuser",config.getProperty("USER",null,"JDBC"));
|
|
60 |
| } |
|
61 |
| catch ( Exception e ) { |
|
62 |
0
| e.printStackTrace();
|
|
63 |
| } |
|
64 |
| } |
|
65 |
| |
|
66 |
0
| public void testAnotherServer() {
|
|
67 |
0
| java.net.URL jcfURL = null;
|
|
68 |
0
| InputStream is = null;
|
|
69 |
0
| try {
|
|
70 |
0
| ConfigServerHandler urlHandler = new ConfigServerHandler();
|
|
71 |
0
| urlHandler.setURL(URL+"/serverconfig");
|
|
72 |
0
| Configuration config = urlHandler.load();
|
|
73 |
0
| assertNotNull(config);
|
|
74 |
0
| assertEquals("serveruser",config.getProperty("USER",null,"JDBC"));
|
|
75 |
| } |
|
76 |
| catch ( Exception e ) { |
|
77 |
0
| e.printStackTrace();
|
|
78 |
| } |
|
79 |
| } |
|
80 |
| |
|
81 |
0
| public void testNoFileFound() {
|
|
82 |
0
| java.net.URL jcfURL = null;
|
|
83 |
0
| InputStream is = null;
|
|
84 |
0
| try {
|
|
85 |
0
| ConfigServerHandler urlHandler = new ConfigServerHandler();
|
|
86 |
0
| urlHandler.setURL(URL+"/memyselfandi");
|
|
87 |
0
| Configuration config = urlHandler.load();
|
|
88 |
0
| fail("exception expected");
|
|
89 |
| } |
|
90 |
| catch ( Exception e ) { |
|
91 |
| } |
|
92 |
| } |
|
93 |
| } |