Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
Signed-off-by: tvallin <[email protected]>
  • Loading branch information
tvallin committed Dec 15, 2023
1 parent 810ff95 commit 8e7e467
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
10 changes: 5 additions & 5 deletions examples/dbclient/mongodb/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ db:
"query": { ping: 1 }
}'
# Insert operation contains collection name, operation type and data to be inserted.
# Name variable is stored as MongoDB primary key attribute name
# Name variable is stored as MongoDB primary key attribute _id
insert2: '{
"collection": "pokemons",
"value": {
"name": $name,
"_id": $name,
"type": $type
}
}'
Expand All @@ -51,7 +51,7 @@ db:
select-one: '{
"collection": "pokemons",
"query": {
"name": ?
"_id": ?
}
}'
delete-all: '{
Expand All @@ -61,7 +61,7 @@ db:
update: '{
"collection": "pokemons",
"query": {
"name": $name
"_id": $name
},
"value": {
$set: { "type": $type }
Expand All @@ -70,7 +70,7 @@ db:
delete: '{
"collection": "pokemons",
"query": {
"name": ?
"_id": ?
}
}'

Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ public class MainIT {
.withExposedPorts(27017);

private static final JsonBuilderFactory JSON_FACTORY = Json.createBuilderFactory(Map.of());
private static final String CONNECTION_URL_KEY = "db.connection.url";

private static WebServer server;
private static WebClient client;

@BeforeAll
static void beforeAll() {
String url = String.format("mongodb://127.0.0.1:%s/pokemon", container.getMappedPort(27017));
System.setProperty("db.connection.url", url);
System.setProperty(CONNECTION_URL_KEY, url);
server = MongoDbExampleMain.setupServer(WebServer.builder());
client = WebClient.create(config -> config.baseUri("http://localhost:" + server.port())
.addMediaSupport(JsonbSupport.create(Config.create()))
Expand All @@ -68,6 +69,7 @@ static void afterAll() {
if (server != null && server.isRunning()) {
server.stop();
}
System.clearProperty(CONNECTION_URL_KEY);
}

@Test
Expand Down Expand Up @@ -106,7 +108,7 @@ void testAddUpdateDeletePokemon() {
// Get the new pokemon added
jsonResponse = client.get("/db/Raticate").request(JsonObject.class);
assertThat(jsonResponse.status(), is(Status.OK_200));
assertThat(jsonResponse.entity().getString("name"), is("Raticate"));
assertThat(jsonResponse.entity().getString("_id"), is("Raticate"));
assertThat(jsonResponse.entity().getString("type"), is("1"));

// Update pokemon
Expand All @@ -116,7 +118,7 @@ void testAddUpdateDeletePokemon() {
// Verify updated pokemon
jsonResponse = client.get("/db/Raticate").request(JsonObject.class);
assertThat(jsonResponse.status(), is(Status.OK_200));
assertThat(jsonResponse.entity().getString("name"), is("Raticate"));
assertThat(jsonResponse.entity().getString("_id"), is("Raticate"));
assertThat(jsonResponse.entity().getString("type"), is("2"));

// Delete Pokemon
Expand All @@ -131,6 +133,6 @@ void testAddUpdateDeletePokemon() {
private List<String> listAllPokemons() {
ClientResponseTyped<JsonArray> response = client.get("/db").request(JsonArray.class);
assertThat(response.status(), is(Status.OK_200));
return response.entity().stream().map(e -> e.asJsonObject().getString("name")).toList();
return response.entity().stream().map(e -> e.asJsonObject().getString("_id")).toList();
}
}
5 changes: 0 additions & 5 deletions examples/dbclient/pokemons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@
<artifactId>helidon-logging-jul</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ private static void startServer() {
Config config = mongo ? Config.create(ConfigSources.classpath(MONGO_CFG)) : Config.create();
Config.global(config);

WebServer server = setupServer(WebServer.builder())
.start();
WebServer server = setupServer(WebServer.builder());

System.out.println("WEB server is up! http://localhost:" + server.port() + "/");
}
Expand All @@ -96,7 +95,8 @@ static WebServer setupServer(WebServerConfig.Builder builder) {
return builder.config(config.get("server"))
.addFeature(observe)
.routing(Main::routing)
.build();
.build()
.start();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ abstract class AbstractPokemonServiceTest {
private static WebClient client;

static void beforeAll() {
server = Main.setupServer(WebServer.builder()).start();
server = Main.setupServer(WebServer.builder());
client = WebClient.create(config -> config.baseUri("http://localhost:" + server.port())
.addMediaSupport(JsonpSupport.create())
.addMediaSupport(JsonpSupport.create()));
}

Expand Down

0 comments on commit 8e7e467

Please sign in to comment.