package beaform.dao;

import java.util.concurrent.Callable;

import org.apache.commons.collections.ListUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import beaform.debug.DebugUtils;
import beaform.entities.Formula;
import beaform.search.SearchFormulaTask;
import junit.framework.TestCase;

/**
 * Test for the formula DA.
 *
 * @author Steven Post
 *
 */
public class FormlaDAOTest extends TestCase {

	/**
	 * {@inheritDoc}
	 */
	@Override
	@Before
	public void setUp() {
		GraphDbHandler.initInstance("test");
		DebugUtils.clearDb();
	}

	/**
	 * Test for adding a new formula.
	 * @throws Exception
	 */
	@Test
	public void testAddFormula() throws Exception {
		final Formula testForm = new Formula("Testform", "Description", "100g");
		FormulaDAO.addFormula("Testform", "Description", "100g", ListUtils.EMPTY_LIST, ListUtils.EMPTY_LIST);
		final Callable<Formula> task = new SearchFormulaTask("Testform");
		final Formula result = task.call();
		assertEquals("This isn't the expected formula", testForm,  result);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	@After
	public void tearDown() {
		DebugUtils.clearDb();
		GraphDbHandler.clearInstance();
	}

}

@@ -15,16 +15,69 @@
 m.dao;%0A%0A
+import java.util.Collections;%0Aimport java.util.List;%0A
 import j
@@ -106,16 +106,16 @@
 llable;%0A
-
 %0Aimport 
@@ -295,16 +295,52 @@
 ormula;%0A
+import beaform.entities.Ingredient;%0A
 import b
@@ -1064,16 +1064,16 @@
 call();%0A
-
 %09%09assert
@@ -1134,24 +1134,1578 @@
 esult);%0A%09%7D%0A%0A
+%09/**%0A%09 * Test retrieving ingredients%0A%09 * @throws Exception%0A%09 */%0A%09@Test%0A%09public void testGetIngredients() throws Exception %7B%0A%09%09DebugUtils.fillDb();%0A%09%09final Callable%3CFormula%3E task = new SearchFormulaTask(%22Form1%22);%0A%09%09final Formula result = task.call();%0A%09%09final List%3CIngredient%3E ingredients = FormulaDAO.getIngredients(result);%0A%09%09assertEquals(%22The ingredient list isn't the expected size%22, 1, ingredients.size());%0A%09%7D%0A%0A%09/**%0A%09 * Test finding a formula by name%0A%09 * @throws Exception%0A%09 */%0A%09@Test%0A%09public void testFindFormulaByName() throws Exception %7B%0A%09%09DebugUtils.fillDb();%0A%09%09GraphDbHandler.getInstance().getEntityManager().clear();%0A%09%09final Formula formula = FormulaDAO.findFormulaByName(%22Form1%22);%0A%09%09assertEquals(%22This isn't the expected formula%22, %22Form1%22, formula.getName());%0A%09%7D%0A%0A%09/**%0A%09 * Test finding formulas by tag%0A%09 * @throws Exception%0A%09 */%0A%09@Test%0A%09public void testFindFormulasByTag() throws Exception %7B%0A%09%09DebugUtils.fillDb();%0A%09%09final List%3CFormula%3E formulas = FormulaDAO.findFormulasByTag(%22First%22);%0A%09%09assertEquals(%22This isn't the number of found formulas%22, 2, formulas.size());%0A%09%7D%0A%0A%09/**%0A%09 * Test updating an existing formula%0A%09 * @throws Exception%0A%09 */%0A%09@Test%0A%09public void testUpdateExisting() throws Exception %7B%0A%09%09DebugUtils.fillDb();%0A%09%09FormulaDAO.updateExisting(%22Form1%22, %22New description%22, %22100g%22, Collections.emptyList(), Collections.emptyList());%0A%09%09final Callable%3CFormula%3E task = new SearchFormulaTask(%22Form1%22);%0A%09%09final Formula result = task.call();%0A%09%09assertEquals(%22This isn't the expected description%22, %22New description%22, result.getDescription());%0A%09%7D%0A%0A
 %09/**%0A%09 * %7B@i

Add more unit tests