001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.simulator.container;
005:
006: import com.tc.test.TCTestCase;
007:
008: import java.io.File;
009: import java.util.ArrayList;
010: import java.util.HashSet;
011: import java.util.Iterator;
012: import java.util.List;
013: import java.util.Set;
014:
015: public class CommandLineContainerBuilderConfigTest extends TCTestCase {
016:
017: CommandLineContainerBuilderConfig cfg;
018:
019: public void testMaster() throws Exception {
020: newConfig(withRequiredArgs("--master"));
021: cfg.parse();
022: assertTrue(cfg.master());
023: }
024:
025: public void testStartServer() throws Exception {
026: newConfig(withRequiredArgs("--start-server"));
027: cfg.parse();
028: assertTrue(cfg.startServer());
029: }
030:
031: public void testOutputToConsole() throws Exception {
032: newConfig(withRequiredArgs("--output=console"));
033: cfg.parse();
034: assertTrue(cfg.outputToConsole());
035: }
036:
037: public void testOutputToFile() throws Exception {
038: String filename = "/tmp";
039: File file = new File(filename);
040: newConfig(withRequiredArgs("--output=" + filename));
041: cfg.parse();
042: assertTrue(cfg.outputToFile());
043: assertEquals(file, cfg.outputFile());
044: }
045:
046: public void testAppConfigBuilder() throws Exception {
047: String classname = getClass().getName();
048: newConfig(withRequiredArgs("--app-config-builder=" + classname));
049: cfg.parse();
050: assertEquals(classname, cfg.appConfigBuilder());
051: }
052:
053: public void testGlobalParticipantCount() throws Exception {
054: int count = 2;
055: String[] args = withRequiredArgs("--global-participant-count="
056: + count);
057: newConfig(args);
058: cfg.parse();
059: assertEquals(count, cfg.globalParticipantCount());
060: }
061:
062: public void testApplicationClassname() throws Exception {
063: String classname = "foobar";
064: String[] args = withRequiredArgs("--application-classname="
065: + classname);
066: newConfig(args);
067: cfg.parse();
068: assertEquals(classname, cfg.applicationClassname());
069: }
070:
071: public void testIntensity() throws Exception {
072: int count = 5;
073: String[] args = withRequiredArgs("--intensity=" + count);
074: newConfig(args);
075: cfg.parse();
076: assertEquals(count, cfg.intensity());
077: }
078:
079: public void testGlobalContainerCount() throws Exception {
080: int count = 2;
081: String[] args = withRequiredArgs("--global-container-count="
082: + count);
083: newConfig(args);
084: cfg.parse();
085: assertEquals(count, cfg.globalContainerCount());
086: }
087:
088: public void testGetApplicationExecCount() throws Exception {
089: int count = 2;
090: newConfig(withRequiredArgs("--app-exec-count=" + count));
091: cfg.parse();
092: assertEquals(count, cfg.getApplicationExecutionCount());
093:
094: newConfig(withRequiredArgs());
095: cfg.parse();
096: assertEquals(1, cfg.getApplicationExecutionCount());
097: }
098:
099: public void testGetContainerStartTimeout() throws Exception {
100: long timeout = 2;
101: newConfig(withRequiredArgs("--container-start-timeout="
102: + timeout));
103: cfg.parse();
104: assertEquals(2, cfg.getContainerStartTimeout());
105:
106: newConfig(withRequiredArgs());
107: cfg.parse();
108: assertEquals(5 * 60 * 1000, cfg.getContainerStartTimeout());
109: }
110:
111: public void testGetApplicationStartTimeout() throws Exception {
112: long timeout = 2;
113: newConfig(withRequiredArgs("--app-start-timeout=" + timeout));
114: cfg.parse();
115: assertEquals(timeout, cfg.getApplicationStartTimeout());
116:
117: newConfig(withRequiredArgs());
118: cfg.parse();
119: assertEquals(5 * 60 * 1000, cfg.getApplicationStartTimeout());
120: }
121:
122: public void testGetApplicationExecutionTimeout() throws Exception {
123: long timeout = 2;
124: newConfig(withRequiredArgs("--app-exec-timeout=" + timeout));
125: cfg.parse();
126: assertEquals(2, cfg.getApplicationExecutionTimeout());
127:
128: newConfig(withRequiredArgs());
129: cfg.parse();
130: assertEquals(30 * 60 * 1000, cfg
131: .getApplicationExecutionTimeout());
132: }
133:
134: public void testDumpErrors() throws Exception {
135: newConfig(withRequiredArgs("--dump-errors"));
136: cfg.parse();
137: assertTrue(cfg.dumpErrors());
138:
139: newConfig(withRequiredArgs());
140: cfg.parse();
141: assertFalse(cfg.dumpErrors());
142: }
143:
144: public void testDumpOutput() throws Exception {
145: newConfig(withRequiredArgs("--dump-output"));
146: cfg.parse();
147: assertTrue(cfg.dumpOutput());
148:
149: newConfig(withRequiredArgs());
150: cfg.parse();
151: assertFalse(cfg.dumpOutput());
152: }
153:
154: public void testAggregate() throws Exception {
155: newConfig(withRequiredArgs("--aggregate"));
156: cfg.parse();
157: assertTrue(cfg.aggregate());
158:
159: newConfig(withRequiredArgs());
160: cfg.parse();
161: assertFalse(cfg.aggregate());
162: }
163:
164: public void testStream() throws Exception {
165: newConfig(withRequiredArgs("--stream"));
166: cfg.parse();
167: assertTrue(cfg.stream());
168:
169: newConfig(withRequiredArgs());
170: cfg.parse();
171: assertFalse(cfg.stream());
172: }
173:
174: private void newConfig(String[] args) {
175: this .cfg = new CommandLineContainerBuilderConfig(args);
176: }
177:
178: private String[] withRequiredArgs() {
179: return (String[]) requiredArgs.toArray(new String[requiredArgs
180: .size()]);
181: }
182:
183: private String[] withRequiredArgs(String arg) {
184: List argList = new ArrayList();
185: argList.add(arg);
186:
187: String argname = (arg.indexOf('=') >= 0) ? arg.substring(0, arg
188: .indexOf('=')) : arg;
189: for (Iterator i = requiredArgs.iterator(); i.hasNext();) {
190: String required = (String) i.next();
191: if (!required.startsWith(argname))
192: argList.add(required);
193: }
194:
195: String[] rv = new String[argList.size()];
196: argList.toArray(rv);
197: return rv;
198: }
199:
200: private static final Set requiredArgs = new HashSet();
201: static {
202: requiredArgs.add("--app-config-builder=alkdfj");
203: requiredArgs.add("--global-participant-count=123");
204: requiredArgs.add("--global-container-count=323");
205: }
206:
207: }
|