Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OTSWithFeign
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Siva Naga Someswara Jatla
OTSWithFeign
Commits
0b5b7679
Commit
0b5b7679
authored
Apr 17, 2020
by
Naren Medarametla
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://gitlab.mynisum.com/sgandhi/offertransactionservice
parents
285acc44
36e73d6c
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
142 additions
and
67 deletions
+142
-67
build.gradle
build.gradle
+38
-51
readme.md
readme.md
+5
-5
OfferMetaDataRepo.java
.../nisum/offertransactionservice/dao/OfferMetaDataRepo.java
+1
-1
OfferCallingPEService.java
...ffertransactionservice/service/OfferCallingPEService.java
+1
-1
application.properties
src/main/resources/application.properties
+1
-0
OfferTransactionControllerIntegrationTest.java
...controller/OfferTransactionControllerIntegrationTest.java
+85
-7
OfferServiceTest.java
...sum/offertransactionservice/service/OfferServiceTest.java
+2
-2
application-integration.properties
src/test/resources/application-integration.properties
+8
-0
endOfSale-response.json
src/test/resources/endOfSale-response.json
+1
-0
endOfTransaction-response.json
src/test/resources/endOfTransaction-response.json
+0
-0
No files found.
build.gradle
View file @
0b5b7679
...
...
@@ -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'
}
...
...
readme.md
View file @
0b5b7679
...
...
@@ -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"
)
;
```
...
...
src/main/java/com/nisum/offertransactionservice/dao/OfferMetaDataRepo.java
View file @
0b5b7679
...
...
@@ -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
>
findByOfferIdAndOfferStatus
IgnoreCase
(
Long
offerId
,
String
offerStatus
);
}
src/main/java/com/nisum/offertransactionservice/service/OfferCallingPEService.java
View file @
0b5b7679
...
...
@@ -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
());
...
...
src/main/resources/application.properties
View file @
0b5b7679
spring.profiles.active
=
dev
spring.datasource.url
=
jdbc:postgresql://127.0.0.1:5432/storedb
spring.datasource.username
=
postgres
spring.datasource.password
=
welcome123
...
...
src/test/java/com/nisum/offertransactionservice/controller/OfferTransactionControllerIntegrationTest.java
View file @
0b5b7679
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
);
...
...
src/test/java/com/nisum/offertransactionservice/service/OfferServiceTest.java
View file @
0b5b7679
...
...
@@ -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
).
findByOfferIdAndOfferStatus
IgnoreCase
(
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
).
findByOfferIdAndOfferStatus
IgnoreCase
(
ArgumentMatchers
.
any
(),
ArgumentMatchers
.
any
());
offerCallingPEService
.
getDiscountedItemList
(
offerTransactionRequest
);
}
...
...
src/test/resources/application-integration.properties
0 → 100644
View file @
0b5b7679
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
src/test/resources/endOfSale-response.json
0 → 100644
View file @
0b5b7679
"86fd4146-0540-405b-b621-a95f4ccdfa0d"
\ No newline at end of file
src/test/resources/endOfTransaction-response.json
0 → 100644
View file @
0b5b7679
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment