/*
 * Copyright (C) 2004-2005  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package com.exedio.cope;

import com.exedio.cope.testmodel.AttributeItem;
import com.exedio.cope.testmodel.EmptyItem;

/**
 * Test, whether database converts empty strings to null,
 * and how the framework hides such behaviour from the user.
 * @author Ralf Wiebicke
 */
public class NullEmptyTest extends TestmodelTest
{
	EmptyItem someItem;
	AttributeItem item;
	AttributeItem item2;
	String emptyString;

	public void setUp() throws Exception
	{
		super.setUp();
		deleteOnTearDown(someItem = new EmptyItem());
		deleteOnTearDown(item = new AttributeItem("someString", 5, 6l, 2.2, true, someItem, AttributeItem.SomeEnum.enumValue1));
		deleteOnTearDown(item2 = new AttributeItem("someString", 5, 6l, 2.2, false, someItem, AttributeItem.SomeEnum.enumValue2));

		if(model.supportsEmptyStrings())
			emptyString = "";
		else
			emptyString = null;
	}

	public void testNullEmpty()
			throws IntegrityViolationException
	{
		assertEquals(null, item.getSomeString());

		item.setSomeString("");
		assertEquals("", item.getSomeString()); // TODO empty to null conversion must take effect immediately
		restartTransaction();
		assertEquals(emptyString, item.getSomeString());

		item.setSomeString(null);
		assertEquals(null, item.getSomeString());
		restartTransaction();
		assertEquals(null, item.getSomeString());
	}

}

@@ -859,61 +859,14 @@
 del.
-AttributeItem;%0Aimport com.exedio.cope.testmodel.Empty
+String
 Item
@@ -1076,59 +1076,14 @@
 %0A%7B%0A%09
-EmptyItem someItem;%0A%09AttributeItem item;%0A%09Attribute
+String
 Item
@@ -1087,17 +1087,16 @@
 tem item
-2
 ;%0A%09Strin
@@ -1192,281 +1192,30 @@
 own(
-someItem = new EmptyItem());%0A%09%09deleteOnTearDown(item = new AttributeItem(%22someString%22, 5, 6l, 2.2, true, someItem, AttributeItem.SomeEnum.enumValue1));%0A%09%09deleteOnTearDown(item2 = new AttributeItem(%22someString%22, 5, 6l, 2.2, false, someItem, AttributeItem.SomeEnum.enumValue2
+item = new StringItem(
 ));%0A
@@ -1400,34 +1400,27 @@
 ll, item.get
-SomeString
+Any
 ());%0A%0A%09%09item
@@ -1423,26 +1423,19 @@
 item.set
-SomeString
+Any
 (%22%22);%0A%09%09
@@ -1455,34 +1455,27 @@
 %22%22, item.get
-SomeString
+Any
 ()); // TODO
@@ -1585,34 +1585,27 @@
 ng, item.get
-SomeString
+Any
 ());%0A%0A%09%09item
@@ -1608,26 +1608,19 @@
 item.set
-SomeString
+Any
 (null);%0A
@@ -1644,34 +1644,27 @@
 ll, item.get
-SomeString
+Any
 ());%0A%09%09resta
@@ -1713,18 +1713,11 @@
 .get
-SomeString
+Any
 ());

use StringItem instead of AttributeItem