blob: fcc04faa2e0aac8041c544dd0dc2358edd1e345c (
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
|
package testing.protocols;
import testing.*;
import org.junit.jupiter.api.*;
/**
* Base class for protocol tests providing common setup and utilities.
*/
public abstract class BaseProtocolTest {
protected HeadlessSimulationRunner runner;
@BeforeEach
public void baseSetup() {
runner = new HeadlessSimulationRunner();
}
@AfterEach
public void baseTeardown() {
if (runner != null) {
runner.shutdown();
}
}
/**
* Run a simulation and get the result with error handling.
*/
protected SimulationResult runSimulation(String file, long duration) {
try {
SimulationResult result = runner.runSimulation(file, duration);
// Check if any messages were sent
int totalMessages = result.getMetrics().getTotalMessageCount();
if (totalMessages == 0) {
throw new AssertionError("Protocol test failed: No messages were sent during simulation of " + file);
}
return result;
} catch (Exception e) {
throw new RuntimeException("Failed to run simulation: " + file, e);
}
}
/**
* Create a basic verifier that checks for no errors.
*/
protected ProtocolVerifier createBasicVerifier() {
return new ProtocolVerifier()
.expectNoLog("ERROR")
.expectNoLog("Exception")
.expectNoLog("null")
.expectNoLog("NullPointer");
}
}
|