/**
 * Created Dec 19, 2007
 */
package com.crawljax.core.state;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.crawljax.util.Helper;

/**
 * @author mesbah
 * @version $Id: EventableTest.java 6275 2009-12-23 14:13:05Z stefan $
 */
public class EventableTest {

	@Test
	public void testHashCode() {
		String xpath = "/body/div[3]";
		Identification id = new Identification("xpath", xpath);
		String eventType = "onclick";

		Eventable c = new Eventable(id, eventType);
		Eventable temp = new Eventable(id, eventType);

		assertEquals(temp.hashCode(), c.hashCode());

		temp = new Eventable(new Identification("id", "34"), eventType);
		assertNotSame(temp.hashCode(), c.hashCode());

		temp = new Eventable(id, "onmouseover");
		assertNotSame(temp.hashCode(), c.hashCode());
	}

	@Test
	public void testToString() {
		Eventable c = new Eventable(new Identification("xpath", "/body/div[3]"), "onclick");

		assertNotNull(c.toString());
	}

	/**
	 * Test method for {@link com.crawljax.core.state.Eventable#equals(java.lang.Object)}.
	 */
	@Test
	public void testEqualsObject() {
		Eventable c = new Eventable(new Identification("xpath", "/body/div[3]"), "onclick");
		Eventable b = new Eventable(new Identification("xpath", "/body/div[3]"), "onclick");
		Eventable d = new Eventable(new Identification("id", "23"), "onclick");
		Eventable e = new Eventable(new Identification("id", "23"), "onmouseover");
		assertTrue(c.equals(b));
		assertFalse(c.equals(d));
		assertFalse(d.equals(e));
	}

	@Test
	public void testGetInfo() {
		Eventable c = new Eventable(new Identification("xpath", "/body/div[3]"), "onclick");
		String info = " onclick xpath /body/div[3]";
		assertEquals(info, c.toString());
	}

	@Test
	public void testClickableElement() {
		String html =
		        "<body><div id='firstdiv'></div><div><span id='thespan'>"
		                + "<a id='thea'>test</a></span></div></body>";

		try {
			Document dom = Helper.getDocument(html);
			assertNotNull(dom);

			Element element = dom.getElementById("firstdiv");

			Eventable clickable = new Eventable(element, "onclick");
			assertNotNull(clickable);

			/*
			 * String infoexpected = "DIV: id=firstdiv, xpath /HTML[1]/BODY[1]/DIV[1] onclick";
			 */
			String infoexpected =
			        "ID: firstdivDIV: id=\"firstdiv\" onclick xpath " + "/HTML[1]/BODY[1]/DIV[1]";
			System.out.println(clickable);
			assertEquals(infoexpected, clickable.toString());
		} catch (Exception e) {
			fail(e.getMessage());
		}
	}
}

@@ -2775,11 +2775,399 @@
 ;%0A%09%09%7D%0A%09%7D
+%0A%0A%09@Test%0A%09public void testEdge() %7B%0A%09%09StateVertix s1 = new StateVertix(%22stateSource%22, %22dom1%22);%0A%09%09StateVertix s2 = new StateVertix(%22stateTarget%22, %22dom2%22);%0A%0A%09%09Eventable e = new Eventable();%0A%09%09Edge edge = new Edge(s1, s2);%0A%09%09e.setEdge(edge);%0A%09%09assertNotNull(%22Edge not null%22, edge);%0A%0A%09%09assertEquals(s1, e.getEdge().getFromStateVertix());%0A%09%09assertEquals(s2, e.getEdge().getToStateVertix());%0A%0A%09%7D
 %0A%7D%0A

test the edge.