-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTestLogSimulator.groovy
More file actions
123 lines (95 loc) · 4.09 KB
/
TestLogSimulator.groovy
File metadata and controls
123 lines (95 loc) · 4.09 KB
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
/*
* Simple test mechanism to ensure that as we make improvements we don't break the individual operations
* can be run by setting environment variable called verbose tov be true to get all output e.g.
* set verbose=true
* The test are then run with the command:
* groovy LogSimulatorTest.groovy -enableassertion
* note the flag needed to ensure the asserts work
*/
import java.util.logging.Level;
import LogSimulator;
class tests {
static final boolean verbose = ((System.getenv("verbose") == null) ||
(System.getenv("verbose").trim().equalsIgnoreCase("true")));
static void log (String msg)
{
if (verbose) {
System.out.println (msg)
}
}
static void testLogToString ()
{
final String msg = "testing A B C";
String dtgFormat = "";
String separator = "!";
String outTemplate = "(%j-%i) %m";
boolean verbose = true;
int counter = 2;
int iterCount = 3;
LogGenerator.testLogEntry.message = msg;
String result = LogGenerator.logToString (LogGenerator.testLogEntry, dtgFormat, separator, outTemplate, verbose, counter, iterCount);
int strMsgIdx = result.indexOf(msg);
int strIterCountIdx = result.indexOf(new String(iterCount));
int strCounterIdx = result.indexOf(new String(counter));
System.out.println ("testLogToString>" + result + " indexed at " + strIdx);
assert (strIdx > -1) : "Missing message content";
assert (strIterCountIdx > -1) : "Missing iteration counter content";
assert (strCounterIdx > -1) : "Missing message counter content";
}
static void testJULMappings ()
{
try
{
Properties props = new Properties();
props.setProperty("DEFAULT-LOGLEVEL", Level.INFO.toString());
log ("testJULMappings prep'd");
Level test = LogGenerator.toJULLevel (null, props);
assert (test == Level.INFO) : "Default to INFO failed";
test = LogGenerator.toJULLevel ("", props);
assert (test == Level.INFO) : "Default to INFO failed";
test = LogGenerator.toJULLevel ("warning", props);
assert (test == Level.WARNING) : "Translate WARNING error";
test = LogGenerator.toJULLevel ("severe", props);
assert (test == Level.SEVERE) : "Translate SEVERE error";
test = LogGenerator.toJULLevel ("fatal", props);
assert (test == Level.SEVERE) : "Translate SEVERE (fatal) error";
test = LogGenerator.toJULLevel ("error", props);
assert (test == Level.SEVERE) : "Translate SEVERE (error) error";
test = LogGenerator.toJULLevel ("info", props);
assert (test == Level.INFO) : "Translate INFO error";
test = LogGenerator.toJULLevel ("information", props);
assert (test == Level.INFO) : "Translate INFO(rmation) error";
test = LogGenerator.toJULLevel ("config", props);
assert (test == Level.CONFIG) : "Translate CONFIG error";
test = LogGenerator.toJULLevel ("fine", props);
assert (test == Level.FINE) : "Translate FINE error";
test = LogGenerator.toJULLevel ("trace", props);
assert (test == Level.FINE) : "Translate FINE (trace) error";
test = LogGenerator.toJULLevel ("finer", props);
assert (test == Level.FINER) : "Translate FINER error";
test = LogGenerator.toJULLevel ("finest", props);
assert (test == Level.FINEST) : "Translate FINEST error";
}
catch (AssertionError err)
{
System.out.println ("JUL Mapping assertions failed\n" + err.toString());
}
System.out.println ("testJULMappings completed");
}
/*
* invokes the required test methods
*/
public static void main (String[] args)
{
try
{
log ("Starting tests ...");
testJULMappings();
testLogToString();
}
catch (Exception err)
{
log("caught:\n" + err.toString());
}
}
}