Skip to content

Commit

Permalink
test: fix environment configuration test by starting callback server …
Browse files Browse the repository at this point in the history
…first
  • Loading branch information
cake-lier committed Jan 24, 2024
1 parent b799a49 commit aa8b1e0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 98 deletions.
79 changes: 38 additions & 41 deletions src/test/java/org/hyperagents/yggdrasil/BodyNotificationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,18 @@ public class BodyNotificationTest {
private static final String BODIES_PATH = "/agents/";
private static final String CALLBACK_URL = "http://" + TEST_HOST + ":" + 8081 + "/";

private final List<Promise<Map.Entry<String, String>>> callbackMessages;
private List<Promise<Map.Entry<String, String>>> callbackMessages;
private WebClient client;
private int promiseIndex;

public BodyNotificationTest() {
@BeforeEach
public void setUp(final Vertx vertx, final VertxTestContext ctx) {
this.client = WebClient.create(vertx);
this.callbackMessages =
Stream.generate(Promise::<Map.Entry<String, String>>promise)
.limit(5)
.collect(Collectors.toList());
}

@BeforeEach
public void setUp(final Vertx vertx, final VertxTestContext ctx) {
this.client = WebClient.create(vertx);
this.promiseIndex = 0;
vertx
.eventBus()
.<String>consumer(
Expand All @@ -78,40 +76,39 @@ public void setUp(final Vertx vertx, final VertxTestContext ctx) {
this.promiseIndex++;
}
);
vertx
.deployVerticle(
new MainVerticle(),
new DeploymentOptions().setConfig(JsonObject.of(
"http-config",
JsonObject.of(
"host",
TEST_HOST,
"port",
TEST_PORT
),
"notification-config",
JsonObject.of(
"enabled",
true
),
"environment-config",
JsonObject.of(
"enabled",
true,
"known-artifacts",
JsonArray.of(
JsonObject.of(
"class",
COUNTER_ARTIFACT_CLASS,
"template",
"org.hyperagents.yggdrasil.artifacts.Counter"
)
)
)
))
)
.compose(r -> vertx.deployVerticle(new CallbackServerVerticle()))
.onComplete(ctx.succeedingThenComplete());
vertx.deployVerticle(new CallbackServerVerticle())
.compose(r -> vertx.deployVerticle(
new MainVerticle(),
new DeploymentOptions().setConfig(JsonObject.of(
"http-config",
JsonObject.of(
"host",
TEST_HOST,
"port",
TEST_PORT
),
"notification-config",
JsonObject.of(
"enabled",
true
),
"environment-config",
JsonObject.of(
"enabled",
true,
"known-artifacts",
JsonArray.of(
JsonObject.of(
"class",
COUNTER_ARTIFACT_CLASS,
"template",
"org.hyperagents.yggdrasil.artifacts.Counter"
)
)
)
))
))
.onComplete(ctx.succeedingThenComplete());
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,19 @@ public class EnvironmentConfigurationTest {
private static final String WORKSPACES_PATH = "/workspaces/";
private static final String ARTIFACTS_PATH = "/artifacts/";

private final List<Promise<Map.Entry<String, String>>> callbackMessages;
private List<Promise<Map.Entry<String, String>>> callbackMessages;
private WebClient client;
private int promiseIndex;

public EnvironmentConfigurationTest() {
this.callbackMessages =
Stream.generate(Promise::<Map.Entry<String, String>>promise)
.limit(2)
.collect(Collectors.toList());
}

@BeforeEach
public void setUp(final Vertx vertx, final VertxTestContext ctx)
throws URISyntaxException, IOException {
this.client = WebClient.create(vertx);
this.callbackMessages =
Stream.generate(Promise::<Map.Entry<String, String>>promise)
.limit(2)
.collect(Collectors.toList());
this.promiseIndex = 0;
vertx
.eventBus()
.<String>consumer(
Expand All @@ -66,15 +64,15 @@ public void setUp(final Vertx vertx, final VertxTestContext ctx)
this.promiseIndex++;
}
);
vertx
.deployVerticle(
final var configuration = Files.readString(
Path.of(ClassLoader.getSystemResource("cartago_config.json").toURI()),
StandardCharsets.UTF_8
);
vertx.deployVerticle(new CallbackServerVerticle())
.compose(r -> vertx.deployVerticle(
new MainVerticle(),
new DeploymentOptions().setConfig((JsonObject) Json.decodeValue(Files.readString(
Path.of(ClassLoader.getSystemResource("cartago_config.json").toURI()),
StandardCharsets.UTF_8
)))
)
.compose(r -> vertx.deployVerticle(new CallbackServerVerticle()))
new DeploymentOptions().setConfig((JsonObject) Json.decodeValue(configuration))
))
.onComplete(ctx.succeedingThenComplete());
}

Expand Down
79 changes: 38 additions & 41 deletions src/test/java/org/hyperagents/yggdrasil/MainVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,18 @@ public class MainVerticleTest {
private static final String ARTIFACTS_PATH = "/artifacts/";
private static final String CALLBACK_URL = "http://" + TEST_HOST + ":" + 8081 + "/";

private final List<Promise<Map.Entry<String, String>>> callbackMessages;
private List<Promise<Map.Entry<String, String>>> callbackMessages;
private WebClient client;
private int promiseIndex;

public MainVerticleTest() {
@BeforeEach
public void setUp(final Vertx vertx, final VertxTestContext ctx) {
this.client = WebClient.create(vertx);
this.callbackMessages =
Stream.generate(Promise::<Map.Entry<String, String>>promise)
.limit(9)
.collect(Collectors.toList());
}

@BeforeEach
public void setUp(final Vertx vertx, final VertxTestContext ctx) {
this.client = WebClient.create(vertx);
this.promiseIndex = 0;
vertx
.eventBus()
.<String>consumer(
Expand All @@ -78,40 +76,39 @@ public void setUp(final Vertx vertx, final VertxTestContext ctx) {
this.promiseIndex++;
}
);
vertx
.deployVerticle(
new MainVerticle(),
new DeploymentOptions().setConfig(JsonObject.of(
"http-config",
JsonObject.of(
"host",
TEST_HOST,
"port",
TEST_PORT
),
"notification-config",
JsonObject.of(
"enabled",
true
),
"environment-config",
JsonObject.of(
"enabled",
true,
"known-artifacts",
JsonArray.of(
JsonObject.of(
"class",
COUNTER_ARTIFACT_CLASS,
"template",
"org.hyperagents.yggdrasil.artifacts.Counter"
)
)
)
))
)
.compose(r -> vertx.deployVerticle(new CallbackServerVerticle()))
.onComplete(ctx.succeedingThenComplete());
vertx.deployVerticle(new CallbackServerVerticle())
.compose(r -> vertx.deployVerticle(
new MainVerticle(),
new DeploymentOptions().setConfig(JsonObject.of(
"http-config",
JsonObject.of(
"host",
TEST_HOST,
"port",
TEST_PORT
),
"notification-config",
JsonObject.of(
"enabled",
true
),
"environment-config",
JsonObject.of(
"enabled",
true,
"known-artifacts",
JsonArray.of(
JsonObject.of(
"class",
COUNTER_ARTIFACT_CLASS,
"template",
"org.hyperagents.yggdrasil.artifacts.Counter"
)
)
)
))
))
.onComplete(ctx.succeedingThenComplete());
}

@AfterEach
Expand Down

0 comments on commit aa8b1e0

Please sign in to comment.