Commit 0b5b7679 authored by Naren Medarametla's avatar Naren Medarametla
parents 285acc44 36e73d6c
......@@ -19,7 +19,7 @@ configurations {
repositories {
flatDir {
dirs 'C:\\Users\\kpadhi\\.m2\\repository\\com\\nisum\\exceptionservice\\0.0.1'
dirs '/Users/sivanagasomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
}
mavenCentral()
}
......@@ -29,7 +29,6 @@ dependencies {
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
//compile group: 'org.springframework', name: 'spring-context', version: '5.2.5.RELEASE'
compile group: 'com.google.guava', name: 'guava', version: '28.2-jre'
compileOnly 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
......@@ -37,38 +36,26 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test')
compile 'com.nisum:exceptionservice:0.0.1'
// https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.0'
// https://mvnrepository.com/artifact/com.vladmihalcea/hibernate-types-parent
compile 'com.vladmihalcea:hibernate-types-52:2.0.0'
compile 'org.mapstruct:mapstruct:1.3.0.Beta2'
testCompile 'com.squareup.okhttp3:mockwebserver:3.8.0'
//implementation group: 'junit', name: 'junit', version: '4.12'
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.3.RELEASE'
//testImplementation group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
compile 'com.h2database:h2:1.3.156'
// https://mvnrepository.com/artifact/io.rest-assured/rest-assured
//testCompile group: 'io.rest-assured', name: 'rest-assured', version: '4.3.0'
testCompile group: 'io.rest-assured', name: 'rest-assured', version: '4.0.0'
testCompile group: 'io.rest-assured', name: 'rest-assured-common', version: '4.0.0'
testCompile group: 'io.rest-assured', name: 'json-path', version: '4.0.0'
testCompile group: 'io.rest-assured', name: 'xml-path', version: '4.0.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
// https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock
testCompile "com.github.tomakehurst:wiremock-jre8:2.26.3"
//testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"
testCompile group: 'org.springframework.cloud', name: 'spring-cloud-starter-contract-stub-runner', version: '2.2.2.RELEASE'
}
......
......@@ -40,7 +40,7 @@ In Header click on Tool -> Query Tool --> and paste the below query
CREATE TABLE offer_lookup
(
id INTEGER,
id VARCHAR(500),
store_id VARCHAR(200),
terminal VARCHAR(200),
offer_type VARCHAR(200),
......@@ -61,16 +61,16 @@ Once you create use the below query to insert a data
INSERT INTO public.offer_lookup(
store_id, terminal, offer_type, offer_id, pre_condition, id)
VALUES ('0001','001','Customer',1,'AND',54321);
VALUES ('0001','001','Customer',1,'AND',"54321");
INSERT INTO public.offer_lookup(
store_id, terminal, offer_type, offer_id, pre_condition,id)
VALUES ('0001','001','Customer',2,'AND',54321);
VALUES ('0001','001','Customer',2,'AND',"54321");
INSERT INTO public.offer_lookup(
store_id, terminal, offer_type, offer_id, pre_condition,id)
VALUES ('0001','001','Customer',3,'AND',54321);
VALUES ('0001','001','Customer',3,'AND',"54321");
INSERT INTO public.offer_lookup(
store_id, terminal, offer_type, offer_id, pre_condition,id)
VALUES ('0001','001','Customer',4,'AND',54321);
VALUES ('0001','001','Customer',4,'AND',"54321");
```
......
......@@ -8,6 +8,6 @@ import java.util.Optional;
public interface OfferMetaDataRepo extends JpaRepository<OfferMeta,Long> {
public Optional<OfferMeta> findByOfferIdAndOfferStatus(Long offerId,String offerStatus);
public Optional<OfferMeta> findByOfferIdAndOfferStatusIgnoreCase(Long offerId,String offerStatus);
}
......@@ -60,7 +60,7 @@ public class OfferCallingPEService {
return eligibleOffer.stream().
map(offer -> {
Optional<OfferMeta> optionalOfferMeta = offerMetaDataRepo.
findByOfferIdAndOfferStatus(offer.getOfferId(), "ACTIVE");
findByOfferIdAndOfferStatusIgnoreCase(offer.getOfferId(), "ACTIVE");
if(optionalOfferMeta.isPresent()){
OfferMetaDTO offerMetaDTO = OfferConvertion.INSTANCE.map(optionalOfferMeta.get());
......
spring.profiles.active=dev
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/storedb
spring.datasource.username=postgres
spring.datasource.password=welcome123
......
package com.nisum.offertransactionservice.controller;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.nisum.offertransactionservice.dto.Item;
import com.nisum.offertransactionservice.dto.OfferTransactionRequest;
import com.nisum.offertransactionservice.dto.OfferTransactionResponse;
import com.nisum.offertransactionservice.dto.*;
import com.nisum.offertransactionservice.model.OfferLookup;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
......@@ -16,19 +15,19 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.ActiveProfiles;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.DEFINED_PORT)
@AutoConfigureWireMock
@ActiveProfiles(value = "integration")
public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{
@Rule
......@@ -41,6 +40,8 @@ public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{
@Before
public void setUp() {
mockForOfferTransactionCall();
mockForEndOfSale();
mockForEndOfTransaction();
}
private void mockForOfferTransactionCall() {
......@@ -52,6 +53,24 @@ public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{
));
}
private void mockForEndOfSale() {
mWireMockServer.stubFor(post(urlEqualTo("/endOfSale"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("endOfSale-response.json")
));
}
private void mockForEndOfTransaction() {
mWireMockServer.stubFor(post(urlEqualTo("/endOfTransaction"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("endOfTransaction-response.json")
));
}
@Test
public void getOfferTransactionResponseTest() {
URI uri = URI.create("http://localhost:7072/offerTransactionCall");
......@@ -65,6 +84,65 @@ public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{
}
@Test
public void endOfSaleTest() {
URI uri = URI.create("http://localhost:7072/endOfSale");
RequestEntity requestEntity = new RequestEntity(getEndOfSaleReq(),HttpMethod.POST,uri);
ResponseEntity<EndOfSaleResponse> responseEntity = testRestTemplate.exchange("http://localhost:7072/endOfSale", HttpMethod.POST,requestEntity,
new ParameterizedTypeReference<EndOfSaleResponse>(){}
);
EndOfSaleResponse endOfSaleResponse = responseEntity.getBody();
Assert.assertNotNull(endOfSaleResponse.getUuId());
}
@Test
public void endOfTransactionTest() {
URI uri = URI.create("http://localhost:7072/endOfTransaction");
String uuid = "86fd4146-0540-405b-b621-a95f4ccdfa0d";
RequestEntity requestEntity = new RequestEntity(uuid,HttpMethod.POST,uri);
ResponseEntity<String> responseEntity = testRestTemplate.exchange("http://localhost:7072/endOfTransaction", HttpMethod.POST,requestEntity,
new ParameterizedTypeReference<String>(){}
);
String endOfTransactionRes = responseEntity.getBody();
Assert.assertNotNull(endOfTransactionRes);
}
private EndOfSaleReq getEndOfSaleReq() {
EndOfSaleReq endOfSaleReq = new EndOfSaleReq();
endOfSaleReq.setOfferTransactionResponse(retOfferTransRes());
endOfSaleReq.setOffers(returnOffers());
return endOfSaleReq;
}
private OfferTransactionResponse retOfferTransRes() {
OfferTransactionResponse offerTransactionResponse = new OfferTransactionResponse();
offerTransactionResponse.setHhid("123");
List<Item> itemList = new ArrayList<>();
Item item1 = new Item("Coke", "12", 6.05);
Item item2 = new Item("Thumpsup", "11", 12.32);
itemList.add(item1);
itemList.add(item2);
offerTransactionResponse.setDiscountedItemList(itemList);
offerTransactionResponse.setTransactionId("123456788899999998");
return offerTransactionResponse;
}
public List<OfferLookup> returnOffers() {
OfferLookup offerLookup1 = new OfferLookup(1L, "12", 23L, "02", "AND", "BOGO");
OfferLookup offerLookup2 = new OfferLookup(2L, "13", 24L, "02", "OR", "BXGY");
List<OfferLookup> offerLookups = new ArrayList<>();
offerLookups.add(offerLookup1);
offerLookups.add(offerLookup2);
return offerLookups.stream().collect(Collectors.toList());
}
private OfferTransactionRequest getOfferTransactionRequest() {
OfferTransactionRequest offerTransactionRequest = new OfferTransactionRequest();
offerTransactionRequest.setHhId(54321L);
......
......@@ -51,7 +51,7 @@ public class OfferServiceTest {
OfferTransactionRequest offerTransactionRequest = getOfferTransactionRequest();
Mockito.when(offerLookupRepo.findByHhId(ArgumentMatchers.any())).thenReturn(returnOffers());
Mockito.when(clientService.getPeResponseFlux(ArgumentMatchers.any())).thenReturn(getPeResponse());
Mockito.doReturn(getOfferMeta()).when(offerMetaDataRepo).findByOfferIdAndOfferStatus(ArgumentMatchers.any(),ArgumentMatchers.any());
Mockito.doReturn(getOfferMeta()).when(offerMetaDataRepo).findByOfferIdAndOfferStatusIgnoreCase(ArgumentMatchers.any(),ArgumentMatchers.any());
OfferTransactionResponse offerTransactionResponse = offerCallingPEService.getDiscountedItemList(offerTransactionRequest);
Assert.assertNotNull(offerTransactionResponse);
}
......@@ -60,7 +60,7 @@ public class OfferServiceTest {
public void serviceNegTest() {
OfferTransactionRequest offerTransactionRequest = getOfferTransactionRequest();
Mockito.when(offerLookupRepo.findByHhId(ArgumentMatchers.any())).thenReturn(returnOffers());
Mockito.doReturn(Optional.empty()).when(offerMetaDataRepo).findByOfferIdAndOfferStatus(ArgumentMatchers.any(),ArgumentMatchers.any());
Mockito.doReturn(Optional.empty()).when(offerMetaDataRepo).findByOfferIdAndOfferStatusIgnoreCase(ArgumentMatchers.any(),ArgumentMatchers.any());
offerCallingPEService.getDiscountedItemList(offerTransactionRequest);
}
......
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/postgres
spring.datasource.username=user
spring.datasource.password=password123
endpoint.url.promotionEngineUrl=/promotionEngine/calculateDiscount
endpoint.url.peBaseUrl=http://localhost:7073
endpoint.url.storeProducerUrl=/store/producer
endpoint.url.spBaseUrl=http://localhost:7070
server.port = 7072
\ No newline at end of file
"86fd4146-0540-405b-b621-a95f4ccdfa0d"
\ No newline at end of file
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