use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView in project microservice_framework by CJSCommonPlatform.
the class RecipesQueryViewTest method shouldReturnRecipesForQuery.
@Test
public void shouldReturnRecipesForQuery() throws Exception {
final UUID recipeId = randomUUID();
final UUID recipeId2 = randomUUID();
final String recipeName = "some recipe name";
final String recipeName2 = "some other recipe name";
final int pagesize = 5;
when(service.getRecipes(pagesize, Optional.of(recipeName), Optional.of(false))).thenReturn(new RecipesView(asList(new RecipeView(recipeId, recipeName, false), new RecipeView(recipeId2, recipeName2, false))));
final SearchRecipes searchRecipes = new SearchRecipes(pagesize);
searchRecipes.setName(recipeName);
searchRecipes.setGlutenFree(false);
final Envelope<SearchRecipes> envelope = envelopeFrom(metadataWithDefaults(), searchRecipes);
final Envelope<RecipesView> response = queryView.queryRecipes(envelope);
final RecipesView payload = response.payload();
assertThat(payload.getRecipes().get(0).getName(), is(searchRecipes.getName()));
}
use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView in project microservice_framework by CJSCommonPlatform.
the class RecipeServiceTest method shouldGetRecipes2.
@Test
public void shouldGetRecipes2() {
int pageSize = 10;
Optional<String> nameQueryParam = Optional.of("other name");
Optional<Boolean> glutenFreeQueryParam = Optional.empty();
given(recipeRepository.findBy(pageSize, nameQueryParam, glutenFreeQueryParam)).willReturn(singletonList(new Recipe(RECIPE_ID, NAME, GLUTEN_FREE, PHOTO_ID)));
RecipesView recipes = service.getRecipes(pageSize, nameQueryParam, glutenFreeQueryParam);
List<RecipeView> firstRecipe = recipes.getRecipes();
assertThat(firstRecipe, hasSize(1));
assertThat(firstRecipe.get(0).getId(), equalTo(RECIPE_ID));
assertThat(firstRecipe.get(0).getName(), equalTo(NAME));
assertThat(firstRecipe.get(0).isGlutenFree(), is(GLUTEN_FREE));
}
use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView in project microservice_framework by CJSCommonPlatform.
the class RecipeServiceTest method shouldGetRecipes.
@Test
public void shouldGetRecipes() {
int pageSize = 20;
Optional<String> nameQueryParam = Optional.of("name123");
Optional<Boolean> glutenFreeQueryParam = Optional.of(false);
given(recipeRepository.findBy(pageSize, nameQueryParam, glutenFreeQueryParam)).willReturn(singletonList(new Recipe(RECIPE_ID, NAME, GLUTEN_FREE, PHOTO_ID)));
RecipesView recipes = service.getRecipes(pageSize, nameQueryParam, glutenFreeQueryParam);
List<RecipeView> firstRecipe = recipes.getRecipes();
assertThat(firstRecipe, hasSize(1));
assertThat(firstRecipe.get(0).getId(), equalTo(RECIPE_ID));
assertThat(firstRecipe.get(0).getName(), equalTo(NAME));
assertThat(firstRecipe.get(0).isGlutenFree(), is(GLUTEN_FREE));
}
use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView in project microservice_framework by CJSCommonPlatform.
the class RecipesQueryViewTest method shouldQueryForRecipesOfGivenName.
@Test
public void shouldQueryForRecipesOfGivenName() throws Exception {
final UUID recipeId = randomUUID();
final String recipeName = "some recipe name";
final String nameUsedInQuery = "some recipe";
final int pagesize = 5;
when(service.getRecipes(pagesize, Optional.of(nameUsedInQuery), Optional.empty())).thenReturn(new RecipesView(singletonList(new RecipeView(recipeId, recipeName, false))));
final Envelope<JsonObject> envelope = envelopeFrom(metadataWithDefaults(), createObjectBuilder().add("pagesize", pagesize).add("name", nameUsedInQuery).build());
final Envelope<RecipesView> response = queryView.listRecipes(envelope);
assertThat(response.payload().getRecipes().get(0).getId(), is(recipeId));
assertThat(response.payload().getRecipes().get(0).getName(), is(recipeName));
}
use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView in project microservice_framework by CJSCommonPlatform.
the class RecipesQueryViewTest method shouldReturnRecipes.
@Test
public void shouldReturnRecipes() throws Exception {
final UUID recipeId = randomUUID();
final UUID recipeId2 = randomUUID();
final String recipeName = "some recipe name";
final String recipeName2 = "some other recipe name";
final int pagesize = 5;
when(service.getRecipes(pagesize, Optional.empty(), Optional.empty())).thenReturn(new RecipesView(asList(new RecipeView(recipeId, recipeName, false), new RecipeView(recipeId2, recipeName2, false))));
final Envelope<JsonObject> envelope = envelopeFrom(metadataWithDefaults(), createObjectBuilder().add("pagesize", pagesize).build());
final Envelope<RecipesView> response = queryView.listRecipes(envelope);
assertThat(response.payload().getRecipes().size(), is(2));
assertThat(response.payload().getRecipes().get(0).getId(), is(recipeId));
assertThat(response.payload().getRecipes().get(0).getName(), is(recipeName));
assertThat(response.payload().getRecipes().get(1).getId(), is(recipeId2));
assertThat(response.payload().getRecipes().get(1).getName(), is(recipeName2));
}
Aggregations