Skip to content

Commit

Permalink
fix: handled mongo configuration to support mongodb+srv
Browse files Browse the repository at this point in the history
  • Loading branch information
simone-lungarella committed Oct 2, 2023
1 parent ef910e1 commit 6081512
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClients;

import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.mongo.MongoLockProvider;

Expand All @@ -34,7 +38,11 @@ public class MongoDatabaseCFG {

@Bean
public MongoDatabaseFactory mongoDatabaseFactory(final MongoPropertiesCFG mongoPropertiesCFG){
return new SimpleMongoClientDatabaseFactory(mongoPropertiesCFG.getUri());
ConnectionString connectionString = new ConnectionString(mongoPropertiesCFG.getUri());
MongoClientSettings mongoClientSettings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.build();
return new SimpleMongoClientDatabaseFactory(MongoClients.create(mongoClientSettings), mongoPropertiesCFG.getSchemaName());
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ public class MongoPropertiesCFG {

@Value("${data.mongodb.uri}")
private String uri;

@Value("${data.mongodb.schema-name}")
private String schemaName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
import it.finanze.sanita.fse2.ms.gtw.statusmanager.scheduler.actions.ActionBuilderEDS;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.scheduler.actions.base.IActionStepEDS;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.scheduler.actions.base.IExecutableEDS;
import lombok.extern.slf4j.Slf4j;

import java.util.LinkedHashMap;

@Slf4j
public abstract class LExecutor implements IExecutableEDS {

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ management.server.port=8013
# Database
#######################################
data.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse
data.mongodb.schema-name=FSE_GTW

#######################################
# KAFKA
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-docker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ management.server.port=8013
# Database
#######################################
data.mongodb.uri=mongodb://mongoadmin:[email protected]:27888/fse
data.mongodb.schema-name=FSE_GTW

#######################################
# KAFKA
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ log.level=trace
# DATASOURCE DB
#######################################
data.mongodb.uri=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@<mondodb_hostname>:<mondodb_port>/<mondodb_dbname>
data.mongodb.schema-name=${MONGO_DBNAME}

#######################################
# KAFKA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package it.finanze.sanita.fse2.ms.gtw.statusmanager;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;

import org.junit.jupiter.api.DisplayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
*/
package it.finanze.sanita.fse2.ms.gtw.statusmanager;

import it.finanze.sanita.fse2.ms.gtw.statusmanager.client.IConfigClient;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.client.IProcessorClient;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.config.Constants;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.dto.client.processor.res.tx.DeleteTxResDTO;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.dto.client.processor.res.tx.GetTxResDTO;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.enums.ActionRes;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.repository.entity.FhirEvent;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.repository.mongo.ITransactionEventsRepo;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.scheduler.executors.impl.TxExecutor;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.springframework.http.HttpMethod.DELETE;

import java.util.ArrayList;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -35,11 +32,13 @@
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.springframework.http.HttpMethod.DELETE;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.client.IConfigClient;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.config.Constants;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.dto.client.processor.res.tx.DeleteTxResDTO;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.dto.client.processor.res.tx.GetTxResDTO;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.enums.ActionRes;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.repository.entity.FhirEvent;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.scheduler.executors.impl.TxExecutor;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles(Constants.Profile.TEST)
Expand All @@ -48,15 +47,9 @@ class TxExecutorTest {
@Autowired
private TxExecutor txExecutor;

@Autowired
private IProcessorClient processorClient;

@MockBean
private IConfigClient configClient;

@Autowired
private ITransactionEventsRepo transaction;

@Autowired
private MongoTemplate mongoTemplate;

Expand Down Expand Up @@ -121,7 +114,6 @@ void executorFailureTestOnProcess() {
void executorFailureTestOnDelete() {
GetTxResDTO first = TestUtility.createFirstTxLinksMock();
GetTxResDTO last = TestUtility.createLastTxLinksMock();
DeleteTxResDTO deleted = TestUtility.createDeletedTransactionMock();

Mockito.when(configClient.getExpirationDate()).thenReturn(5);

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ kafka.enablessl=false
# Database
#######################################
data.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse
data.mongodb.schema-name=FSE_GTW

####### LOGGING OUTPUT FORMAT ############
# Must be one of console, json
Expand Down

0 comments on commit 6081512

Please sign in to comment.