Skip to content

Commit

Permalink
BC-7240 - test dto class
Browse files Browse the repository at this point in the history
  • Loading branch information
mamutmk5 authored Jul 12, 2024
1 parent b1b92c3 commit 6589d56
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/main/java/de/svs/doido/mongo/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.mongodb.client.MongoDatabase;
import java.util.List;

import svs.doido.mongo.dto.MongoServer;

@Path("/admin")
public class Admin {

Expand All @@ -30,14 +32,7 @@ public Admin(KubernetesClient kubernetesClient) {
@Path("/{clientname}")
public void testConnect(String clientname) {
String uri = "mongodb://mongodb-2.mongo-svc:27017/replicaSet=rs0&directConnection=false";
ServerApi serverApi = ServerApi.builder()
.version(ServerApiVersion.V1)
.build();
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(new ConnectionString(uri))
.serverApi(serverApi)
.build();
try (MongoClient mongoClient = MongoClients.create(settings)) {
try (MongoClient mongoClient = new MongoServer(clientname, uri).getMongoClient()) {
MongoDatabase database = mongoClient.getDatabase(clientname);
try {
// Send a ping to confirm a successful connection
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/de/svs/doido/mongo/db/MongoApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package svs.doido.mongo.db;

import svs.doido.mongo.dto.Configmap;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.client.KubernetesClient;
import jakarta.inject.Inject;
import jakarta.enterprise.context.ApplicationScoped;


@ApplicationScoped
public class MongoApp {

}
45 changes: 45 additions & 0 deletions src/main/java/de/svs/doido/mongo/dto/MogoServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package svs.doido.mongo.dto;

import lombok.Getter;
import lombok.ToString;
import lombok.EqualsAndHashCode;
import com.mongodb.*;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;


@ToString
@EqualsAndHashCode
public class MongoServer {
@Getter
private String name;

@Getter
private MongoClient mongoClient;

@Getter
private ConnectionString connectionString;

public void MongoServer(String name, String connectionString) {
if (name == null ) {
throw new NullPointerException();
}
if (connectionString == null) {
throw new NullPointerException();
}
else {
this.connectionString = new ConnectionString(connectionString);
}
ServerApi serverApi = ServerApi.builder()
.version(ServerApiVersion.V1)
.build();
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(this.connectionString)
.applicationName(name)
.serverApi(serverApi)
.build();
mongoClient = MongoClients.create(settings);
}

}

0 comments on commit 6589d56

Please sign in to comment.