Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jooby/src/main/java/io/jooby/Jooby.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ public Jooby() {
} else {
copyState(owner, this);
}
if (BOOT_SERVER != null) {
BOOT_SERVER.init(this);
}
}

@Override
Expand Down Expand Up @@ -1242,6 +1239,9 @@ public static void runApp(
if (server.getOptions().defaults && appServerOptions != null) {
server.setOptions(appServerOptions);
}
for (var app : apps) {
server.init(app);
}
targetServer.start(apps.toArray(new Jooby[0]));
} catch (Throwable startupError) {
try {
Expand Down
54 changes: 54 additions & 0 deletions jooby/src/test/java/io/jooby/Issue3995.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;

import org.junit.jupiter.api.Test;

import io.jooby.output.OutputFactory;

class Issue3995 {

private static class TestServer extends Server.Base {
@Override
public String getName() {
return "test-server";
}

@Override
public OutputFactory getOutputFactory() {
return OutputFactory.create();
}

@Override
public Server start(Jooby... application) {
return this;
}

@Override
public Server stop() {
return this;
}
}

@Test
void serverInitMustRunAfterFinalServerOptionsAreSet() {
var server = new TestServer();
var configured = new ServerOptions().setPort(3995);

Jooby app = Jooby.createApp(server, ExecutionMode.DEFAULT, () -> new Jooby() {});

server.setOptions(configured);
server.init(app);

var registryOptions = app.getServices().require(ServerOptions.class);
assertSame(configured, registryOptions);
assertEquals(3995, registryOptions.getPort());
assertEquals("test-server", registryOptions.getServer());
}
}
12 changes: 9 additions & 3 deletions jooby/src/test/java/io/jooby/JoobyRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

Expand Down Expand Up @@ -93,8 +94,11 @@ void testRunApp_MultipleApps_MutedServer_DefaultsTrue() {

// Verification
// Defaults was true, so server.setOptions should be called with appOptions
verify(server).setOptions(appOptions);
verify(mutedServer).start(new Jooby[] {app1, app2});
InOrder inOrder = inOrder(server, mutedServer);
inOrder.verify(server).setOptions(appOptions);
inOrder.verify(server).init(app1);
inOrder.verify(server).init(app2);
inOrder.verify(mutedServer).start(new Jooby[] {app1, app2});
}

@Test
Expand Down Expand Up @@ -124,7 +128,9 @@ void testRunApp_SingleApp_NormalServer_DefaultsFalse() {

// Verification
verify(server, never()).setOptions(any()); // Because defaults == false
verify(server).start(new Jooby[] {app1});
InOrder inOrder = inOrder(server);
inOrder.verify(server).init(app1);
inOrder.verify(server).start(new Jooby[] {app1});
}

@DisplayName("Test Exception: StartupException thrown, stop throws ignored exception")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private Jooby startApp(ExtensionContext context, JoobyTest metadata) throws Exce
var defaultEnv = System.getProperty("application.env");
System.setProperty("application.env", metadata.environment());
app = Jooby.createApp(server, metadata.executionMode(), reflectionProvider(metadata.value()));
server.init(app);
server.start(app);
if (defaultEnv != null) {
System.setProperty("application.env", defaultEnv);
Expand All @@ -85,6 +86,7 @@ private Jooby startApp(ExtensionContext context, JoobyTest metadata) throws Exce
}
} else {
app = fromFactoryMethod(context, metadata, factoryMethod);
server.init(app);
server.start(app);
}
ExtensionContext.Store store = getStore(context);
Expand Down
1 change: 1 addition & 0 deletions tests/src/test/java/io/jooby/junit/ServerTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void ready(SneakyThrows.Consumer2<WebClient, WebClient> onReady) {
if (options.isSSLEnabled()) {
options.setSecurePort(0);
}
server.init(app);
WebClient https = null;
try {
MutedServer.mute(server).start(app);
Expand Down