1 | package geniusweb.simplerunner;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertTrue;
|
---|
4 | import static org.mockito.Matchers.any;
|
---|
5 | import static org.mockito.Matchers.eq;
|
---|
6 | import static org.mockito.Mockito.spy;
|
---|
7 | import static org.mockito.Mockito.times;
|
---|
8 | import static org.mockito.Mockito.verify;
|
---|
9 |
|
---|
10 | import java.io.IOException;
|
---|
11 | import java.nio.charset.StandardCharsets;
|
---|
12 | import java.nio.file.Files;
|
---|
13 | import java.nio.file.Paths;
|
---|
14 | import java.util.Arrays;
|
---|
15 | import java.util.Collection;
|
---|
16 | import java.util.logging.Level;
|
---|
17 |
|
---|
18 | import org.junit.Before;
|
---|
19 | import org.junit.Test;
|
---|
20 | import org.junit.runner.RunWith;
|
---|
21 | import org.junit.runners.Parameterized;
|
---|
22 | import org.junit.runners.Parameterized.Parameters;
|
---|
23 |
|
---|
24 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
25 |
|
---|
26 | import geniusweb.protocol.NegoSettings;
|
---|
27 | import tudelft.utilities.logging.ReportToLogger;
|
---|
28 | import tudelft.utilities.logging.Reporter;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * E2E test doing a full real run of a session with real agents and protocol.
|
---|
32 | * NOTICE This will exercise a full system to errors here may point far outside
|
---|
33 | * this module.
|
---|
34 | */
|
---|
35 | @RunWith(Parameterized.class)
|
---|
36 | public class SessionRunnerE2ETest {
|
---|
37 | private static final int TEST_RUNTIME = 5000;
|
---|
38 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
39 | private NegoRunner runner;
|
---|
40 | private Reporter logger = spy(new ReportToLogger("test"));
|
---|
41 | private String filename;
|
---|
42 |
|
---|
43 | @Parameters
|
---|
44 | public static Collection<Object[]> data() {
|
---|
45 | return Arrays
|
---|
46 | .asList(new Object[][] { { "src/test/resources/settings.json" },
|
---|
47 | { "src/test/resources/settings2.json" },
|
---|
48 | { "src/test/resources/settingsbadprofile.json" },
|
---|
49 | { "src/test/resources/shaoptoursettings.json" },
|
---|
50 | { "src/test/resources/mopac.json" },
|
---|
51 | { "src/test/resources/tournament.json" } });
|
---|
52 | }
|
---|
53 |
|
---|
54 | public SessionRunnerE2ETest(String file) {
|
---|
55 | this.filename = file;
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Before
|
---|
59 | public void before() throws IOException {
|
---|
60 | System.out.println("Running from file " + filename);
|
---|
61 | String serialized = new String(Files.readAllBytes(Paths.get(filename)),
|
---|
62 | StandardCharsets.UTF_8);
|
---|
63 | NegoSettings settings = jackson.readValue(serialized,
|
---|
64 | NegoSettings.class);
|
---|
65 |
|
---|
66 | runner = new NegoRunner(settings, new ClassPathConnectionFactory(),
|
---|
67 | logger, TEST_RUNTIME);
|
---|
68 |
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Test
|
---|
72 | public void smokeTest() throws IOException {
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Test
|
---|
76 | public void runTest() throws IOException {
|
---|
77 | runner.run();
|
---|
78 | System.out.println("Final state:\n" + runner.getProtocol().getState());
|
---|
79 | assertTrue(runner.isProperlyStopped());
|
---|
80 | verify(logger, times(0)).log(eq(Level.WARNING), any());
|
---|
81 | verify(logger, times(0)).log(eq(Level.SEVERE), any());
|
---|
82 | }
|
---|
83 |
|
---|
84 | @Test
|
---|
85 | public void runTestMainFunction() throws IOException {
|
---|
86 | NegoRunner.main(new String[] { filename });
|
---|
87 | }
|
---|
88 | }
|
---|