1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package name.angoca.zemucan;
30
31 import name.angoca.zemucan.core.syntactic.impl.ImplementationSyntacticAnalyzer;
32 import name.angoca.zemucan.executer.api.ExecutionState;
33 import name.angoca.zemucan.executer.impl.ImplementationExecuter;
34 import name.angoca.zemucan.grammarReader.api.GrammarReaderController;
35 import name.angoca.zemucan.tools.Constants;
36 import name.angoca.zemucan.tools.configurator.Configurator;
37 import name.angoca.zemucan.tools.test.RandomTestRunner;
38 import name.angoca.zemucan.ui.api.OutputWriter;
39 import name.angoca.zemucan.ui.impl.system.SystemOutputWriter;
40
41 import org.junit.After;
42 import org.junit.Assert;
43 import org.junit.BeforeClass;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 @RunWith(RandomTestRunner.class)
63 public final class IntegrationTest {
64
65
66
67
68
69
70
71 @BeforeClass
72 public static void setUpBeforeClass() throws AbstractZemucanException {
73 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
74 "sa_conf-test.xml");
75 Configurator.getInstance().setProperty(
76 Constants.GRAMMAR_READER_NAME_PROPERTY,
77 Configurator.GRAMMAR_READER_NAME_VALUE);
78 Configurator.getInstance()
79 .setProperty(Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
80 "grammar-test.xml");
81 ImplementationSyntacticAnalyzer.getInstance();
82 }
83
84
85
86
87 public IntegrationTest() {
88
89 }
90
91
92
93
94 @After
95 public void tearDown() {
96
97 Configurator.destroyInstance();
98
99 GrammarReaderController.destroyInstance();
100
101
102 ImplementationSyntacticAnalyzer.destroyInstance();
103
104 ImplementationExecuter.destroyInstance();
105 }
106
107
108
109
110
111
112
113 @Test
114 public void testExecute() throws AbstractZemucanException {
115 final String command = "hostname";
116 final OutputWriter writer = new SystemOutputWriter();
117
118 final ExecutionState actual = ImplementationExecuter.getInstance()
119 .execute(command, writer);
120
121 final ExecutionState expected = ExecutionState.EXECUTED;
122
123 Assert.assertEquals("Execution of 'hostname'", expected, actual);
124 }
125
126
127
128
129
130
131
132 @Test
133 public void testExecuteExit() throws AbstractZemucanException {
134 final String command = "exit";
135 final OutputWriter writer = new SystemOutputWriter();
136
137 final ExecutionState actual = ImplementationExecuter.getInstance()
138 .execute(command, writer);
139
140 final ExecutionState expected = ExecutionState.APPLICATION_EXIT;
141
142 Assert.assertEquals("Execution of 'exit'", expected, actual);
143 }
144
145
146
147
148
149
150
151 @Test
152 public void testExecuteNullCommand() throws AbstractZemucanException {
153 final String command = null;
154
155 final OutputWriter writer = null;
156
157 Exception e = null;
158 try {
159 ImplementationExecuter.getInstance().execute(command, writer);
160 } catch (final Exception exception) {
161 e = exception;
162 }
163 Assert.assertTrue("ParameterNullException",
164 e instanceof ParameterNullException);
165 }
166
167
168
169
170
171
172
173 @Test
174 public void testExecuteNullWriter() throws AbstractZemucanException {
175 final String command = "command";
176
177 final OutputWriter writer = null;
178
179 Exception e = null;
180 try {
181 ImplementationExecuter.getInstance().execute(command, writer);
182 } catch (final Exception exception) {
183 e = exception;
184 }
185 Assert.assertTrue("ParameterNullException",
186 e instanceof ParameterNullException);
187 }
188
189
190
191
192
193
194
195 @Test
196 public void testExecuteQuit() throws AbstractZemucanException {
197 final String command = "quit";
198 final OutputWriter writer = new SystemOutputWriter();
199
200 final ExecutionState actual = ImplementationExecuter.getInstance()
201 .execute(command, writer);
202
203 final ExecutionState expected = ExecutionState.APPLICATION_EXIT;
204
205 Assert.assertEquals("Execution of 'quit'", expected, actual);
206 }
207 }