/*
 * Copyright (C) 2004-2006  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.dtype;

import com.exedio.cope.AbstractLibTest;
import com.exedio.cope.Main;

public class DTypeTest extends AbstractLibTest
{
	public DTypeTest()
	{
		super(Main.dtypeModel);
	}
	
	DTypeItem item, item2;
	
	public void setUp() throws Exception
	{
		super.setUp();
		deleteOnTearDown(item = new DTypeItem("item1"));
		deleteOnTearDown(item2 = new DTypeItem("item2"));
	}
	
	public void testIt()
	{
		assertEquals(item.TYPE, item.features.getType());
		assertEquals("features", item.features.getName());
		
		assertContains(item.features.getTypes());
		
		final DType handy = item.features.createType("handy");
		deleteOnTearDown(handy);
		assertContains(handy, item.features.getTypes());
		assertContains(handy.getAttributes());

		final DAttribute akkuTime = handy.addIntegerAttribute("akkuTime");
		deleteOnTearDown(akkuTime);
		assertEquals(0, akkuTime.getPosition());
		assertEquals(list(akkuTime), handy.getAttributes());

		final DAttribute memory = handy.addStringAttribute("memory");
		deleteOnTearDown(memory);
		assertEquals(1, memory.getPosition());
		assertEquals(list(akkuTime, memory), handy.getAttributes());
		
		assertEquals(null, item.features.getType(item));
		
		item.features.setType(item, handy);
		assertEquals(handy, item.features.getType(item));
		
		assertEquals(null, akkuTime.get(item));
		assertEquals(null, memory.get(item));
		
		akkuTime.set(item, 5);
		assertEquals(5, akkuTime.get(item));
		assertEquals(null, memory.get(item));
		
		akkuTime.set(item, 80);
		assertEquals(80, akkuTime.get(item));
		assertEquals(null, memory.get(item));
		
		memory.set(item, "80TB");
		assertEquals(80, akkuTime.get(item));
		assertEquals("80TB", memory.get(item));

		item.features.setType(item, null);
		assertEquals(null, item.features.getType(item));
	}
	
}

@@ -1388,21 +1388,25 @@
 l DType 
-handy
+cellPhone
  = item.
@@ -1426,21 +1426,25 @@
 teType(%22
-handy
+cellPhone
 %22);%0A%09%09de
@@ -1458,21 +1458,25 @@
 earDown(
-handy
+cellPhone
 );%0A%09%09ass
@@ -1487,21 +1487,25 @@
 ontains(
-handy
+cellPhone
 , item.f
@@ -1542,21 +1542,25 @@
 ontains(
-handy
+cellPhone
 .getAttr
@@ -1601,21 +1601,25 @@
 uTime = 
-handy
+cellPhone
 .addInte
@@ -1748,21 +1748,25 @@
 uTime), 
-handy
+cellPhone
 .getAttr
@@ -1805,21 +1805,25 @@
 emory = 
-handy
+cellPhone
 .addStri
@@ -1953,21 +1953,25 @@
 emory), 
-handy
+cellPhone
 .getAttr
@@ -2068,21 +2068,25 @@
 e(item, 
-handy
+cellPhone
 );%0A%09%09ass
@@ -2099,13 +2099,17 @@
 als(
-handy
+cellPhone
 , it

rename handy to cellPhone