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