summaryrefslogtreecommitdiffstats
path: root/java/src/rasj/test/Systemtest_rasj.java
blob: 50c33c5a1f0234fdc2b8e1131b4ff3c0745d7457 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package rasj.test;

/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
/** ***********************************************************
 * <pre>
 *
 * PURPOSE:
 *
 *
 *
 * COMMENTS:
 *
 * </pre>
 *********************************************************** */

import java.io.*;

import rasj.*;
import rasj.global.*;
import org.odmg.*;


// auxiliary classes for exception testing
class TestRasResultIsNoCellException extends RasResultIsNoCellException
{
    TestRasResultIsNoCellException()
    {
	super();
    }
}

class TestRasResultIsNoIntervalException extends RasResultIsNoIntervalException
{
    TestRasResultIsNoIntervalException()
    {
	super();
    }
}

class TestRasClientInternalException extends RasClientInternalException
{
    TestRasClientInternalException(String msg)
    {
	super("Systemtest_rasj","TestExceptions",msg);
    }
}

// main program
/**
 * class for testing rasj interface
 * @version $$
 */
public class Systemtest_rasj
{

public static void main(String[] args)
    {
	String server = null;
	String port = "7001";
	boolean wrongUsage = false;

	// get args
	if(args.length == 0)
	    wrongUsage = true;
	for(int i = 0; i < args.length; i+=2)
	    {
		if (args[i].equals("-server"))
		    server = args[i+1];
		else if (args[i].equals("-port"))
		    port = args[i+1];
		else
		    wrongUsage = true;
	    }

	if(wrongUsage)
	    {
		System.err.println("Usage: Systemtest_rasj -s <servername> [ -p <port> ]");
		System.exit(-1);
	    }

	// start
	Implementation myApp = new RasImplementation("http://" + server + ":" + port);

	testExceptions(myApp);

        testMArrays marrayTest = new testMArrays(server);

        testIntervals intervalTest = new testIntervals();

    }

    // exception testing
    static void testExceptions(Implementation imp)
    {

	boolean resultIsOk = false;
	Database myDb = null;
	Transaction myTa = null;
	OQLQuery myQu = null;

	System.err.println("\n### Testing exceptions:");

	// RasConnectionFailedException
	Implementation errorApp;
	String logMsg;
	try {
	    errorApp = new RasImplementation("wrongserver:8080");
	    myDb = errorApp.newDatabase();
	    logMsg = "Exception was not thrown";
	    myDb.open("RASBASE",Database.OPEN_READ_WRITE);
	}
	catch(RasConnectionFailedException e1) {
	    resultIsOk = true;
	    logMsg = e1.getMessage();
	}
	catch(ODMGException e2) {
	    logMsg = e2.getMessage();
	}
	log("RasConnectionFailedException",resultIsOk,logMsg);

	// RasDimensionMismatchException
	resultIsOk = false;
	logMsg = "Exception was not thrown";
	try {
	    RasMInterval test1;
	    RasMInterval test2 = new RasMInterval("[1:20,1:20]");
	    RasMInterval test3 = new RasMInterval("[1:4,1:9,1:6]");

	    test1 = test2.intersectionWith(test3);
	}
	catch(RasDimensionMismatchException e1) {
	    resultIsOk = true;
	    logMsg = e1.getMessage();
	}
	catch(Exception e2) {
	    logMsg = e2.getClass().getName() + ", " + e2.getMessage();
	}
	log("RasDimensionMismatchException",resultIsOk,logMsg);

	// RasIndexOutOfBoundsException
	resultIsOk = false;
	logMsg = "Exception was not thrown";
	try {
	    RasGMArray myMDD = new RasGMArray(new RasMInterval("[1:5,1:5]"),1);
	    byte[] retVal = myMDD.getCell(new RasPoint(4,7));
	}
	catch(RasIndexOutOfBoundsException e1) {
	    resultIsOk = true;
	    logMsg = e1.getMessage();
	}
	catch(RasResultIsNoIntervalException e2) {
	    //this cannot occur
	}
	catch(RasDimensionMismatchException e3) {
	    // this cannot occur
	}
	log("RasIndexOutOfBoundsException",resultIsOk,logMsg);

	// RasClientInternalException
	resultIsOk = false;
	logMsg = "Exception was not thrown";
	try {
	    throw new TestRasClientInternalException("This is a test error");
	}
	catch(RasClientInternalException e1) {
	    resultIsOk = true;
	    logMsg = e1.getMessage();
	}
	log("RasClientInternalException",resultIsOk,logMsg);

	// RasResultIsNoCellException
	resultIsOk = false;
	logMsg = "Exception was not thrown";
	try {
	    throw new TestRasResultIsNoCellException();
	}
	catch(RasResultIsNoCellException e1) {
	    resultIsOk = true;
	    logMsg = e1.getMessage();
	}
	log("RasResultIsNoCellException",resultIsOk,logMsg);

	// RasResultIsNoIntervalException
	resultIsOk = false;
	logMsg = "Exception was not thrown";
	try {
	    throw new TestRasResultIsNoIntervalException();
	}
	catch(RasResultIsNoIntervalException e1) {
	    resultIsOk = true;
	    logMsg = e1.getMessage();
	}
	log("RasResultIsNoIntervalException",resultIsOk,logMsg);

	// RasStreamInputOverflowException
	resultIsOk = false;
	logMsg = "Exception was not thrown";
	try {
	    RasMInterval int1 = new RasMInterval(2);
	    int1.stream(new RasSInterval("1:10"));
	    int1.stream(new RasSInterval("1:5"));
	    int1.stream(new RasSInterval("1:20"));
	}
	catch(RasResultIsNoIntervalException e1) {
	    //
	}
	catch(RasStreamInputOverflowException e3) {
	    resultIsOk = true;
	    logMsg = e3.getMessage();
	}
	log("RasStreamInputOverflowException",resultIsOk,logMsg);


	// RasTypeInvalidException
	resultIsOk = false;
	logMsg = "Exception was not thrown";
	try {
	    RasPrimitiveType myType = new RasPrimitiveType("myType",RasGlobalDefs.RAS_BOOLEAN);
	    myType.getFloat(new Object());
	}
	catch(RasTypeInvalidException e3) {
	    resultIsOk = true;
	    logMsg = e3.getMessage();
	}
	log("RasTypeInvalidException",resultIsOk,logMsg);

	// RasTypeNotSupportedException
	resultIsOk = false;
	logMsg = "Exception was not thrown";
	try {
	    throw new RasTypeNotSupportedException("RAS_TEST");
	}
	catch(RasTypeNotSupportedException e3) {
	    resultIsOk = true;
	    logMsg = e3.getMessage();
	}
	log("RasTypeNotSupportedException",resultIsOk,logMsg);
    }





    static void log(String testObject, boolean resultOK, String message)
    {
	if(resultOK)
	    System.err.println(testObject + " ... OK\n     (" + message + ")");
	else
	    {
		System.err.println(testObject + " ... FAILED!\n     (" + message + ")");
		System.err.println("Continue? [y/n]");
		BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
		try {
		String answer = br.readLine();
		while(answer != "")
		    {
		    if(answer.equals("n"))
			System.exit(1);
		    else if(!answer.equals("y"))
			{
			    System.err.println("Please answer y or n: ");
			    answer = br.readLine();
			}
		    }
		}
		catch(IOException e1) {
		    //
		}

	    }
    }


}