Package fr.valtech.many2many.domain

Examples of fr.valtech.many2many.domain.Recipe


        _400gJambon = new RecipeIngredient();
        _400gJambon.setAmount("400g grammes");
        _400gJambon.setIngredient(jambon);

        recipe = new Recipe();
        recipe.setTitle("title");
        recipe.addRecipeIngredient(_400gJambon);

    }
View Full Code Here


        Assert.assertNull(recipe.getId());
        recipeDAO.save(recipe);
        Assert.assertTrue(recipe.getId() > 0);
        flushSession();

        Recipe searchedRecipe = recipeDAO.getEntity(Recipe.class,
                recipe.getId());
        assertEquals(recipe.getId(), searchedRecipe.getId());
        assertEquals(jambon.getLabel(), searchedRecipe.getRecipeIngredients()
                .iterator().next().getIngredient().getLabel());
    }
View Full Code Here

        Assert.assertNull(recipe.getId());
        recipeDAO.save(recipe);
        flushSession();

        // recette2
        Recipe recipe2 = new Recipe();
        recipe2.setTitle("title2");
        Iterator<RecipeIngredient> it = recipe.getRecipeIngredients()
                .iterator();

        // les ingredients détachés
        Ingredient i1 = new Ingredient();
        i1.setId(it.next().getIngredient().getId());
        RecipeIngredient ri1 = new RecipeIngredient(i1, "200g");
        recipe2.addRecipeIngredient(ri1);

        Ingredient i2 = new Ingredient();
        i2.setId(it.next().getIngredient().getId());
        RecipeIngredient ri2 = new RecipeIngredient(i2, "300g");
        recipe2.addRecipeIngredient(ri2);

        assertFalse(i1.getId().equals(i2.getId()));
        assertFalse(i1.equals(i2));

        recipeDAO.save(recipe2);
        assertEquals(2, recipe2.getRecipeIngredients().size());
        flushSession();

        // asserts
        Recipe searchedRecipe2 = recipeDAO.getEntity(Recipe.class,
                recipe2.getId());
        Iterator<RecipeIngredient> itRecipe1 = recipe.getRecipeIngredients()
                .iterator();
        i1 = itRecipe1.next().getIngredient();
        i2 = itRecipe1.next().getIngredient();

        it = searchedRecipe2.getRecipeIngredients().iterator();
        boolean foundi1 = false;
        boolean foundi2 = false;
        while (it.hasNext()) {
            RecipeIngredient ri = it.next();
            if (ri.getIngredient().equals(i1)) {
View Full Code Here

    }

    @Test
    public void testLoadNonExistingRecipe() throws Exception {

        Recipe searchedRecipe = recipeDAO.getEntity(Recipe.class, -1);
        assertNull(searchedRecipe);
    }
View Full Code Here

        recipeDAO.save(recipe);
        Assert.assertTrue(recipe.getId() > 0);
        Assert.assertEquals(1, recipe.getRecipeIngredients().size());
        flushSession();

        Recipe searchedRecipe;
        // clean la session pour detacher les objets
        entityManager.clear();
        Ingredient pates = new Ingredient();
        pates.setLabel("pates");

        RecipeIngredient _100gPates = new RecipeIngredient(pates, "200g");

        searchedRecipe = detachRecipe(recipe);
        searchedRecipe.addRecipeIngredient(_100gPates);
        recipeDAO.merge(searchedRecipe);
        flushSession();

        recipe = recipeDAO.getEntity(Recipe.class, searchedRecipe.getId());
        Assert.assertEquals(2, recipe.getRecipeIngredients().size());
    }
View Full Code Here

        Assert.assertTrue(recipe.getId() > 0);
        flushSession();

        // clean de la session pour detacher les objets
        entityManager.clear();
        Recipe searchedRecipe = detachRecipe(recipe);
        // ajoute un nouvel ingredient (sans id)
        Ingredient pates = new Ingredient();
        pates.setLabel("pates");
        RecipeIngredient _100gPates = new RecipeIngredient(pates, "100g");

        searchedRecipe.addRecipeIngredient(_100gPates);
        recipeDAO.merge(searchedRecipe);
        flushSession();

        recipe = recipeDAO.getEntity(Recipe.class, searchedRecipe.getId());
        Assert.assertEquals(2, recipe.getRecipeIngredients().size());
    }
View Full Code Here

        // clean de la session et de la recette
        entityManager.clear();
        Ingredient saladeDetached = new Ingredient();
        saladeDetached.setId(salade.getId());

        Recipe searchedRecipe = detachRecipe(recipe);
        // ajoute un nouvel ingredient (avec id)
        RecipeIngredient _1feuilleSalade = new RecipeIngredient(saladeDetached,
                "1 feuille");
        searchedRecipe.addRecipeIngredient(_1feuilleSalade);

        recipeDAO.merge(searchedRecipe);
        flushSession();

        recipe = recipeDAO.getEntity(Recipe.class, searchedRecipe.getId());
        Assert.assertEquals(2, recipe.getRecipeIngredients().size());
    }
View Full Code Here

        // clean de la session et de la recette
        entityManager.clear();
        Ingredient saladeDetached = new Ingredient();
        saladeDetached.setId(salade.getId());

        Recipe searchedRecipe = detachRecipe(recipe);
        // ajoute un nouvel ingredient (avec id)
        RecipeIngredient ri = searchedRecipe.getRecipeIngredients().iterator()
                .next();
        ri.setIngredient(saladeDetached);

        recipeDAO.merge(searchedRecipe);
        flushSession();
        entityManager.clear();

        recipe = recipeDAO.getEntity(Recipe.class, searchedRecipe.getId());
        Assert.assertEquals(1, recipe.getRecipeIngredients().size());
        Assert.assertEquals(saladeDetached.getId(), recipe
                .getRecipeIngredients().iterator().next().getIngredient()
                .getId());
    }
View Full Code Here

        flushSession();

        // clean la session pour detacher les objets
        entityManager.clear();

        Recipe searchedRecipe = detachRecipe(recipe);
        Iterator<RecipeIngredient> it = searchedRecipe.getRecipeIngredients()
                .iterator();
        RecipeIngredient ri1 = it.next();
        ri1.setAmount("new amount");

        recipeDAO.merge(searchedRecipe);
        flushSession();
        entityManager.clear();

        recipe = recipeDAO.getEntity(Recipe.class, searchedRecipe.getId());
        Assert.assertEquals(1, recipe.getRecipeIngredients().size());
        Assert.assertEquals("new amount", recipe.getRecipeIngredients()
                .iterator().next().getAmount());
    }
View Full Code Here

        Assert.assertTrue(recipe.getId() > 0);
        flushSession();
        entityManager.clear();

        // detache la recette a modifier
        Recipe searchedRecipe = detachRecipe(recipe);
        assertEquals(2, searchedRecipe.getRecipeIngredients().size());
        // supprime un ingredient
        Iterator<RecipeIngredient> it = searchedRecipe.getRecipeIngredients()
                .iterator();
        it.next();
        it.remove();
        assertEquals(1, searchedRecipe.getRecipeIngredients().size());
        recipeDAO.merge(searchedRecipe);
        flushSession();
        entityManager.clear();

        recipe = recipeDAO.getEntity(Recipe.class, searchedRecipe.getId());
        Assert.assertEquals(1, recipe.getRecipeIngredients().size());
    }
View Full Code Here

TOP

Related Classes of fr.valtech.many2many.domain.Recipe

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.