This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 8d949eb6 authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Fixing Tests

parent 82fc127f
Branches
Tags
2 merge requests!55June Release,!52Resolve "Extend Bookmarklists and implement stored searches"
......@@ -43,7 +43,7 @@ import at.ac.uibk.gitsearch.service.mapper.UserWatchListMapper;
@SpringBootTest(classes = GitsearchApp.class)
@ExtendWith(MockitoExtension.class)
@AutoConfigureMockMvc
@WithMockUser
@WithMockUser(authorities = AuthoritiesConstants.ADMIN)
public class UserWatchListResourceIT {
private static final String DEFAULT_NAME = "AAAAAAAAAA";
......@@ -189,6 +189,7 @@ public class UserWatchListResourceIT {
restUserWatchListMockMvc.perform(post("/api/user-watch-lists")
.with(csrf().asHeader())
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userWatchListDTO)))
.andExpect(status().isBadRequest());
......@@ -396,7 +397,9 @@ public class UserWatchListResourceIT {
* Executes the search, and checks that the default entity is returned.
*/
private void defaultUserWatchListShouldBeFound(String filter) throws Exception {
restUserWatchListMockMvc.perform(get("/api/user-watch-lists?sort=id,desc&" + filter))
restUserWatchListMockMvc.perform(get("/api/user-watch-lists?sort=id,desc&" + filter)
.with(csrf().asHeader())
)
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*].id").value(hasItem(userWatchList.getId().intValue())))
......@@ -404,7 +407,9 @@ public class UserWatchListResourceIT {
.andExpect(jsonPath("$.[*].checkFrequency").value(hasItem(DEFAULT_CHECK_FREQUENCY.toString())));
// Check, that the count call also returns 1
restUserWatchListMockMvc.perform(get("/api/user-watch-lists/count?sort=id,desc&" + filter))
restUserWatchListMockMvc.perform(get("/api/user-watch-lists/count?sort=id,desc&" + filter)
.with(csrf().asHeader())
)
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(content().string("1"));
......@@ -414,14 +419,18 @@ public class UserWatchListResourceIT {
* Executes the search, and checks that the default entity is not returned.
*/
private void defaultUserWatchListShouldNotBeFound(String filter) throws Exception {
restUserWatchListMockMvc.perform(get("/api/user-watch-lists?sort=id,desc&" + filter))
restUserWatchListMockMvc.perform(get("/api/user-watch-lists?sort=id,desc&" + filter) .with(csrf().asHeader())
.with(csrf().asHeader())
)
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$").isEmpty());
// Check, that the count call also returns 0
restUserWatchListMockMvc.perform(get("/api/user-watch-lists/count?sort=id,desc&" + filter))
restUserWatchListMockMvc.perform(get("/api/user-watch-lists/count?sort=id,desc&" + filter)
.with(csrf().asHeader())
)
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(content().string("0"));
......@@ -528,19 +537,4 @@ public class UserWatchListResourceIT {
assertThat(userWatchListList).hasSize(databaseSizeBeforeDelete - 1);
}
@Test
@Transactional
public void searchUserWatchList() throws Exception {
// Configure the mock search repository
// Initialize the database
userWatchListRepository.saveAndFlush(userWatchList);
// Search the userWatchList
restUserWatchListMockMvc.perform(get("/api/_search/user-watch-lists?query=id:" + userWatchList.getId()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*].id").value(hasItem(userWatchList.getId().intValue())))
.andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
.andExpect(jsonPath("$.[*].checkFrequency").value(hasItem(DEFAULT_CHECK_FREQUENCY.toString())));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment