[43] | 1 | package geniusweb.simplerunner;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertTrue;
|
---|
| 4 | import static org.mockito.ArgumentMatchers.any;
|
---|
| 5 | import static org.mockito.ArgumentMatchers.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 | { "src/test/resources/tournamentlearn.json" } });
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public SessionRunnerE2ETest(String file) {
|
---|
| 56 | this.filename = file;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | @Before
|
---|
| 60 | public void before() throws IOException {
|
---|
| 61 | System.out.println("Running from file " + filename);
|
---|
| 62 | String serialized = new String(Files.readAllBytes(Paths.get(filename)),
|
---|
| 63 | StandardCharsets.UTF_8);
|
---|
| 64 | NegoSettings settings = jackson.readValue(serialized,
|
---|
| 65 | NegoSettings.class);
|
---|
| 66 |
|
---|
| 67 | runner = new NegoRunner(settings, new ClassPathConnectionFactory(),
|
---|
| 68 | logger, TEST_RUNTIME);
|
---|
| 69 |
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | @Test
|
---|
| 73 | public void smokeTest() throws IOException {
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | @Test
|
---|
| 77 | public void runTest() throws IOException {
|
---|
| 78 | runner.run();
|
---|
| 79 | System.out.println("Final state:\n" + runner.getProtocol().getState());
|
---|
| 80 | assertTrue(runner.isProperlyStopped());
|
---|
| 81 | verify(logger, times(0)).log(eq(Level.WARNING), any());
|
---|
| 82 | verify(logger, times(0)).log(eq(Level.SEVERE), any());
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | @Test
|
---|
| 86 | public void runTestMainFunction() throws IOException {
|
---|
| 87 | NegoRunner.main(new String[] { filename });
|
---|
| 88 | }
|
---|
| 89 | }
|
---|