01: package com.ibm.emb.junit;
02:
03: /**
04: * this class contains various static helper functions used in the testsuite for
05: * Enterprise Media Beans
06: */
07:
08: public class EMBStaticHelper {
09:
10: /**
11: * static Helper function for logging which should only be used when no EMB
12: * TestConfig object is available, i.e. during initialisation of the
13: * testsuite no writing to a configurable file is possible here
14: */
15: static public void testLog(String msg) {
16: System.out.println("[LOG] :" + msg);
17: }
18:
19: /**
20: * static Helper function for error tracing which should only be used when
21: * no EMB TestConfig object is available, i.e. during initialisation of the
22: * testsuite no writing to a configurable file is possible here
23: */
24: static public void testError(String msg) {
25: System.out.println("[ERROR] :" + msg);
26: }
27:
28: /**
29: * static Helper function for tracing which should only be used when no EMB
30: * TestConfig object is available, i.e. during initialisation of the
31: * testsuite no writing to a configurable file is possible here
32: */
33: static public void testTrace(String msg) {
34: System.out.println("[TRACE] :" + msg);
35: }
36:
37: /**
38: * creates a String of length length with random content
39: */
40: static public String createRandomString(int length) {
41: String result = "";
42: for (int i = 0; i < length; i++) {
43: int branch = randomInt(0, 2);
44: switch (branch) {
45: case 0:
46: result = result + (char) randomInt(65, 90);
47: break;
48: case 1:
49: result = result + (char) randomInt(48, 57);
50: break;
51: case 2:
52: result = result + (char) randomInt(97, 122);
53: break;
54:
55: }
56: }
57: return result;
58: }
59:
60: /**
61: * creates a byte Array String of length length with random content
62: */
63: static public byte[] createRandomByteArray(int length) {
64: // 1024 byte array
65: byte[] result = new byte[length];
66: for (int i = 0; i < length; i++) {
67: result[i] = (byte) Math.round(255 * Math.random());
68: }
69: return result;
70: }
71:
72: /**
73: * creates a random int in range between min and max
74: */
75: static public int randomInt(int min, int max) {
76: int result = min
77: + (Math.round((float) ((max - min) * Math.random())));
78: return result;
79: }
80:
81: }
|