Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneNuts committed Dec 18, 2023
1 parent 6e636ec commit f16d3cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;

import it.finanze.sanita.fse2.ms.gtw.statusmanager.service.impl.ConfigSRV;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.common.TopicPartition;
import org.junit.jupiter.api.Test;
Expand All @@ -34,7 +35,6 @@
import org.springframework.messaging.MessageHeaders;
import org.springframework.test.context.ActiveProfiles;

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.exceptions.BusinessException;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.service.IKafkaReceiverSRV;
Expand All @@ -53,14 +53,14 @@ class KafkaReceiverTest {

@Value("${kafka.statusmanager.topic}")
String topic;

@MockBean
private IConfigClient configClient;
private ConfigSRV config;

@Test
@Description("Generic error test on status manager listener - wrong json")
void kafkaReceiverErrorTest() {
given(configClient.getExpirationDate()).willReturn(0);
given(config.getExpirationDate()).willReturn(0);
Map<String, Object> map = new HashMap<>();
MessageHeaders headers = new MessageHeaders(map);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.BDDMockito.given;

import it.finanze.sanita.fse2.ms.gtw.statusmanager.service.impl.ConfigSRV;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
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.statusmanager.client.IConfigClient;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.config.Constants;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.exceptions.BusinessException;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.repository.mongo.impl.TransactionEventsRepo;
Expand All @@ -30,14 +30,14 @@
class RepoTest {

@MockBean
private IConfigClient configClient;
private ConfigSRV config;

@Test
@DisplayName("transaction Events Repo test Ko ")
void transactionEvTestKo() {
TransactionEventsRepo transEvRep = new TransactionEventsRepo();

given(configClient.getExpirationDate()).willReturn(0);
given(config.getExpirationDate()).willReturn(0);
assertThrows(BusinessException.class, () -> transEvRep.saveEvent(null, null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.ArrayList;

import it.finanze.sanita.fse2.ms.gtw.statusmanager.service.impl.ConfigSRV;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -32,7 +33,6 @@
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;

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;
Expand All @@ -48,7 +48,7 @@ class TxExecutorTest {
private TxExecutor txExecutor;

@MockBean
private IConfigClient configClient;
private ConfigSRV config;

@Autowired
private MongoTemplate mongoTemplate;
Expand All @@ -67,7 +67,7 @@ void executorSuccessTest() {
GetTxResDTO last = TestUtility.createLastTxLinksMock();
DeleteTxResDTO deleted = TestUtility.createDeletedTransactionMock();

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

Mockito.when(restTemplate.getForEntity(anyString(), eq(GetTxResDTO.class)))
.thenReturn(new ResponseEntity<>(first, HttpStatus.OK))
Expand All @@ -81,7 +81,7 @@ void executorSuccessTest() {

@Test
void executorFailureTestOnInit() {
Mockito.when(configClient.getExpirationDate()).thenReturn(5);
Mockito.when(config.getExpirationDate()).thenReturn(5);
Mockito.when(restTemplate.getForEntity(anyString(), eq(GetTxResDTO.class)))
.thenThrow(ResourceAccessException.class);
Assertions.assertEquals(ActionRes.KO, txExecutor.execute());
Expand All @@ -91,7 +91,7 @@ void executorFailureTestOnInit() {
void executorFailureTestOnVerify() {
GetTxResDTO first = TestUtility.createFirstTxLinksMock();
first.setWif(new ArrayList<>());
Mockito.when(configClient.getExpirationDate()).thenReturn(5);
Mockito.when(config.getExpirationDate()).thenReturn(5);
Mockito.when(restTemplate.getForEntity(anyString(), eq(GetTxResDTO.class)))
.thenReturn(new ResponseEntity<>(first, HttpStatus.OK));
Assertions.assertEquals(ActionRes.EMPTY, txExecutor.execute());
Expand All @@ -101,7 +101,7 @@ void executorFailureTestOnVerify() {
void executorFailureTestOnProcess() {
GetTxResDTO first = TestUtility.createFirstTxLinksMock();

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

Mockito.when(restTemplate.getForEntity(anyString(), eq(GetTxResDTO.class)))
.thenReturn(new ResponseEntity<>(first, HttpStatus.OK))
Expand All @@ -115,7 +115,7 @@ void executorFailureTestOnDelete() {
GetTxResDTO first = TestUtility.createFirstTxLinksMock();
GetTxResDTO last = TestUtility.createLastTxLinksMock();

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

Mockito.when(restTemplate.getForEntity(anyString(), eq(GetTxResDTO.class)))
.thenReturn(new ResponseEntity<>(first, HttpStatus.OK))
Expand Down

0 comments on commit f16d3cb

Please sign in to comment.