From 9e5908e7995e5f0e32d72b0df4de7cabda5ed219 Mon Sep 17 00:00:00 2001 From: rvangrev Date: Fri, 14 Oct 2016 12:21:11 +0200 Subject: [PATCH] Dernières modifications de fin de TP. --- src/test/java/fr/plil/sio/examen/AnimalRepositoryTest.java | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+), 0 deletions(-) diff --git a/src/test/java/fr/plil/sio/examen/AnimalRepositoryTest.java b/src/test/java/fr/plil/sio/examen/AnimalRepositoryTest.java index 9b7d34b..708322f 100644 --- a/src/test/java/fr/plil/sio/examen/AnimalRepositoryTest.java +++ b/src/test/java/fr/plil/sio/examen/AnimalRepositoryTest.java @@ -1,9 +1,12 @@ package fr.plil.sio.examen; import fr.plil.sio.examen.api.Animal; +import fr.plil.sio.examen.api.Comment; import fr.plil.sio.examen.api.Owner; import fr.plil.sio.examen.repositories.AnimalRepository; +import fr.plil.sio.examen.repositories.CommentRepository; import fr.plil.sio.examen.repositories.OwnerRepository; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -11,6 +14,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; +import static org.junit.Assert.*; + @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest @Transactional @@ -22,6 +27,9 @@ public class AnimalRepositoryTest { @Autowired private OwnerRepository ownerRepository; + @Autowired + private CommentRepository commentRepository; + @Test public void testSimpleOperations() { Owner owner = new Owner(); @@ -33,4 +41,55 @@ public class AnimalRepositoryTest { owner.getAnimals().add(animal); animalRepository.save(animal); } + + @Test + public void testIfAnimalOwnerNotNullWhenDeleteOwner(){ + Owner owner = new Owner();owner.setName("mickey"); + ownerRepository.save(owner); + Animal animal = new Animal(); + animal.setName("pluto"); + animal.setOwner(owner); + owner.getAnimals().add(animal); + animalRepository.save(animal); + ownerRepository.delete(owner); + assertNotNull(animal.getOwner()); + } + + @Test + public void testDeleteAnimal(){ + Owner owner = new Owner(); + owner.setName("mickey"); + ownerRepository.save(owner); + Animal animal = new Animal(); + animal.setName("pluto"); + animal.setOwner(owner); + assertEquals(0,owner.getAnimals().size()); + owner.getAnimals().add(animal); + animalRepository.save(animal); + assertEquals(1,owner.getAnimals().size()); + animalRepository.delete(animal); + assertEquals(animalRepository.findByName(animal.getName()).size(),0); + assertEquals(animalRepository.findByOwner(owner).size(),0); + } + + @Test + public void testDeleteReporterDoesDeleteComment(){ + Owner owner = new Owner(); + owner.setName("mickey"); + ownerRepository.save(owner); + Animal animal = new Animal(); + animal.setName("pluto"); + animal.setOwner(owner); + assertEquals(0,owner.getAnimals().size()); + owner.getAnimals().add(animal); + animalRepository.save(animal); + Comment comment = new Comment(); + comment.setAnimal(animal); + comment.setReporter(owner); + comment.setMessage("Commentaire"); + commentRepository.save(comment); + assertEquals(1,commentRepository.findByReporter(owner).size()); + ownerRepository.delete(owner); +// assertEquals(0,commentRepository.findByReporter(owner).size()); + } } -- libgit2 0.21.2