1 package de.tivsource.lib.jcyradm.test;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.Properties;
6
7 import junit.framework.TestCase;
8 import de.tivsource.lib.jcyradm.JCyrAdm;
9 import de.tivsource.lib.jcyradm.exception.AuthenticationFailure;
10 import de.tivsource.lib.jcyradm.exception.NoLogMessagesFile;
11 import de.tivsource.lib.jcyradm.exception.NoPropertiesFile;
12 import de.tivsource.lib.jcyradm.exception.NoServerAnswerFile;
13 import de.tivsource.lib.jcyradm.exception.NoServerResponse;
14 import de.tivsource.lib.jcyradm.exception.NoServerStream;
15 import de.tivsource.lib.jcyradm.exception.UnexpectedServerAnswer;
16
17
18
19
20
21
22
23
24 public class JCyrAdmConnectTest extends TestCase {
25
26 private JCyrAdm jcyradm;
27 private Properties props;
28
29
30
31
32
33
34
35 public JCyrAdmConnectTest(String testName) {
36 super(testName);
37 }
38
39 protected void setUp() throws NoPropertiesFile, NoServerAnswerFile, NoLogMessagesFile {
40
41
42 props = new Properties();
43 InputStream inputStream = getClass().getClassLoader()
44 .getResourceAsStream("JCyrAdmTest.properties");
45 try {
46 props.load(inputStream);
47 inputStream.close();
48 } catch( Exception ex ) {
49 fail("Fehler: Properties-Datei fehlt.");
50 }
51
52 System.setProperty("javax.net.ssl.trustStore", props.getProperty("trustStore"));
53 System.setProperty("javax.net.ssl.trustStorePassword", props.getProperty("trustStorePassword"));
54
55 jcyradm = new JCyrAdm();
56 jcyradm.setAdministrator(props.getProperty("administrator"));
57 jcyradm.setPassword(props.getProperty("password"));
58 jcyradm.setHost(props.getProperty("testServer"));
59 }
60
61 protected void tearDown() {
62 }
63
64
65
66
67
68
69
70 public void testConnect() {
71 try {
72 jcyradm.connect(false);
73 } catch (IOException e) {
74 fail( "Fehler: die Verbindung konnte nicht hergestellt werden." );
75 }
76 try {
77 jcyradm.disconnect();
78 } catch (IOException e) {
79 fail( "Fehler: Es besteht keine Verbindung oder die Verbindung konnte nicht bendet werden." );
80 }
81 }
82
83
84
85
86
87 public void testConnectUnknownHost() {
88 jcyradm.setHost("LiLaLauenBär");
89 try {
90 jcyradm.connect(false);
91 fail("Eine Verbindung herzustellen hätte nicht gelingen sollen.");
92 } catch (IOException e) {
93 assertTrue("Die verbindung zu LiLaLauenBär war wie erwartet nicht erfolgreich", true);
94 }
95 }
96
97
98
99
100
101
102 public void testConnectPort() {
103 jcyradm.setPort(Integer.parseInt(props.getProperty("testPort")));
104 try {
105 jcyradm.connect(false);
106 } catch (IOException e) {
107 fail( "Fehler: die Verbindung konnte nicht hergestellt werden. Es wurde der Port: 143 verwendet" );
108 }
109 try {
110 jcyradm.disconnect();
111 } catch (IOException e) {
112 fail( "Fehler: Es besteht keine Verbindung oder die Verbindung konnte nicht bendet werden." );
113 }
114 }
115
116
117
118
119
120
121 public void testConnectWelcome() throws IOException {
122 jcyradm.connect(false);
123 assertEquals(props.getProperty("welcome"), jcyradm.getWelcomeMsg());
124 jcyradm.disconnect();
125 }
126
127
128 public void testDisconnect() throws IOException {
129 jcyradm.connect(false);
130 jcyradm.disconnect();
131 }
132
133 public void testDisconnectException() throws IOException {
134 jcyradm.connect(false);
135 jcyradm.disconnect();
136 try {
137 jcyradm.disconnect();
138 } catch (IOException e) {
139 assertTrue(true);
140 }
141 }
142
143
144
145
146
147
148
149
150 public void testConnectSSL() throws IOException {
151 jcyradm.connect(true);
152 jcyradm.disconnect();
153 }
154
155
156
157
158
159 public void testConnectSSLUnknownHost() {
160 jcyradm.setHost("LiLaLauenBär");
161 try {
162 jcyradm.connect(true);
163 } catch (IOException e) {
164 assertTrue(true);
165 }
166 }
167
168
169
170
171
172
173 public void testConnectSSLPort() throws IOException {
174 jcyradm.setPort(993);
175 jcyradm.connect(true);
176 jcyradm.disconnect();
177 }
178
179
180
181
182
183
184 public void testConnectSSLWelcome() throws IOException {
185 jcyradm.connect(true);
186 assertEquals(props.getProperty("welcomeSSL"), jcyradm.getWelcomeMsg());
187 jcyradm.disconnect();
188 }
189
190 public void testDisconnectSSL() throws IOException {
191 jcyradm.connect(true);
192 jcyradm.disconnect();
193 }
194
195 public void testDisconnectSSLException() throws IOException {
196 jcyradm.connect(true);
197 jcyradm.disconnect();
198 try {
199 jcyradm.disconnect();
200 } catch (IOException e) {
201 assertTrue(true);
202 }
203 }
204
205 public void testVersion() throws IOException {
206 jcyradm.connect(false);
207 jcyradm.capability();
208 try {
209 jcyradm.login();
210 } catch (NoServerResponse e) {
211
212 e.printStackTrace();
213 } catch (UnexpectedServerAnswer e) {
214
215 e.printStackTrace();
216 } catch (AuthenticationFailure e) {
217
218 e.printStackTrace();
219 }
220 assertEquals(props.getProperty("testVersion"), jcyradm.version());
221 try {
222 jcyradm.logout();
223 } catch (NoServerResponse e) {
224
225 e.printStackTrace();
226 } catch (NoServerStream e) {
227
228 e.printStackTrace();
229 } catch (UnexpectedServerAnswer e) {
230
231 e.printStackTrace();
232 }
233 jcyradm.disconnect();
234 }
235 }