01: package net.sourceforge.cruisecontrol.distributed.core;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.cruisecontrol.CruiseControlException;
05:
06: import java.io.File;
07:
08: /**
09: * @author Dan Rollo
10: * Date: Oct 24, 2007
11: * Time: 12:15:23 AM
12: */
13: public class RemoteResultTest extends TestCase {
14:
15: /** expose msg text for use by other unit tests. */
16: public static final String MSG_SUFFIX_BAD_DISTRIBUTED_CHILD_ELEMENT_RESULT = RemoteResult.MSG_SUFFIX_BAD_DISTRIBUTED_CHILD_ELEMENT_RESULT;
17:
18: public static void resetTempZippedFile(
19: final RemoteResult remoteResult) {
20: remoteResult.resetTempZippedFile();
21: }
22:
23: public void testValidate() throws Exception {
24: final int badIdx = -1;
25: try {
26: new RemoteResult(badIdx).validate();
27: fail("Invalid index should have failed.");
28: } catch (CruiseControlException e) {
29: assertEquals("Invalid remoteResult index: " + badIdx, e
30: .getMessage());
31: }
32:
33: final RemoteResult remoteResult = new RemoteResult(0);
34: try {
35: remoteResult.validate();
36: fail("Invalid index should have failed.");
37: } catch (CruiseControlException e) {
38: assertEquals(
39: "'agentDir' is required for "
40: + RemoteResultTest.MSG_SUFFIX_BAD_DISTRIBUTED_CHILD_ELEMENT_RESULT,
41: e.getMessage());
42: }
43: remoteResult.setAgentDir("agent");
44:
45: try {
46: remoteResult.validate();
47: fail("Invalid index should have failed.");
48: } catch (CruiseControlException e) {
49: assertEquals(
50: "'masterDir' is required for "
51: + RemoteResultTest.MSG_SUFFIX_BAD_DISTRIBUTED_CHILD_ELEMENT_RESULT,
52: e.getMessage());
53: }
54: remoteResult.setMasterDir("master");
55:
56: remoteResult.validate();
57: }
58:
59: public void testImutable() throws Exception {
60: final RemoteResult remoteResult = new RemoteResult(0);
61: remoteResult.setAgentDir("agent");
62: try {
63: remoteResult.setAgentDir("reset");
64: fail("Reset should fail");
65: } catch (IllegalStateException e) {
66: assertTrue(e.getMessage().startsWith(
67: "agentDir already set to: "));
68: }
69:
70: remoteResult.setMasterDir("master");
71: try {
72: remoteResult.setMasterDir("reset");
73: fail("Reset should fail");
74: } catch (IllegalStateException e) {
75: assertTrue(e.getMessage().startsWith(
76: "masterDir already set to: "));
77: }
78:
79: remoteResult.storeTempZippedFile(new File("tempZip"));
80: try {
81: remoteResult.storeTempZippedFile(new File("dummy"));
82: fail("Reset should fail");
83: } catch (IllegalStateException e) {
84: assertTrue(e.getMessage().startsWith(
85: "storeTempZippedFile already set to: "));
86: }
87: remoteResult.resetTempZippedFile();
88: remoteResult.storeTempZippedFile(new File("tempZip"));
89: }
90: }
|