Commit d171e7b7 authored by Kali Padhi's avatar Kali Padhi

Updated with offer lookup condition

parent 49e994ef
...@@ -5,15 +5,17 @@ import com.nisum.offertransactionservice.model.OfferLookup; ...@@ -5,15 +5,17 @@ import com.nisum.offertransactionservice.model.OfferLookup;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import javax.swing.text.html.Option; import javax.swing.text.html.Option;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface OfferLookupRepo extends JpaRepository<OfferLookup,String> { public interface OfferLookupRepo extends JpaRepository<OfferLookup,String> {
@Query(value= "SELECT * FROM offer_lookup WHERE id=:hhid" , nativeQuery = true) @Query(value= "SELECT * FROM offer_lookup WHERE id in :ids and offer_type = :offerType" , nativeQuery = true)
public List<OfferLookup> findByHhId(String hhid); public List<OfferLookup> findByHhId(@Param("ids") Collection<String> ids, @Param("offerType") String offerType);
......
...@@ -13,7 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,7 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -36,7 +38,8 @@ public class OfferCallingPEService { ...@@ -36,7 +38,8 @@ public class OfferCallingPEService {
public OfferTransactionResponse getDiscountedItemList(OfferTransactionRequest offerTransactionRequest) { public OfferTransactionResponse getDiscountedItemList(OfferTransactionRequest offerTransactionRequest) {
log.info("Inside getDiscountedItemList Method"); log.info("Inside getDiscountedItemList Method");
List<OfferLookup> eligibleOffer = new ArrayList(); List<OfferLookup> eligibleOffer = new ArrayList();
offerLookupRepo.findByHhId(offerTransactionRequest.getHhId()).forEach(eligibleOffer::add); final List<@NotNull String> idList = Arrays.asList(offerTransactionRequest.getHhId(), "ANY");
offerLookupRepo.findByHhId(idList,"Customer").forEach(eligibleOffer::add);
List<OfferLookupDTO> offerLookupDTOList = getOfferMetaDto(eligibleOffer); List<OfferLookupDTO> offerLookupDTOList = getOfferMetaDto(eligibleOffer);
if (offerLookupDTOList.isEmpty()) { if (offerLookupDTOList.isEmpty()) {
log.error("Offer lookup Object is empty"); log.error("Offer lookup Object is empty");
......
...@@ -60,7 +60,7 @@ class OfferTransactionControllerTest { ...@@ -60,7 +60,7 @@ class OfferTransactionControllerTest {
@Description("Component test for getOfferTransactionResponse method") @Description("Component test for getOfferTransactionResponse method")
@Test @Test
void getOfferTransactionResponse() throws InterruptedException { void getOfferTransactionResponse() throws InterruptedException {
when(offerLookupRepo.findByHhId(ArgumentMatchers.any())).thenReturn(getOffers()); when(offerLookupRepo.findByHhId(ArgumentMatchers.any(),ArgumentMatchers.any())).thenReturn(getOffers());
when(clientService.getPeResponseFlux(Mockito.any(PERequest.class))).thenReturn(getPeResponse()); when(clientService.getPeResponseFlux(Mockito.any(PERequest.class))).thenReturn(getPeResponse());
when(offerCallingPEService.getOfferMetaDto(ArgumentMatchers.any())).thenReturn(getOfferLookupDto()); when(offerCallingPEService.getOfferMetaDto(ArgumentMatchers.any())).thenReturn(getOfferLookupDto());
Mockito.doReturn(Optional.of(getOfferMeta())).when(offerMetaDataRepo).findByOfferIdAndOfferStatusIgnoreCase(Mockito.anyLong(), Mockito.anyString()); Mockito.doReturn(Optional.of(getOfferMeta())).when(offerMetaDataRepo).findByOfferIdAndOfferStatusIgnoreCase(Mockito.anyLong(), Mockito.anyString());
......
...@@ -49,7 +49,7 @@ public class OfferServiceTest { ...@@ -49,7 +49,7 @@ public class OfferServiceTest {
@Test @Test
public void serviceTest() { public void serviceTest() {
OfferTransactionRequest offerTransactionRequest = getOfferTransactionRequest(); OfferTransactionRequest offerTransactionRequest = getOfferTransactionRequest();
Mockito.when(offerLookupRepo.findByHhId(ArgumentMatchers.any())).thenReturn(returnOffers()); Mockito.when(offerLookupRepo.findByHhId(ArgumentMatchers.any(),ArgumentMatchers.any())).thenReturn(returnOffers());
Mockito.when(clientService.getPeResponseFlux(ArgumentMatchers.any())).thenReturn(getPeResponse()); Mockito.when(clientService.getPeResponseFlux(ArgumentMatchers.any())).thenReturn(getPeResponse());
Mockito.doReturn(getOfferMeta()).when(offerMetaDataRepo).findByOfferIdAndOfferStatusIgnoreCase(ArgumentMatchers.any(),ArgumentMatchers.any()); Mockito.doReturn(getOfferMeta()).when(offerMetaDataRepo).findByOfferIdAndOfferStatusIgnoreCase(ArgumentMatchers.any(),ArgumentMatchers.any());
OfferTransactionResponse offerTransactionResponse = offerCallingPEService.getDiscountedItemList(offerTransactionRequest); OfferTransactionResponse offerTransactionResponse = offerCallingPEService.getDiscountedItemList(offerTransactionRequest);
...@@ -59,7 +59,7 @@ public class OfferServiceTest { ...@@ -59,7 +59,7 @@ public class OfferServiceTest {
@Test(expected = GlobalApiGenericException.class) @Test(expected = GlobalApiGenericException.class)
public void serviceNegTest() { public void serviceNegTest() {
OfferTransactionRequest offerTransactionRequest = getOfferTransactionRequest(); OfferTransactionRequest offerTransactionRequest = getOfferTransactionRequest();
Mockito.when(offerLookupRepo.findByHhId(ArgumentMatchers.any())).thenReturn(returnOffers()); Mockito.when(offerLookupRepo.findByHhId(ArgumentMatchers.any(),ArgumentMatchers.any())).thenReturn(returnOffers());
Mockito.doReturn(Optional.empty()).when(offerMetaDataRepo).findByOfferIdAndOfferStatusIgnoreCase(ArgumentMatchers.any(),ArgumentMatchers.any()); Mockito.doReturn(Optional.empty()).when(offerMetaDataRepo).findByOfferIdAndOfferStatusIgnoreCase(ArgumentMatchers.any(),ArgumentMatchers.any());
offerCallingPEService.getDiscountedItemList(offerTransactionRequest); offerCallingPEService.getDiscountedItemList(offerTransactionRequest);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment