Skip to content

Commit

Permalink
Improve jsonPath assertions of qbe tests
Browse files Browse the repository at this point in the history
To ensure the QueryByExampleFromSpecificationPredicateBuilder is still needed and not replaced by Spring Data's own QueryByExamplePredicateBuilder, the qbe tests should enhance their jsonPath assertions with proper Hamcrest matchers.
  • Loading branch information
drumonii committed Nov 2, 2019
1 parent 5b4b997 commit 9475247
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Expand Up @@ -15,7 +15,7 @@
import org.springframework.test.web.servlet.MockMvc;

import static com.drumonii.loltrollbuild.util.GameMapUtil.HOWLING_ABYSS_ID;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsNull.nullValue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
Expand Down Expand Up @@ -60,28 +60,28 @@ void getChampions() throws Exception {
.param("name", champion.getName().toLowerCase()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*]").isNotEmpty());
.andExpect(jsonPath("$..name", contains(champion.getName())));

// qbe with title
mockMvc.perform(get("{apiPath}/champions", apiPath)
.param("title", champion.getTitle().toLowerCase()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*]").isNotEmpty());
.andExpect(jsonPath("$..title", contains(champion.getTitle())));

// qbe with partype
mockMvc.perform(get("{apiPath}/champions", apiPath)
.param("partype", champion.getPartype().toLowerCase()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*]").isNotEmpty());
.andExpect(jsonPath("$..partype", everyItem(is(champion.getPartype()))));

// qbe with tags
mockMvc.perform(get("/api/champions")
.param("tags", champion.getTags().iterator().next()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*]").isNotEmpty());
.andExpect(jsonPath("$..tags", everyItem(hasItem(champion.getTags().iterator().next()))));

// qbe with no results
mockMvc.perform(get("{apiPath}/champions", apiPath)
Expand Down
Expand Up @@ -15,8 +15,7 @@
import java.util.stream.Collectors;

import static com.drumonii.loltrollbuild.util.GameMapUtil.SUMMONERS_RIFT_SID;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

Expand Down Expand Up @@ -59,21 +58,21 @@ void getItems() throws Exception {
.param("name", item.getName().toLowerCase()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*]").isNotEmpty());
.andExpect(jsonPath("$..name", everyItem(is(item.getName()))));

// qbe with required champion
mockMvc.perform(get("{apiPath}/items", apiPath)
.param("requiredChampion", item.getRequiredChampion().toLowerCase()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*]").isNotEmpty());
.andExpect(jsonPath("$..requiredChampion", everyItem(is(item.getRequiredChampion()))));

// qbe with maps
mockMvc.perform(get("{apiPath}/items", apiPath)
.param("maps[12]", Boolean.TRUE.toString()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*]").isNotEmpty());
.andExpect(jsonPath("$..maps[\"12\"]", everyItem(is(true))));

// qbe with no results
mockMvc.perform(get("{apiPath}/items", apiPath)
Expand Down
Expand Up @@ -16,6 +16,7 @@

import static com.drumonii.loltrollbuild.model.SummonerSpell.GameMode.CLASSIC;
import static java.util.function.Predicate.not;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

Expand Down Expand Up @@ -55,14 +56,14 @@ void getSummonerSpells() throws Exception {
.param("name", summonerSpell.getName().toLowerCase()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*]").isNotEmpty());
.andExpect(jsonPath("$..name", everyItem(is(summonerSpell.getName()))));

// qbe with modes
mockMvc.perform(get("{apiPath}/summoner-spells", apiPath)
.param("modes", summonerSpell.getModes().iterator().next().name()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*]").isNotEmpty());
.andExpect(jsonPath("$..modes", everyItem(hasItem(summonerSpell.getModes().iterator().next().name()))));

// qbe with no results
mockMvc.perform(get("{apiPath}/summoner-spells", apiPath)
Expand Down

0 comments on commit 9475247

Please sign in to comment.