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;

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

	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("someNotNullString", "running100"); someNotNullString = "running100";
		setFormElement("someNotNullInteger", "107"); someNotNullInteger = "107";
		setFormElement("someBoolean", "null"); someBoolean = "null";
		setFormElement("someNotNullBoolean", "on"); someNotNullBoolean = true;
		submit("SAVE");
		assertTitleEquals("AttributeItem.103");
		assertItemForm();
	}
}

@@ -269,16 +269,41 @@
 Boolean;
+%0A%09String someEnumeration;
 %0A%0A%09publi
@@ -544,16 +544,44 @@
 = true;%0A
+%09%09someEnumeration = %22null%22;%0A
 %09%7D%0A%09%0A%09pr
@@ -883,16 +883,16 @@
 %0A%09%09else%0A
-
 %09%09%09asser
@@ -935,16 +935,79 @@
 lean%22);%0A
+%09%09assertFormElementEquals(%22someEnumeration%22, someEnumeration);%0A
 %09%7D%0A%0A%09pub
@@ -2244,32 +2244,196 @@
 ertItemForm();%0A%0A
+%09%09setFormElement(%22someEnumeration%22, %22enumValue2%22); someEnumeration = %22enumValue2%22;%0A%09%09submit(%22SAVE%22);%0A%09%09assertTitleEquals(%22AttributeItem.103%22);%0A%09%09assertItemForm();%0A%0A
 %09%09setFormElement
@@ -2714,16 +2714,87 @@
 = true;%0A
+%09%09setFormElement(%22someEnumeration%22, %22null%22); someEnumeration = %22null%22;%0A
 %09%09submit

test someEnumeration