package com.exedio.cope.lib;

import com.exedio.cope.lib.IntegrityViolationException;
import com.exedio.cope.lib.Cope;
import com.exedio.cope.testmodel.FirstSub;
import com.exedio.cope.testmodel.SecondSub;

public class HierarchyTest extends DatabaseLibTest
{
	public void testHierarchy()
			throws IntegrityViolationException
	{
		final FirstSub firstItem = new FirstSub(0);
		assertID(0, firstItem);
		assertEquals(0, firstItem.getSuperInt());
		assertEquals(null, firstItem.getFirstSubString());
		
		firstItem.setSuperInt(2);
		assertEquals(2, firstItem.getSuperInt());
		assertEquals(null, firstItem.getFirstSubString());
		
		firstItem.setFirstSubString("firstSubString");
		assertEquals(2, firstItem.getSuperInt());
		assertEquals("firstSubString", firstItem.getFirstSubString());
		
		firstItem.passivate();
		assertEquals(2, firstItem.getSuperInt());
		assertEquals("firstSubString", firstItem.getFirstSubString());
		
		final SecondSub secondItem = new SecondSub(2);
		assertID(1, secondItem);
		assertEquals(2, secondItem.getSuperInt());
		assertEquals(null, secondItem.getFirstSubString());

		final SecondSub secondItem2 = new SecondSub(3);
		assertID(2, secondItem2);

		final FirstSub firstItem2 = new FirstSub(4);
		assertID(3, firstItem2);
		
		assertEquals(list(firstItem), firstItem.TYPE.search(Cope.equal(firstItem.firstSubString, "firstSubString")));
		assertEquals(list(), firstItem.TYPE.search(Cope.equal(firstItem.firstSubString, "firstSubStringX")));

		firstItem2.delete();
		secondItem2.delete();
		secondItem.delete();
		firstItem.delete();
	}

}

@@ -369,16 +369,47 @@
 Sub(0);%0A
+%09%09deleteOnTearDown(firstItem);%0A
 %09%09assert
@@ -418,32 +418,32 @@
 (0, firstItem);%0A
-
 %09%09assertEquals(0
@@ -997,24 +997,56 @@
 condSub(2);%0A
+%09%09deleteOnTearDown(secondItem);%0A
 %09%09assertID(1
@@ -1210,16 +1210,49 @@
 Sub(3);%0A
+%09%09deleteOnTearDown(secondItem2);%0A
 %09%09assert
@@ -1319,16 +1319,48 @@
 Sub(4);%0A
+%09%09deleteOnTearDown(firstItem2);%0A
 %09%09assert
@@ -1489,24 +1489,24 @@
 String%22)));%0A
+
 %09%09assertEqua
@@ -1600,101 +1600,8 @@
 )));
-%0A%0A%09%09firstItem2.delete();%0A%09%09secondItem2.delete();%0A%09%09secondItem.delete();%0A%09%09firstItem.delete();
 %0A%09%7D%0A

use deleteOnTearDown