package com.exedio.copernica;

import net.sourceforge.jwebunit.WebTestCase;

public class WebTest extends WebTestCase
{

	public WebTest(String name)
	{
		super(name);
	}

	String someNotNullString;
	String someNotNullInteger;
	String someBoolean;
	boolean someNotNullBoolean;
	String someEnumeration;
	String someNotNullEnumeration;

	public void setUp() throws Exception
	{
		super.setUp();
		getTestContext().setBaseUrl("http://localhost:8080/copernicatest/");
		someNotNullString = "running100";
		someNotNullInteger = "107";
		someBoolean = "null";
		someNotNullBoolean = true;
		someEnumeration = "null";
		someNotNullEnumeration = "enumValue2";
	}
	
	private void assertItemForm()
	{
		assertFormElementEquals("someNotNullString", someNotNullString);
		assertFormElementEquals("someNotNullInteger", someNotNullInteger);
		assertFormElementEquals("someBoolean", someBoolean);
		if(someNotNullBoolean)
			assertCheckboxSelected("someNotNullBoolean");
		else
			assertCheckboxNotSelected("someNotNullBoolean");
		assertFormElementEquals("someEnumeration", someEnumeration);
		assertFormElementEquals("someNotNullEnumeration", someNotNullEnumeration);
	}

	public void testSearch()
	{
		beginAt("copernica.jsp");
		assertTitleEquals("Copernica");
		assertLinkPresentWithText("de");

		clickLinkWithText("Attribute Item");
		assertTitleEquals("Attribute Item");
		assertTextPresent("Attribute Item");
		
		assertLinkPresentWithText("50");
		clickLinkWithText("50");
		assertTitleEquals("Attribute Item");
		assertLinkNotPresentWithText("50");

		clickLinkWithText("[X]");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();

		setFormElement("someNotNullString", "running100changed"); someNotNullString = "running100changed";
		submit("SAVE");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();

		setFormElement("someNotNullInteger", "1077"); someNotNullInteger = "1077";
		submit("SAVE");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();

		setFormElement("someBoolean", "on"); someBoolean = "on";
		submit("SAVE");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();

		setFormElement("someBoolean", "off"); someBoolean = "off";
		submit("SAVE");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();

		uncheckCheckbox("someNotNullBoolean"); someNotNullBoolean = false;
		submit("SAVE");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();

		setFormElement("someEnumeration", "enumValue2"); someEnumeration = "enumValue2";
		submit("SAVE");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();

		setFormElement("someNotNullEnumeration", "enumValue1"); someNotNullEnumeration = "enumValue1";
		submit("SAVE");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();

		setFormElement("someNotNullString", "running100"); someNotNullString = "running100";
		setFormElement("someNotNullInteger", "107"); someNotNullInteger = "107";
		setFormElement("someBoolean", "null"); someBoolean = "null";
		setFormElement("someNotNullBoolean", "on"); someNotNullBoolean = true;
		setFormElement("someEnumeration", "null"); someEnumeration = "null";
		setFormElement("someNotNullEnumeration", "enumValue2"); someNotNullEnumeration = "enumValue2";
		submit("SAVE");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();
	}
}

@@ -326,16 +326,41 @@
 eration;
+%0A%09String someNotNullItem;
 %0A%0A%09publi
@@ -670,16 +670,51 @@
 alue2%22;%0A
+%09%09someNotNullItem = %22EmptyItem.1%22;%0A
 %09%7D%0A%09%0A%09pr
@@ -1208,16 +1208,79 @@
 ation);%0A
+%09%09assertFormElementEquals(%22someNotNullItem%22, someNotNullItem);%0A
 %09%7D%0A%0A%09pub
@@ -2859,32 +2859,198 @@
 ertItemForm();%0A%0A
+%09%09setFormElement(%22someNotNullItem%22, %22EmptyItem.2%22); someNotNullItem = %22EmptyItem.2%22;%0A%09%09submit(%22SAVE%22);%0A%09%09assertTitleEquals(%22AttributeItem.103%22);%0A%09%09assertItemForm();%0A%0A
 %09%09setFormElement
@@ -3491,32 +3491,117 @@
 = %22enumValue2%22;%0A
+%09%09setFormElement(%22someNotNullItem%22, %22EmptyItem.1%22); someNotNullItem = %22EmptyItem.1%22;%0A
 %09%09submit(%22SAVE%22)

test someNotNullItem