Skip to content

Commit

Permalink
Update CarmaCloudInstanceTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
kruegersp authored Apr 24, 2024
1 parent 6ccf7a5 commit aaed398
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CarmaCloudInstanceTest {

private CarmaCloudInstance instance;
private TimeSyncMessage parsedMessage;
private HttpServer oSrvr;
// private HttpServer oSrvr;

class TimeSyncHandler implements HttpHandler {
@Override
Expand All @@ -54,16 +54,16 @@ public void handle(HttpExchange oExch) throws IOException {
@Before
public void setUp() throws IOException {
instance = new CarmaCloudInstance("carma-cloud", "http://localhost:8080/carmacloud/simulation");
oSrvr = HttpServer.create(new InetSocketAddress("localhost", 8080), 0);
HttpContext oCtx = oSrvr.createContext("/carmacloud/simulation");
oCtx.setHandler(new TimeSyncHandler());
oSrvr.start();
// oSrvr = HttpServer.create(new InetSocketAddress("localhost", 8080), 0);
// HttpContext oCtx = oSrvr.createContext("/carmacloud/simulation");
// oCtx.setHandler(new TimeSyncHandler());
// oSrvr.start();
}

@After
public void tearDown() throws IOException {
oSrvr.stop(0);
}
// @After
// public void tearDown() throws IOException {
// oSrvr.stop(0);
// }

@Test
public void testGetterSetterConstructor() {
Expand All @@ -74,6 +74,12 @@ public void testGetterSetterConstructor() {

@Test
public void testSendTimeSyncMsg() throws IOException {
// setup dummy servlet container
HttpServer oSrvr = HttpServer.create(new InetSocketAddress("localhost", 8080), 0);
HttpContext oCtx = oSrvr.createContext("/carmacloud/simulation");
oCtx.setHandler(new TimeSyncHandler());
oSrvr.start();

// Test SendTimeSyncMsg method
TimeSyncMessage test_msg = new TimeSyncMessage(999L, 11);
instance.sendTimeSyncMsg(test_msg);
Expand All @@ -84,5 +90,6 @@ public void testSendTimeSyncMsg() throws IOException {
assertEquals(parsedMessage.getTimestep(), 999L);
assertEquals(parsedMessage.getSeq(), 11);
}
oSrvr.stop();
}
}

0 comments on commit aaed398

Please sign in to comment.