Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GrowBros
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tomato
GrowBros
Commits
50da15df
Commit
50da15df
authored
1 year ago
by
Blersch Lara
Browse files
Options
Downloads
Patches
Plain Diff
implemented unit test for wishlistController
parent
aff50458
No related branches found
No related tags found
1 merge request
!51
Wishlist unittests
Pipeline
#57448
passed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/hdm/mi/growbros/controllers/WishListControllerTest.java
+69
-0
69 additions, 0 deletions
...a/hdm/mi/growbros/controllers/WishListControllerTest.java
with
69 additions
and
0 deletions
src/test/java/hdm/mi/growbros/controllers/WishListControllerTest.java
0 → 100644
+
69
−
0
View file @
50da15df
package
hdm.mi.growbros.controllers
;
import
hdm.mi.growbros.config.SpringSecurityTestConfig
;
import
hdm.mi.growbros.models.plant.Plant
;
import
hdm.mi.growbros.service.WishListService
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.test.context.support.WithMockUser
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.web.servlet.MockMvc
;
import
java.util.List
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultHandlers
.
print
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.*;
@SpringBootTest
(
classes
=
SpringSecurityTestConfig
.
class
)
@AutoConfigureMockMvc
@ActiveProfiles
(
"test"
)
public
class
WishListControllerTest
{
@Autowired
private
MockMvc
mvc
;
@MockBean
private
WishListService
wishlistService
;
@Test
@WithMockUser
void
wishlistEntries_shouldBeOkJson_containList
()
throws
Exception
{
when
(
wishlistService
.
getWishedPlants
(
any
(),
any
())).
thenReturn
(
List
.
of
(
Plant
.
builder
().
name
(
"Plant"
).
build
()));
mvc
.
perform
(
get
(
"/api/v1/wishlist"
).
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
jsonPath
(
"$.size()"
).
value
(
1
))
.
andDo
(
print
());
verify
(
wishlistService
).
getWishedPlants
(
any
(),
any
());
}
@Test
@WithMockUser
void
creatingEntry_shouldBe201_andContainPlant
()
throws
Exception
{
mvc
.
perform
(
post
(
"/api/v1/wishlist/add/0"
).
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
status
().
isCreated
())
.
andDo
(
print
());
verify
(
wishlistService
).
addPlantToWishList
(
anyLong
(),
any
());
}
@Test
@WithMockUser
void
deletingEntry_shouldBe204
()
throws
Exception
{
mvc
.
perform
(
delete
(
"/api/v1/wishlist/remove/1"
).
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
status
().
isNoContent
())
.
andDo
(
print
());
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment