Added integration tests and corrected the service layer ( ACTIVE field)

parent a6d55bdd
...@@ -19,7 +19,7 @@ configurations { ...@@ -19,7 +19,7 @@ configurations {
repositories { repositories {
flatDir { 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() mavenCentral()
} }
...@@ -29,7 +29,6 @@ dependencies { ...@@ -29,7 +29,6 @@ dependencies {
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final' annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux' 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' compile group: 'com.google.guava', name: 'guava', version: '28.2-jre'
compileOnly 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
...@@ -37,38 +36,26 @@ dependencies { ...@@ -37,38 +36,26 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') testImplementation('org.springframework.boot:spring-boot-starter-test')
compile 'com.nisum:exceptionservice:0.0.1' 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' 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 'com.vladmihalcea:hibernate-types-52:2.0.0'
compile 'org.mapstruct:mapstruct:1.3.0.Beta2' compile 'org.mapstruct:mapstruct:1.3.0.Beta2'
testCompile 'com.squareup.okhttp3:mockwebserver:3.8.0' 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('org.springframework.boot:spring-boot-starter-test')
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.3.RELEASE' 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' compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
testImplementation 'io.projectreactor:reactor-test' testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
compile 'com.h2database:h2:1.3.156' 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 "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' testCompile group: 'org.springframework.cloud', name: 'spring-cloud-starter-contract-stub-runner', version: '2.2.2.RELEASE'
} }
......
...@@ -8,6 +8,6 @@ import java.util.Optional; ...@@ -8,6 +8,6 @@ import java.util.Optional;
public interface OfferMetaDataRepo extends JpaRepository<OfferMeta,Long> { 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 { ...@@ -60,7 +60,7 @@ public class OfferCallingPEService {
return eligibleOffer.stream(). return eligibleOffer.stream().
map(offer -> { map(offer -> {
Optional<OfferMeta> optionalOfferMeta = offerMetaDataRepo. Optional<OfferMeta> optionalOfferMeta = offerMetaDataRepo.
findByOfferIdAndOfferStatus(offer.getOfferId(), "ACTIVE"); findByOfferIdAndOfferStatusIgnoreCase(offer.getOfferId(), "ACTIVE");
if(optionalOfferMeta.isPresent()){ if(optionalOfferMeta.isPresent()){
OfferMetaDTO offerMetaDTO = OfferConvertion.INSTANCE.map(optionalOfferMeta.get()); OfferMetaDTO offerMetaDTO = OfferConvertion.INSTANCE.map(optionalOfferMeta.get());
......
package com.nisum.offertransactionservice.controller; package com.nisum.offertransactionservice.controller;
import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.nisum.offertransactionservice.dto.Item; import com.nisum.offertransactionservice.dto.*;
import com.nisum.offertransactionservice.dto.OfferTransactionRequest; import com.nisum.offertransactionservice.model.OfferLookup;
import com.nisum.offertransactionservice.dto.OfferTransactionResponse; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
...@@ -16,17 +15,15 @@ import org.springframework.core.ParameterizedTypeReference; ...@@ -16,17 +15,15 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.RequestEntity; import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.client.WireMock.*;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.DEFINED_PORT) @SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.DEFINED_PORT)
@AutoConfigureWireMock @AutoConfigureWireMock
public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{ public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{
...@@ -41,6 +38,8 @@ public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{ ...@@ -41,6 +38,8 @@ public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{
@Before @Before
public void setUp() { public void setUp() {
mockForOfferTransactionCall(); mockForOfferTransactionCall();
mockForEndOfSale();
mockForEndOfTransaction();
} }
private void mockForOfferTransactionCall() { private void mockForOfferTransactionCall() {
...@@ -52,6 +51,24 @@ public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{ ...@@ -52,6 +51,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 @Test
public void getOfferTransactionResponseTest() { public void getOfferTransactionResponseTest() {
URI uri = URI.create("http://localhost:7072/offerTransactionCall"); URI uri = URI.create("http://localhost:7072/offerTransactionCall");
...@@ -65,6 +82,65 @@ public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{ ...@@ -65,6 +82,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() { private OfferTransactionRequest getOfferTransactionRequest() {
OfferTransactionRequest offerTransactionRequest = new OfferTransactionRequest(); OfferTransactionRequest offerTransactionRequest = new OfferTransactionRequest();
offerTransactionRequest.setHhId(54321L); offerTransactionRequest.setHhId(54321L);
......
...@@ -51,7 +51,7 @@ public class OfferServiceTest { ...@@ -51,7 +51,7 @@ public class OfferServiceTest {
OfferTransactionRequest offerTransactionRequest = getOfferTransactionRequest(); OfferTransactionRequest offerTransactionRequest = getOfferTransactionRequest();
Mockito.when(offerLookupRepo.findByHhId(ArgumentMatchers.any())).thenReturn(returnOffers()); Mockito.when(offerLookupRepo.findByHhId(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).findByOfferIdAndOfferStatus(ArgumentMatchers.any(),ArgumentMatchers.any()); Mockito.doReturn(getOfferMeta()).when(offerMetaDataRepo).findByOfferIdAndOfferStatusIgnoreCase(ArgumentMatchers.any(),ArgumentMatchers.any());
OfferTransactionResponse offerTransactionResponse = offerCallingPEService.getDiscountedItemList(offerTransactionRequest); OfferTransactionResponse offerTransactionResponse = offerCallingPEService.getDiscountedItemList(offerTransactionRequest);
Assert.assertNotNull(offerTransactionResponse); Assert.assertNotNull(offerTransactionResponse);
} }
...@@ -60,7 +60,7 @@ public class OfferServiceTest { ...@@ -60,7 +60,7 @@ public class OfferServiceTest {
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())).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); offerCallingPEService.getDiscountedItemList(offerTransactionRequest);
} }
......
"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