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
7739e942
Commit
7739e942
authored
Apr 17, 2020
by
Siva Naga Someswara Jatla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added integration tests and corrected the service layer ( ACTIVE field)
parent
a6d55bdd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
126 additions
and
62 deletions
+126
-62
build.gradle
build.gradle
+38
-51
OfferMetaDataRepo.java
.../nisum/offertransactionservice/dao/OfferMetaDataRepo.java
+1
-1
OfferCallingPEService.java
...ffertransactionservice/service/OfferCallingPEService.java
+1
-1
OfferTransactionControllerIntegrationTest.java
...controller/OfferTransactionControllerIntegrationTest.java
+83
-7
OfferServiceTest.java
...sum/offertransactionservice/service/OfferServiceTest.java
+2
-2
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 @
7739e942
plugins
{
id
'org.springframework.boot'
version
'2.2.5.RELEASE'
id
'io.spring.dependency-management'
version
'1.0.9.RELEASE'
id
'java'
id
'net.ltgt.apt'
version
'0.20'
id
'org.springframework.boot'
version
'2.2.5.RELEASE'
id
'io.spring.dependency-management'
version
'1.0.9.RELEASE'
id
'java'
id
'net.ltgt.apt'
version
'0.20'
}
apply
plugin:
'net.ltgt.apt-idea'
...
...
@@ -12,66 +12,53 @@ version = '0.0.1-SNAPSHOT'
sourceCompatibility
=
'1.8'
configurations
{
compileOnly
{
extendsFrom
annotationProcessor
}
compileOnly
{
extendsFrom
annotationProcessor
}
}
repositories
{
flatDir
{
dirs
'C:\\Users\\kpadhi\\.m2\\repository\\com\\nisum\\exceptionservice\\
0.0.1'
}
mavenCentral
()
flatDir
{
dirs
'/Users/sivanagasomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/
0.0.1'
}
mavenCentral
()
}
dependencies
{
compile
'org.mapstruct:mapstruct: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-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'
implementation
'org.postgresql:postgresql'
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'
compile
'org.mapstruct:mapstruct: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-webflux'
compile
group:
'com.google.guava'
,
name:
'guava'
,
version:
'28.2-jre'
compileOnly
'org.projectlombok:lombok'
implementation
'org.springframework.boot:spring-boot-starter-data-jpa'
implementation
'org.postgresql:postgresql'
annotationProcessor
'org.projectlombok:lombok'
testImplementation
(
'org.springframework.boot:spring-boot-starter-test'
)
compile
'com.nisum:exceptionservice:0.0.1'
compile
group:
'org.codehaus.jackson'
,
name:
'jackson-mapper-asl'
,
version:
'1.9.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'
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'
testImplementation
(
'org.springframework.boot:spring-boot-starter-test'
)
testImplementation
group:
'org.springframework.boot'
,
name:
'spring-boot-starter-test'
,
version:
'2.0.3.RELEASE'
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'
testCompile
"com.github.tomakehurst:wiremock-jre8:2.26.3"
testCompile
group:
'org.springframework.cloud'
,
name:
'spring-cloud-starter-contract-stub-runner'
,
version:
'2.2.2.RELEASE'
}
test
{
useJUnitPlatform
()
useJUnitPlatform
()
}
src/main/java/com/nisum/offertransactionservice/dao/OfferMetaDataRepo.java
View file @
7739e942
...
...
@@ -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 @
7739e942
...
...
@@ -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/test/java/com/nisum/offertransactionservice/controller/OfferTransactionControllerIntegrationTest.java
View file @
7739e942
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,17 +15,15 @@ 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
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
public
class
OfferTransactionControllerIntegrationTest
extends
AbstractTestBase
{
...
...
@@ -41,6 +38,8 @@ public class OfferTransactionControllerIntegrationTest extends AbstractTestBase{
@Before
public
void
setUp
()
{
mockForOfferTransactionCall
();
mockForEndOfSale
();
mockForEndOfTransaction
();
}
private
void
mockForOfferTransactionCall
()
{
...
...
@@ -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
public
void
getOfferTransactionResponseTest
()
{
URI
uri
=
URI
.
create
(
"http://localhost:7072/offerTransactionCall"
);
...
...
@@ -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
()
{
OfferTransactionRequest
offerTransactionRequest
=
new
OfferTransactionRequest
();
offerTransactionRequest
.
setHhId
(
54321L
);
...
...
src/test/java/com/nisum/offertransactionservice/service/OfferServiceTest.java
View file @
7739e942
...
...
@@ -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/endOfSale-response.json
0 → 100644
View file @
7739e942
"86fd4146-0540-405b-b621-a95f4ccdfa0d"
\ No newline at end of file
src/test/resources/endOfTransaction-response.json
0 → 100644
View file @
7739e942
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