Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
stocks-api-v2
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sharma072072
stocks-api-v2
Commits
bb1c1495
Commit
bb1c1495
authored
May 07, 2022
by
sharma072072
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
controller test case added
parent
c68a9652
Pipeline
#2292
failed with stages
in 13 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
1 deletion
+76
-1
StocksService.java
...in/java/com/altimetrik/ee/demo/service/StocksService.java
+4
-0
StocksControllerTest.java
...va/com/altimetrik/ee/demo/tests/StocksControllerTest.java
+71
-0
StocksRepositoryTest.java
...va/com/altimetrik/ee/demo/tests/StocksRepositoryTest.java
+1
-1
No files found.
src/main/java/com/altimetrik/ee/demo/service/StocksService.java
View file @
bb1c1495
...
...
@@ -19,4 +19,8 @@ public class StocksService {
public
List
<
Stocks
>
getStocks
()
{
return
repository
.
findAll
();
}
public
List
<
Stocks
>
saveStocks
(
Iterable
<
Stocks
>
stocksIterable
)
{
return
repository
.
saveAll
(
stocksIterable
);
}
}
src/test/java/com/altimetrik/ee/demo/tests/StocksControllerTest.java
0 → 100644
View file @
bb1c1495
package
com
.
altimetrik
.
ee
.
demo
.
tests
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
com.altimetrik.ee.demo.bean.Stocks
;
import
com.altimetrik.ee.demo.controller.StocksController
;
import
com.altimetrik.ee.demo.service.StocksService
;
import
java.text.SimpleDateFormat
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
org.springframework.test.web.servlet.request.MockMvcRequestBuilders
;
@RunWith
(
SpringRunner
.
class
)
@WebMvcTest
({
StocksController
.
class
})
public
class
StocksControllerTest
{
@Autowired
private
MockMvc
mockMvc
;
@MockBean
StocksService
stocksService
;
@Test
public
void
getStocksByName
()
throws
Exception
{
String
sDate1
=
"31/12/1998"
;
Date
date1
=
new
SimpleDateFormat
(
"dd/MM/yyyy"
).
parse
(
sDate1
);
List
<
Stocks
>
stocksList
=
Arrays
.
asList
(
new
Stocks
(
"HCL"
,
"HCL Tech"
,
date1
,
420.0
,
"INR"
),
new
Stocks
(
"IBM"
,
"IBM Tech"
,
date1
,
520.0
,
"USD"
),
new
Stocks
(
"UPY"
,
"UPY Tech"
,
date1
,
520.0
,
"JPY"
)
);
when
(
stocksService
.
getStocksByIds
(
any
())).
thenReturn
(
stocksList
);
mockMvc
.
perform
(
MockMvcRequestBuilders
.
get
(
"/stocks/stockQuote?symbols=HCL,IBM"
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
json
(
JSON_STRING
));
}
String
JSON_STRING
=
"[{\"stockQuote\":\"HCL\",\"companyName\":\"HCL Tech\","
+
"\"date\":\"1998-12-30T18:30:00.000+0000\",\"price\":420.0,\"currency\":\"INR\"},"
+
"{\"stockQuote\":\"IBM\",\"companyName\":\"IBM Tech\",\"date\":\"1998-12-30T18:30:00.000+0000\","
+
"\"price\":520.0,\"currency\":\"USD\"},{\"stockQuote\":\"UPY\",\"companyName\":\"UPY Tech\","
+
"\"date\":\"1998-12-30T18:30:00.000+0000\",\"price\":520.0,\"currency\":\"JPY\"}]"
;
@Test
public
void
WhenNoParameterIsPassed
()
throws
Exception
{
when
(
stocksService
.
getStocksByIds
(
any
())).
thenReturn
(
Collections
.
emptyList
());
mockMvc
.
perform
(
MockMvcRequestBuilders
.
get
(
"/stocks/stockQuote?symbols="
))
.
andExpect
(
status
().
isNoContent
());
}
}
src/test/java/com/altimetrik/ee/demo/tests/Stocks
JPA
Test.java
→
src/test/java/com/altimetrik/ee/demo/tests/Stocks
Repository
Test.java
View file @
bb1c1495
...
...
@@ -18,7 +18,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith
(
SpringRunner
.
class
)
@DataJpaTest
public
class
Stocks
JPA
Test
{
public
class
Stocks
Repository
Test
{
@Autowired
private
StocksRepository
stocksRepository
;
...
...
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