Skip to content
Snippets Groups Projects
Commit 05bf070a authored by Birk Øvstetun Narvhus's avatar Birk Øvstetun Narvhus
Browse files

added RecipeRepo test

parent 14fe44c6
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,6 @@ package ntnu.idatt2016.v233.SmartMat.repository;
import ntnu.idatt2016.v233.SmartMat.entity.Allergy;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
/**
......
package ntnu.idatt2016.v233.SmartMat.repository;
import static org.junit.jupiter.api.Assertions.*;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import ntnu.idatt2016.v233.SmartMat.entity.Recipe;
@DataJpaTest
public class RecipeRepositoryTest {
@Autowired
private RecipeRepository recipeRepository;
@Test
public void testGetByName() {
Recipe recipe = Recipe.builder()
.name("Pizza Margherita")
.description("The classic Italian pizza")
.build();
recipeRepository.save(recipe);
Optional<Recipe> foundRecipe = recipeRepository.getByName("Pizza Margherita");
assertTrue(foundRecipe.isPresent());
assertEquals(recipe.getName(), foundRecipe.get().getName());
}
@Test
public void testDeleteById() {
Recipe recipe = Recipe.builder()
.name("Pizza Margherita")
.description("The classic Italian pizza")
.build();
recipeRepository.save(recipe);
long id = recipe.getId();
recipeRepository.deleteById(id);
assertFalse(recipeRepository.findById(id).isPresent());
}
@Test
public void testSave() {
Recipe recipe = Recipe.builder()
.name("Pizza Margherita")
.description("The classic Italian pizza")
.build();
Recipe savedRecipe = recipeRepository.save(recipe);
assertEquals(recipe.getName(), savedRecipe.getName());
assertEquals(recipe.getDescription(), savedRecipe.getDescription());
}
@Test
public void testFindAll() {
Recipe recipe1 = Recipe.builder()
.name("Pizza Margherita")
.description("The classic Italian pizza")
.build();
Recipe recipe2 = Recipe.builder()
.name("Lasagna Bolognese")
.description("The classic Italian pasta dish")
.build();
recipeRepository.save(recipe1);
recipeRepository.save(recipe2);
List<Recipe> foundRecipes = recipeRepository.findAll();
assertEquals(2, foundRecipes.size());
assertEquals(recipe1.getName(), foundRecipes.get(0).getName());
assertEquals(recipe2.getName(), foundRecipes.get(1).getName());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment