package beaform.dao;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;

import beaform.debug.DebugUtils;
import beaform.entities.FormulaTag;

/**
 * Test for the tag DAO.
 *
 * @author Steven Post
 *
 */
@SuppressWarnings("static-method")
public class FormulaTagDAOTest {

	@Before
	public void setUp() {
		GraphDbHandler.initInstance("neo4j_test/db");
		DebugUtils.clearDb();
	}

	@Test
	public void testFindOrCreate() {
		String name;

		DebugUtils.fillDb();
		final GraphDatabaseService graphDb = GraphDbHandler.getInstance().getService();
		try (Transaction tx = graphDb.beginTx()) {
			Node tag = FormulaTagDAO.findOrCreate(new FormulaTag("First"));
			name = (String) tag.getProperty("name");
			tx.success();
		}

		assertNotNull("The tag wasn't found", name);
		assertEquals("This isn't the expected formula", "First", name);
	}

	@After
	public void tearDown() {
		DebugUtils.clearDb();
	}

}

@@ -645,243 +645,1133 @@
 eate
-() %7B%0A%09%09String name;%0A%0A%09%09DebugUtils.fillDb();%0A%09%09final GraphDatabaseService graphDb = GraphDbHandler.getInstance().getService();%0A%09%09try (Transaction tx = graphDb.beginTx()) %7B%0A%09%09%09Node tag = FormulaTagDAO.findOrCreate(new FormulaTag(%22First%22)
+WithoutData() %7B%0A%09%09String name;%0A%0A%09%09final GraphDatabaseService graphDb = GraphDbHandler.getInstance().getService();%0A%09%09try (Transaction tx = graphDb.beginTx()) %7B%0A%09%09%09Node tag = FormulaTagDAO.findOrCreate(new FormulaTag(%22First%22));%0A%09%09%09name = (String) tag.getProperty(%22name%22);%0A%09%09%09tx.success();%0A%09%09%7D%0A%0A%09%09assertNotNull(%22The tag wasn't found%22, name);%0A%09%09assertEquals(%22This isn't the expected formula%22, %22First%22, name);%0A%09%7D%0A%0A%09@Test%0A%09public void testFindOrCreateWithData() %7B%0A%09%09String name;%0A%0A%09%09DebugUtils.fillDb();%0A%09%09final GraphDatabaseService graphDb = GraphDbHandler.getInstance().getService();%0A%09%09try (Transaction tx = graphDb.beginTx()) %7B%0A%09%09%09Node tag = FormulaTagDAO.findOrCreate(new FormulaTag(%22First%22));%0A%09%09%09name = (String) tag.getProperty(%22name%22);%0A%09%09%09tx.success();%0A%09%09%7D%0A%0A%09%09assertNotNull(%22The tag wasn't found%22, name);%0A%09%09assertEquals(%22This isn't the expected formula%22, %22First%22, name);%0A%09%7D%0A%0A%09@Test%0A%09public void testFindByName() %7B%0A%09%09String name;%0A%0A%09%09DebugUtils.fillDb();%0A%09%09final GraphDatabaseService graphDb = GraphDbHandler.getInstance().getService();%0A%09%09try (Transaction tx = graphDb.beginTx()) %7B%0A%09%09%09Node tag = FormulaTagDAO.findByName(%22First%22
 );%0A%09

Add tests for finding tags