From d80f5cf00c0fed366629546c526a2091211721dc Mon Sep 17 00:00:00 2001 From: Alexander Maier Date: Tue, 27 Jun 2023 15:56:21 +0200 Subject: [PATCH] created test class "OfferRetrieverTest" --- .../service/retriever/OfferRetrieverTest.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/test/java/de/rwu/easydrop/service/retriever/OfferRetrieverTest.java diff --git a/src/test/java/de/rwu/easydrop/service/retriever/OfferRetrieverTest.java b/src/test/java/de/rwu/easydrop/service/retriever/OfferRetrieverTest.java new file mode 100644 index 0000000..f29059a --- /dev/null +++ b/src/test/java/de/rwu/easydrop/service/retriever/OfferRetrieverTest.java @@ -0,0 +1,85 @@ +package de.rwu.easydrop.service.retriever; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import javax.naming.ConfigurationException; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import de.rwu.easydrop.api.client.AmazonProductDataSource; +import de.rwu.easydrop.api.client.DataSourceFactory; +import de.rwu.easydrop.api.client.EbayItemDataSource; +import de.rwu.easydrop.api.dto.OfferDTO; +import de.rwu.easydrop.data.connector.OfferPersistenceInterface; +import de.rwu.easydrop.model.Offer; +import de.rwu.easydrop.util.Config; + + + + +class OfferRetrieverTest { + + @Mock + private Config config; + @Mock + private DataSourceFactory dataSourceFactory; + @Mock + private AmazonProductDataSource amazonDataSource; + @Mock + private EbayItemDataSource ebayDataSource; + @Mock + private OfferDTO offerDTO; + @Mock + private Offer offer; + @Mock + private OfferPersistenceInterface persistence; + + private OfferRetriever offerRetriever; + + @BeforeEach + void setUp() throws ConfigurationException { + MockitoAnnotations.openMocks(this); + when(config.getProperty("AMAZON_API_URL")).thenReturn("https://api.amazon.com"); + when(config.getProperty("AMAZON_API_KEY")).thenReturn("amazon-api-key"); + dataSourceFactory.setConfig(config); + offerRetriever = new OfferRetriever(persistence); + } + + @Test + void getOfferFromPersistence(){ + //Arrange + String offerId = "187"; + String lastUpdate = "2023-01-01"; + when(persistence.getOfferDTOById(offerId)).thenReturn(offerDTO); + when(offerDTO.getOfferId()).thenReturn(offerId); + when(offerDTO.getLastUpdate()).thenReturn(lastUpdate); + + //Act + Offer result = offerRetriever.getOfferFromPersistence(offerId); + + //Assert + assertEquals(offerId, result.getOfferId()); + assertEquals(lastUpdate, result.getLastUpdate()); + + //Verify + verify(persistence, times(1)).getOfferDTOById(offerId); + + } + + + + + + + + + + + +}