Skip to content

Commit

Permalink
Merge branch 'feature/fleming' into feature/eds-revolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincenzo Ingenito authored and Vincenzo Ingenito committed Oct 2, 2023
2 parents d147d73 + 2685648 commit 8ace927
Show file tree
Hide file tree
Showing 16 changed files with 455 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
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;


/**
Expand All @@ -39,7 +43,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 @@ -11,6 +11,25 @@
*/
package it.finanze.sanita.fse2.ms.gtw.dispatcher.controller.impl;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import brave.Tracer;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IValidatorClient;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.CDACFG;
Expand All @@ -26,7 +45,15 @@
import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.ValidationCDAReqDTO;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.ErrorResponseDTO;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.LogTraceInfoDTO;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.*;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ActivityEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.DescriptionEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ErrorInstanceEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventCodeEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.InjectionModeEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.RawValidationEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.RestExecutionResultEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.SubjectOrganizationEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.ConnectionRefusedException;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.ValidationException;
Expand All @@ -35,24 +62,6 @@
import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.PDFUtility;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Entities;
import org.jsoup.parser.Parser;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Abstract controller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@
package it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.mongo.impl;


import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.engine.EngineETY;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.mongo.IEngineRepo;
import lombok.extern.slf4j.Slf4j;
import static it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.engine.EngineETY.FIELD_AVAILABLE;
import static it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.engine.EngineETY.FIELD_LAST_SYNC;
import static org.springframework.data.domain.Sort.Direction.DESC;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.limit;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.match;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort;
import static org.springframework.data.mongodb.core.query.Criteria.where;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.TypedAggregation;
import org.springframework.stereotype.Repository;

import static it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.engine.EngineETY.*;
import static org.springframework.data.domain.Sort.Direction.DESC;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.engine.EngineETY;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.mongo.IEngineRepo;

@Repository
public class EngineRepo implements IEngineRepo {
Expand Down

This file was deleted.

This file was deleted.

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=8010
# Database
#######################################
data.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse
data.mongodb.schema-name=FSE_GTW

#######################################
# KAFKA
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ log.kafka-log.enable=true
# 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
@@ -0,0 +1,34 @@
package it.finanze.sanita.fse2.ms.gtw.dispatcher;

import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;

import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.ConnectionRefusedException;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IAccreditamentoSimulationSRV;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IEngineSRV;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.FileUtility;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles(Constants.Profile.TEST)
public class AccreditamentoSimulationTest {

@Autowired
private IAccreditamentoSimulationSRV service;

@MockBean
private IEngineSRV engines;

@Test
void simulationCrashTimeoutTest() {
byte[] pdfAttachment = FileUtility.getFileFromInternalResources("Files/accreditamento/SIGNED_LDO1.pdf");
assertThrows(ConnectionRefusedException.class, () -> service.runSimulation("CRASH_TIMEOUT_id", pdfAttachment, EventTypeEnum.GENERIC_ERROR));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package it.finanze.sanita.fse2.ms.gtw.dispatcher;

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

import java.util.Date;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.ActiveProfiles;

import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.engine.EngineETY;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.mongo.IEngineRepo;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles(Constants.Profile.TEST)
public class EngineRepoTest {

@Autowired
private MongoTemplate mongoTemplate;

@Autowired
private IEngineRepo repository;

@BeforeEach
void init() {
mongoTemplate.dropCollection(EngineETY.class);
}

@Test
void getLatestEngineTest() {
// Data preparation
EngineETY engine = new EngineETY();
engine.setId("id_test");
engine.setLastSync(new Date());
engine.setAvailable(true);
// Insert engine on DB
mongoTemplate.insert(engine);
// Perform getLatestEngine()
EngineETY response = repository.getLatestEngine();
// Assertions
assertEquals(engine.getId(), response.getId());
assertEquals(engine.getLastSync(), response.getLastSync());
assertTrue(response.isAvailable());
}

}
Loading

0 comments on commit 8ace927

Please sign in to comment.