BAEL-4504: Add finally
This commit is contained in:
parent
40029ed9fc
commit
061fa3d12a
|
@ -85,22 +85,23 @@ public class FindFreePortUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNoPortDefined_whenCreatingJettyServer_thenFreePortIsAssigned() {
|
public void givenNoPortDefined_whenCreatingJettyServer_thenFreePortIsAssigned() throws Exception {
|
||||||
Server jettyServer = new Server();
|
Server jettyServer = new Server();
|
||||||
ServerConnector serverConnector = new ServerConnector(jettyServer);
|
ServerConnector serverConnector = new ServerConnector(jettyServer);
|
||||||
jettyServer.addConnector(serverConnector);
|
jettyServer.addConnector(serverConnector);
|
||||||
try {
|
try {
|
||||||
jettyServer.start();
|
jettyServer.start();
|
||||||
assertThat(serverConnector.getLocalPort()).isGreaterThan(0);
|
assertThat(serverConnector.getLocalPort()).isGreaterThan(0);
|
||||||
jettyServer.stop();
|
|
||||||
jettyServer.destroy();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Failed to start Jetty server");
|
fail("Failed to start Jetty server");
|
||||||
|
} finally {
|
||||||
|
jettyServer.stop();
|
||||||
|
jettyServer.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenExplicitFreePort_whenCreatingJettyServer_thenThatPortIsAssigned() {
|
public void givenExplicitFreePort_whenCreatingJettyServer_thenThatPortIsAssigned() throws Exception {
|
||||||
Server jettyServer = new Server();
|
Server jettyServer = new Server();
|
||||||
ServerConnector serverConnector = new ServerConnector(jettyServer);
|
ServerConnector serverConnector = new ServerConnector(jettyServer);
|
||||||
serverConnector.setPort(FREE_PORT_NUMBER);
|
serverConnector.setPort(FREE_PORT_NUMBER);
|
||||||
|
@ -108,38 +109,41 @@ public class FindFreePortUnitTest {
|
||||||
try {
|
try {
|
||||||
jettyServer.start();
|
jettyServer.start();
|
||||||
assertThat(serverConnector.getLocalPort()).isEqualTo(FREE_PORT_NUMBER);
|
assertThat(serverConnector.getLocalPort()).isEqualTo(FREE_PORT_NUMBER);
|
||||||
jettyServer.stop();
|
|
||||||
jettyServer.destroy();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Failed to start Jetty server");
|
fail("Failed to start Jetty server");
|
||||||
|
} finally {
|
||||||
|
jettyServer.stop();
|
||||||
|
jettyServer.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPortZero_whenCreatingTomcatServer_thenFreePortIsAssigned() {
|
public void givenPortZero_whenCreatingTomcatServer_thenFreePortIsAssigned() throws Exception {
|
||||||
Tomcat tomcatServer = new Tomcat();
|
Tomcat tomcatServer = new Tomcat();
|
||||||
tomcatServer.setPort(0);
|
tomcatServer.setPort(0);
|
||||||
try {
|
try {
|
||||||
tomcatServer.start();
|
tomcatServer.start();
|
||||||
assertThat(tomcatServer.getConnector().getLocalPort()).isGreaterThan(0);
|
assertThat(tomcatServer.getConnector().getLocalPort()).isGreaterThan(0);
|
||||||
tomcatServer.stop();
|
|
||||||
tomcatServer.destroy();
|
|
||||||
} catch (LifecycleException e) {
|
} catch (LifecycleException e) {
|
||||||
fail("Failed to start Tomcat server");
|
fail("Failed to start Tomcat server");
|
||||||
|
} finally {
|
||||||
|
tomcatServer.stop();
|
||||||
|
tomcatServer.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenExplicitFreePort_whenCreatingTomcatServer_thenThatPortIsAssigned() {
|
public void givenExplicitFreePort_whenCreatingTomcatServer_thenThatPortIsAssigned() throws Exception {
|
||||||
Tomcat tomcatServer = new Tomcat();
|
Tomcat tomcatServer = new Tomcat();
|
||||||
tomcatServer.setPort(FREE_PORT_NUMBER);
|
tomcatServer.setPort(FREE_PORT_NUMBER);
|
||||||
try {
|
try {
|
||||||
tomcatServer.start();
|
tomcatServer.start();
|
||||||
assertThat(tomcatServer.getConnector().getLocalPort()).isEqualTo(FREE_PORT_NUMBER);
|
assertThat(tomcatServer.getConnector().getLocalPort()).isEqualTo(FREE_PORT_NUMBER);
|
||||||
tomcatServer.stop();
|
|
||||||
tomcatServer.destroy();
|
|
||||||
} catch (LifecycleException e) {
|
} catch (LifecycleException e) {
|
||||||
fail("Failed to start Tomcat server");
|
fail("Failed to start Tomcat server");
|
||||||
|
} finally {
|
||||||
|
tomcatServer.stop();
|
||||||
|
tomcatServer.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue