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
74b86128
Commit
74b86128
authored
Apr 17, 2020
by
Siva Naga Someswara Jatla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added integration test
parent
0d2175e9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
18 deletions
+105
-18
build.gradle
build.gradle
+14
-2
AbstractTestBase.java
.../offertransactionservice/controller/AbstractTestBase.java
+27
-0
OfferTransactionControllerIntegrationTest.java
...controller/OfferTransactionControllerIntegrationTest.java
+48
-16
response.json
src/test/resources/response.json
+16
-0
No files found.
build.gradle
View file @
74b86128
...
@@ -54,8 +54,20 @@ dependencies {
...
@@ -54,8 +54,20 @@ dependencies {
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
// 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.3.0'
//compile 'org.hamcrest:hamcrest-all:2.1'
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'
}
}
...
...
src/test/java/com/nisum/offertransactionservice/controller/AbstractTestBase.java
0 → 100644
View file @
74b86128
package
com
.
nisum
.
offertransactionservice
.
controller
;
import
com.github.tomakehurst.wiremock.WireMockServer
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
abstract
class
AbstractTestBase
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
AbstractTestBase
.
class
);
protected
final
static
int
HTTP_ENDPOINT_PORT
=
9090
;
protected
static
WireMockServer
mWireMockServer
=
new
WireMockServer
(
HTTP_ENDPOINT_PORT
);
@BeforeClass
public
static
void
setup
()
{
mWireMockServer
.
start
();
}
@AfterClass
public
static
void
tearDown
()
{
/* Stop the WireMock server. */
mWireMockServer
.
stop
();
}
}
src/test/java/com/nisum/offertransactionservice/controller/OfferTransactionControllerIntegrationTest.java
View file @
74b86128
package
com
.
nisum
.
offertransactionservice
.
controller
;
package
com
.
nisum
.
offertransactionservice
.
controller
;
import
com.github.tomakehurst.wiremock.junit.WireMockRule
;
import
com.nisum.offertransactionservice.dto.Item
;
import
com.nisum.offertransactionservice.dto.Item
;
import
com.nisum.offertransactionservice.dto.OfferTransactionRequest
;
import
com.nisum.offertransactionservice.dto.OfferTransactionRequest
;
import
io.restassured.RestAssured
;
import
com.nisum.offertransactionservice.dto.OfferTransactionResponse
;
import
org.
hamcrest.Matchers
;
import
org.
junit.Before
;
import
org.junit.
jupiter.api.BeforeEach
;
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.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.cloud.contract.wiremock.AutoConfigureWireMock
;
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.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
static
io
.
restassured
.
RestAssured
.
with
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.*
;
@SpringBootTest
public
class
OfferTransactionControllerIntegrationTest
{
@BeforeEach
public
void
setup
()
{
@RunWith
(
SpringRunner
.
class
)
RestAssured
.
baseURI
=
"http://localhost"
;
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
DEFINED_PORT
)
RestAssured
.
port
=
7072
;
@AutoConfigureWireMock
public
class
OfferTransactionControllerIntegrationTest
extends
AbstractTestBase
{
@Rule
public
WireMockRule
wireMockRule
=
new
WireMockRule
(
7072
);
@Autowired
private
TestRestTemplate
testRestTemplate
;
@Before
public
void
setUp
()
{
mockForOfferTransactionCall
();
}
}
private
void
mockForOfferTransactionCall
()
{
mWireMockServer
.
stubFor
(
post
(
urlEqualTo
(
"/offerTransactionCall"
))
.
willReturn
(
aResponse
()
.
withStatus
(
200
)
.
withHeader
(
"Content-Type"
,
"application/json"
)
.
withBodyFile
(
"response.json"
)
));
}
@Test
@Test
public
void
getOfferTransactionResponseTest
()
{
public
void
getOfferTransactionResponseTest
()
{
with
().
body
(
getOfferTransactionRequest
())
URI
uri
=
URI
.
create
(
"http://localhost:7072/offerTransactionCall"
);
.
when
()
RequestEntity
requestEntity
=
new
RequestEntity
(
getOfferTransactionRequest
(),
HttpMethod
.
POST
,
uri
);
.
request
(
"POST"
,
"/offerTransactionCall"
)
.
then
()
ResponseEntity
<
OfferTransactionResponse
>
responseEntity
=
testRestTemplate
.
exchange
(
"http://localhost:7072/offerTransactionCall"
,
HttpMethod
.
POST
,
requestEntity
,
.
statusCode
(
200
)
new
ParameterizedTypeReference
<
OfferTransactionResponse
>(){}
.
body
(
"offerTransactionCall.offerTransactionResponse.transactionId"
,
Matchers
.
notNullValue
());
);
OfferTransactionResponse
offerTransactionResponse
=
responseEntity
.
getBody
();
System
.
out
.
println
(
offerTransactionResponse
);
}
}
private
OfferTransactionRequest
getOfferTransactionRequest
()
{
private
OfferTransactionRequest
getOfferTransactionRequest
()
{
...
...
src/test/resources/response.json
0 → 100644
View file @
74b86128
{
"hhid"
:
"54321"
,
"transactionId"
:
"b89dc898-6e33-4e54-bda8-ada7a80340bf"
,
"discountedItemList"
:
[
{
"itemName"
:
"coke"
,
"itemId"
:
"12"
,
"price"
:
1800.0
},
{
"itemName"
:
"coke"
,
"itemId"
:
"12"
,
"price"
:
900.0
}
]
}
\ No newline at end of file
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