generated from pagopa/template-java-spring-microservice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93fc9ac
commit 809b2e0
Showing
11 changed files
with
172 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/main/java/it/gov/pagopa/standinmanager/repository/entity/BlacklistStation.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/test/java/it/gov/pagopa/standinmanager/ConfigServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package it.gov.pagopa.standinmanager; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.*; | ||
|
||
import com.microsoft.azure.kusto.data.exceptions.DataClientException; | ||
import com.microsoft.azure.kusto.data.exceptions.DataServiceException; | ||
import com.microsoft.azure.kusto.data.exceptions.KustoServiceQueryError; | ||
import it.gov.pagopa.standinmanager.config.model.ConfigDataV1; | ||
import it.gov.pagopa.standinmanager.config.model.Station; | ||
import it.gov.pagopa.standinmanager.service.ConfigService; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.openapitools.client.api.CacheApi; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ConfigServiceTest { | ||
|
||
@Mock | ||
private CacheApi cacheApi; | ||
|
||
@InjectMocks | ||
private ConfigService configService; | ||
|
||
@BeforeEach | ||
void setUp() throws KustoServiceQueryError, DataServiceException, DataClientException { | ||
ConfigDataV1 configDataV1 = new ConfigDataV1(); | ||
Map<String, Station> stations = new HashMap<>(); | ||
Station station1 = new Station(); | ||
Station station2 = new Station(); | ||
stations.put("station1",station1); | ||
stations.put("station2",station2); | ||
configDataV1.setStations(stations); | ||
when(cacheApi.cache()).thenReturn(configDataV1); | ||
|
||
} | ||
|
||
@Test | ||
void test1() throws Exception { | ||
configService.loadCache(); | ||
ConfigDataV1 cache = configService.getCache(); | ||
verify(cacheApi, times(1)).cache(); | ||
assertEquals(cache.getStations().size(),2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,11 @@ | |
import static org.mockito.Mockito.*; | ||
|
||
import com.azure.cosmos.CosmosClient; | ||
import com.azure.cosmos.CosmosContainer; | ||
import com.azure.cosmos.CosmosDatabase; | ||
import com.azure.messaging.eventhubs.EventDataBatch; | ||
import com.azure.messaging.eventhubs.EventHubProducerClient; | ||
import com.microsoft.azure.kusto.data.Client; | ||
import com.microsoft.azure.kusto.data.KustoOperationResult; | ||
import com.microsoft.azure.kusto.data.exceptions.DataClientException; | ||
import com.microsoft.azure.kusto.data.exceptions.DataServiceException; | ||
import com.microsoft.azure.kusto.data.exceptions.KustoServiceQueryError; | ||
|
@@ -25,7 +28,9 @@ | |
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.testcontainers.shaded.com.fasterxml.jackson.databind.util.ArrayIterator; | ||
import software.amazon.awssdk.services.ses.SesClient; | ||
import software.amazon.awssdk.services.ses.model.SendEmailRequest; | ||
import software.amazon.awssdk.services.ses.model.SendEmailResponse; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class NodoCalcServiceTest { | ||
|
@@ -37,22 +42,46 @@ class NodoCalcServiceTest { | |
@Mock private CosmosNodeDataRepository cosmosNodeDataRepository = mock(CosmosNodeDataRepository.class); | ||
@Mock private CosmosStationRepository cosmosStationsRepository = mock(CosmosStationRepository.class); | ||
@Mock private DatabaseStationsRepository databaseStationsRepository = mock(DatabaseStationsRepository.class); | ||
@Mock private CosmosEventsRepository cosmosEventsRepository = mock(CosmosEventsRepository.class); | ||
@Mock private EventHubService eventHubService; | ||
@Mock private MailService awsSesClient; | ||
|
||
private CosmosEventsRepository cosmosEventsRepository = spy(new CosmosEventsRepository()); | ||
private EventHubService eventHubService = new EventHubService(); | ||
private MailService mailService = new MailService(); | ||
|
||
@Mock private EventHubProducerClient producer; | ||
@Mock private SesClient sesClient; | ||
EventDataBatch testBatch = mock(EventDataBatch.class); | ||
@Mock private SendEmailResponse testResponse; | ||
@Mock private CosmosDatabase cosmosDatabase; | ||
@Mock private CosmosContainer cosmosContainer; | ||
|
||
@InjectMocks | ||
private NodoCalcService nodoCalcService; | ||
|
||
@BeforeEach | ||
void setUp() throws KustoServiceQueryError, DataServiceException, DataClientException { | ||
org.springframework.test.util.ReflectionTestUtils.setField(cosmosEventsRepository, "cosmosClient", cosmosClient); | ||
org.springframework.test.util.ReflectionTestUtils.setField(mailService, "sesClient", sesClient); | ||
org.springframework.test.util.ReflectionTestUtils.setField(mailService, "from", "[email protected]"); | ||
org.springframework.test.util.ReflectionTestUtils.setField(mailService, "mailto", "[email protected]"); | ||
org.springframework.test.util.ReflectionTestUtils.setField(nodoCalcService, "mailService", mailService); | ||
org.springframework.test.util.ReflectionTestUtils.setField(eventHubService, "producer", producer); | ||
org.springframework.test.util.ReflectionTestUtils.setField( | ||
eventHubService, "om", new com.fasterxml.jackson.databind.ObjectMapper().findAndRegisterModules()); | ||
org.springframework.test.util.ReflectionTestUtils.setField(nodoCalcService, "eventHubService", eventHubService); | ||
org.springframework.test.util.ReflectionTestUtils.setField(nodoCalcService, "slotMinutes", 1); | ||
org.springframework.test.util.ReflectionTestUtils.setField(nodoCalcService, "rangeMinutes", 5); | ||
org.springframework.test.util.ReflectionTestUtils.setField(nodoCalcService, "sendEvent", true); | ||
org.springframework.test.util.ReflectionTestUtils.setField(nodoCalcService, "saveDB", true); | ||
// when(kustoClient.execute(any(),any(),any())).thenReturn(new KustoOperationResult("{ \"Tables\":[ \"RE\"] }","")); | ||
// when(cosmosNodeDataRepository.saveAll(any())).thenReturn(new ArrayIterator<>(null)); | ||
// when(standInStationsRepository.getStations()).thenReturn(List.of(new CosmosStandInStation("","station1", Instant.now()),new CosmosStandInStation("","station2", Instant.now()))); | ||
|
||
when(cosmosClient.getDatabase(any())).thenReturn(cosmosDatabase); | ||
when(cosmosDatabase.getContainer(any())).thenReturn(cosmosContainer); | ||
when(testBatch.tryAdd(any())).thenReturn(true); | ||
when(testBatch.getCount()).thenReturn(2); | ||
when(producer.createBatch()).thenReturn(testBatch); | ||
when(sesClient.sendEmail(any(SendEmailRequest.class))).thenReturn(testResponse); | ||
when(cosmosNodeDataRepository.getStationCounts(any())) | ||
.thenReturn( | ||
List.of( | ||
|
@@ -65,10 +94,10 @@ void setUp() throws KustoServiceQueryError, DataServiceException, DataClientExce | |
@Test | ||
void test1() throws Exception { | ||
nodoCalcService.runCalculations(); | ||
verify(eventHubService, times(2)).publishEvent(any(),any(),any()); | ||
verify(producer, times(2)).send(any(EventDataBatch.class)); | ||
verify(databaseStationsRepository, times(2)).save(any()); | ||
verify(cosmosStationsRepository, times(2)).save(any()); | ||
verify(cosmosEventsRepository, times(2)).newEvent(any(),any(),any()); | ||
verify(awsSesClient, times(2)).sendEmail(any(),any()); | ||
verify(sesClient, times(2)).sendEmail(any(SendEmailRequest.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.