Package fr.valtech.many2many.domain

Examples of fr.valtech.many2many.domain.RecipeIngredient


    public void setUp() throws Exception {

        jambon = new Ingredient();
        jambon.setLabel("jambon");

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

        recipe = new Recipe();
        recipe.setTitle("title");
View Full Code Here


        // recette1
        Ingredient pain = new Ingredient();
        pain.setLabel("pain");

        RecipeIngredient _100gPain = new RecipeIngredient(pain, "100g");
        recipe.addRecipeIngredient(_100gPain);
        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)) {
                foundi1 = true;
            }
            if (ri.getIngredient().equals(i2)) {
                foundi2 = true;
            }
        }
        Assert.assertTrue(foundi1);
        Assert.assertTrue(foundi2);
View Full Code Here

        // 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();
View Full Code Here

        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();
View Full Code Here

        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();
View Full Code Here

        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();
View Full Code Here

        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();
View Full Code Here

            throws Exception {
        // enregistre la recette avec 2 ingredients (salade et jambon)
        Assert.assertNull(recipe.getId());
        Ingredient salade = new Ingredient();
        salade.setLabel("salade");
        RecipeIngredient _1feuilleSalade = new RecipeIngredient();
        _1feuilleSalade.setIngredient(salade);
        _1feuilleSalade.setAmount("1 feuille");
        recipe.addRecipeIngredient(_1feuilleSalade);
        recipeDAO.save(recipe);
        Assert.assertTrue(recipe.getId() > 0);
        flushSession();
        entityManager.clear();
View Full Code Here

        detachedRecipe.setId(r.getId());
        detachedRecipe.setTitle(r.getTitle());

        Iterator<RecipeIngredient> it = r.getRecipeIngredients().iterator();
        while (it.hasNext()) {
            RecipeIngredient ri = it.next();
            Ingredient i = new Ingredient();
            i.setId(ri.getIngredient().getId());
            RecipeIngredient detachedRi = new RecipeIngredient(i,
                    ri.getAmount());
            detachedRecipe.addRecipeIngredient(detachedRi);
        }

        return detachedRecipe;
View Full Code Here

     */
    private void reatachIngredients(Recipe recipe) {

        for (Iterator<RecipeIngredient> it = recipe.getRecipeIngredients()
                .iterator(); it.hasNext();) {
            RecipeIngredient ri = it.next();
            Ingredient ingredient = ri.getIngredient();
            if (ingredient.getId() != null && ingredient.getId() != 0) {
                Ingredient reference = getEntityManager().getReference(
                        Ingredient.class, ingredient.getId());
                ri.setIngredient(reference);
            } else {
                getEntityManager().persist(ingredient);
            }
        }
    }
View Full Code Here

TOP

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

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.