
package com.exedio.cope.lib;

public class QualifierTest extends DatabaseLibTest
{
	QualifiedItem item;
	EmptyItem key1;
	EmptyItem key2;
	
	public void setUp() throws Exception
	{
		super.setUp();
		item = new QualifiedItem();
		key1 = new EmptyItem();
		key2 = new EmptyItem();
	}
	
	public void tearDown() throws Exception
	{
		item.delete();
		key2.delete();
		key1.delete();
		super.tearDown();
	}
	
	public void testQualified()
		throws UniqueViolationException, NotNullViolationException, IntegrityViolationException
	{
		assertEquals(QualifiedItem.qualifier.getParent(), QualifiedEmptyQualifier.parent);
		assertEquals(QualifiedItem.qualifier.getKey(), QualifiedEmptyQualifier.key);
		assertEquals(QualifiedItem.qualifier.getQualifyUnique(), QualifiedEmptyQualifier.qualifyUnique);

		assertEquals(null, QualifiedEmptyQualifier.findByQualifyUnique(item, key1));
		assertEquals(null, item.getQualifier(key1));
		assertEquals(null, item.getQualifiedA(key1));
		assertEquals(null, item.getQualifiedB(key1));
		assertEquals(null, QualifiedEmptyQualifier.findByQualifyUnique(item, key2));
		assertEquals(null, item.getQualifiedA(key2));
		assertEquals(null, item.getQualifiedB(key2));

		final QualifiedEmptyQualifier qitem1 = new QualifiedEmptyQualifier(item, key1);
		assertEquals(qitem1, item.getQualifier(key1));
		assertEquals(null, item.getQualifier(key2));
		assertEquals(null, item.getQualifiedA(key1));
		assertEquals(null, item.getQualifiedB(key1));
		assertEquals(null, QualifiedEmptyQualifier.findByQualifyUnique(item, key2));
		assertEquals(null, item.getQualifiedA(key2));
		assertEquals(null, item.getQualifiedB(key2));

		qitem1.setQualifiedA("value1A");
		assertEquals("value1A", item.getQualifiedA(key1));
		assertEquals(null, item.getQualifiedB(key1));
		assertEquals(null, QualifiedEmptyQualifier.findByQualifyUnique(item, key2));
		assertEquals(null, item.getQualifiedA(key2));
		assertEquals(null, item.getQualifiedB(key2));
		
		qitem1.setQualifiedB("value1B");
		assertEquals("value1A", item.getQualifiedA(key1));
		assertEquals("value1B", item.getQualifiedB(key1));
		assertEquals(null, QualifiedEmptyQualifier.findByQualifyUnique(item, key2));
		assertEquals(null, item.getQualifiedA(key2));
		assertEquals(null, item.getQualifiedB(key2));
		
		final QualifiedEmptyQualifier qitem2 = new QualifiedEmptyQualifier(item, key2);
		assertEquals(qitem1, item.getQualifier(key1));
		assertEquals(qitem2, item.getQualifier(key2));
		assertEquals("value1A", item.getQualifiedA(key1));
		assertEquals("value1B", item.getQualifiedB(key1));
		assertEquals(null, item.getQualifiedA(key2));
		assertEquals(null, item.getQualifiedB(key2));

		qitem2.setQualifiedB("value2B");
		assertEquals("value1A", item.getQualifiedA(key1));
		assertEquals("value1B", item.getQualifiedB(key1));
		assertEquals(null, item.getQualifiedA(key2));
		assertEquals("value2B", item.getQualifiedB(key2));

		qitem1.setQualifiedB(null);
		assertEquals("value1A", item.getQualifiedA(key1));
		assertEquals(null, item.getQualifiedB(key1));
		assertEquals(null, item.getQualifiedA(key2));
		assertEquals("value2B", item.getQualifiedB(key2));

		qitem2.delete();
		qitem1.delete();
	}
	
}

@@ -789,87 +789,8 @@
 );%0A%0A
-%09%09assertEquals(null, QualifiedEmptyQualifier.findByQualifyUnique(item, key1));%0A
 %09%09as
@@ -824,32 +824,32 @@
 alifier(key1));%0A
+
 %09%09assertEquals(n
@@ -953,58 +953,26 @@
 ll, 
-QualifiedEmptyQualifier.findByQualifyUnique(item, 
+item.getQualifier(
 key2
@@ -1207,55 +1207,8 @@
 ));%0A
-%09%09assertEquals(null, item.getQualifier(key2));%0A
 %09%09as
@@ -1324,58 +1324,26 @@
 ll, 
-QualifiedEmptyQualifier.findByQualifyUnique(item, 
+item.getQualifier(
 key2
@@ -1474,24 +1474,73 @@
 %22value1A%22);%0A
+%09%09assertEquals(qitem1, item.getQualifier(key1));%0A
 %09%09assertEqua
@@ -1653,58 +1653,26 @@
 ll, 
-QualifiedEmptyQualifier.findByQualifyUnique(item, 
+item.getQualifier(
 key2
@@ -1805,24 +1805,73 @@
 %22value1B%22);%0A
+%09%09assertEquals(qitem1, item.getQualifier(key1));%0A
 %09%09assertEqua
@@ -1989,58 +1989,26 @@
 ll, 
-QualifiedEmptyQualifier.findByQualifyUnique(item, 
+item.getQualifier(
 key2
@@ -2245,57 +2245,8 @@
 ));%0A
-%09%09assertEquals(qitem2, item.getQualifier(key2));%0A
 %09%09as
@@ -2339,32 +2339,81 @@
 lifiedB(key1));%0A
+%09%09assertEquals(qitem2, item.getQualifier(key2));%0A
 %09%09assertEquals(n
@@ -2524,24 +2524,73 @@
 %22value2B%22);%0A
+%09%09assertEquals(qitem1, item.getQualifier(key1));%0A
 %09%09assertEqua
@@ -2675,32 +2675,81 @@
 lifiedB(key1));%0A
+%09%09assertEquals(qitem2, item.getQualifier(key2));%0A
 %09%09assertEquals(n
@@ -2864,16 +2864,65 @@
 (null);%0A
+%09%09assertEquals(qitem1, item.getQualifier(key1));%0A
 %09%09assert
@@ -2958,32 +2958,32 @@
 lifiedA(key1));%0A
-
 %09%09assertEquals(n
@@ -3006,32 +3006,81 @@
 lifiedB(key1));%0A
+%09%09assertEquals(qitem2, item.getQualifier(key2));%0A
 %09%09assertEquals(n

refactor and complete test