Search in sources :

Example 1 with RecipesView

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()));
}
Also used : SearchRecipes(uk.gov.justice.services.example.cakeshop.query.view.request.SearchRecipes) RecipesView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Example 2 with RecipesView

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));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) RecipesView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Example 3 with RecipesView

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));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) RecipesView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Example 4 with RecipesView

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));
}
Also used : RecipesView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView) JsonObject(javax.json.JsonObject) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Example 5 with RecipesView

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));
}
Also used : RecipesView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView) JsonObject(javax.json.JsonObject) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 RecipeView (uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView)6 RecipesView (uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView)6 UUID (java.util.UUID)4 UUID.randomUUID (java.util.UUID.randomUUID)4 JsonObject (javax.json.JsonObject)3 Recipe (uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe)2 SearchRecipes (uk.gov.justice.services.example.cakeshop.query.view.request.SearchRecipes)1