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
4ea20446
Commit
4ea20446
authored
Apr 03, 2020
by
Naren Medarametla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Junit testcase
parent
96a10913
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
10 deletions
+32
-10
OfferTransactionConfig.java
...ffertransactionservice/config/OfferTransactionConfig.java
+3
-0
OfferDao.java
.../java/com/nisum/offertransactionservice/dao/OfferDao.java
+6
-3
OfferDaoTest.java
...a/com/nisum/offertransactionservice/dao/OfferDaoTest.java
+23
-7
No files found.
src/main/java/com/nisum/offertransactionservice/config/OfferTransactionConfig.java
View file @
4ea20446
...
...
@@ -2,9 +2,12 @@ package com.nisum.offertransactionservice.config;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.web.client.*
;
@Configuration
@PropertySource
(
"classpath:application.properties"
)
public
class
OfferTransactionConfig
{
@Bean
...
...
src/main/java/com/nisum/offertransactionservice/dao/OfferDao.java
View file @
4ea20446
...
...
@@ -6,21 +6,24 @@ import com.nisum.offertransactionservice.model.PERequest;
import
com.nisum.offertransactionservice.model.PEResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.stereotype.Component
;
import
org.springframework.http.*
;
import
org.springframework.web.client.*
;
@Component
@PropertySource
(
"classpath:application.properties"
)
public
class
OfferDao
{
@Autowired
private
RestTemplate
restTemplate
;
@
Value
(
"${promotion.engine.calculate.discount.url}"
)
private
String
promotionEngineUrl
;
/*
Value("${promotion.engine.calculate.discount.url}")
private String promotionEngineUrl ;
*/
public
PEResponse
callPE
(
PERequest
peRequest
)
{
ResponseEntity
<
PEResponse
>
peResponse
=
restTemplate
.
postForEntity
(
"http://localhost:8081
"
+
promotionEngineUrl
,
peRequest
,
PEResponse
.
class
);
ResponseEntity
<
PEResponse
>
peResponse
=
restTemplate
.
postForEntity
(
"http://localhost:8081
/promotionEngine/calculateDiscount"
,
peRequest
,
PEResponse
.
class
);
return
peResponse
.
getBody
();
}
}
src/test/java/com/nisum/offertransactionservice/dao/OfferDaoTest.java
View file @
4ea20446
package
com
.
nisum
.
offertransactionservice
.
dao
;
import
com.nisum.offertransactionservice.config.OfferTransactionConfig
;
import
com.nisum.offertransactionservice.model.Item
;
import
com.nisum.offertransactionservice.model.OfferLookup
;
import
com.nisum.offertransactionservice.model.PERequest
;
import
com.nisum.offertransactionservice.model.PEResponse
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.MockitoAnnotations
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.context.ContextConfiguration
;
...
...
@@ -20,24 +28,32 @@ import org.springframework.web.client.RestTemplate;
import
java.util.ArrayList
;
import
java.util.List
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@PropertySource
(
"classpath:application.properties"
)
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
classes
=
{
OfferDao
.
class
})
public
class
OfferDaoTest
{
@Autowired
@Mock
private
RestTemplate
restTemplate
;
@Autowired
private
OfferDao
offerDao
;
@InjectMocks
private
OfferDao
offerDao
=
new
OfferDao
();
@Before
public
void
setUp
()
throws
Exception
{
MockitoAnnotations
.
initMocks
(
this
);
}
/*@Value("${promotion.engine.calculate.discount.url}")
private String promotionEngineUrl ;*/
@Test
public
void
test
(){
PEResponse
peResponse
=
offerDao
.
callPE
(
getPeRequest
());
Mockito
.
when
(
restTemplate
.
postForEntity
(
"http://localhost:8081/promotionEngine/calculateDiscount"
,
getPeRequest
(),
PEResponse
.
class
))
.
thenReturn
(
new
ResponseEntity
<
PEResponse
>(
getPeResponse
(),
HttpStatus
.
OK
));
.
thenReturn
(
new
ResponseEntity
<
PEResponse
>(
getPeResponse
(),
HttpStatus
.
OK
));
PEResponse
peResponse
=
offerDao
.
callPE
(
getPeRequest
());
Assert
.
assertEquals
(
peResponse
,
getPeResponse
());
}
...
...
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