<#assign curr = entities[current_entity] />
package ${curr.test_namespace};


import ${curr.namespace}.data.${curr.name}SQLiteAdapter;
import ${curr.namespace}.entity.${curr.name};

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.test.AndroidTestCase;

import junit.framework.Assert;

/** ${curr.name} database test abstract class <br/>
 * <b><i>This class will be overwrited whenever you regenerate the project with Harmony. 
 * You should edit ${curr.name}TestDB class instead of this one or you will lose all your modifications.</i></b>
 */
public abstract class ${curr.name}TestDBBase extends AndroidTestCase {
	private Context ctx;

	private ${curr.name}SQLiteAdapter adapter;

	private SQLiteDatabase db;
	private ${curr.name} entity;

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
		
		this.ctx = this.getContext();
		
		this.adapter = new ${curr.name}SQLiteAdapter(this.ctx);
		this.entity = new ${curr.name}();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	/** Test case Create Entity */
	public void testCreate() {
		int result = -1;

		this.db = this.adapter.open();
		this.db.beginTransaction();
		try {
			result = (int) this.adapter.insert(this.entity);

			this.db.setTransactionSuccessful();
		} finally {
			this.db.endTransaction();
			this.adapter.close();
		}

		Assert.assertTrue(result >= 0);
	}
	
	/** Test case Read Entity */
	public void testRead() {
		int result = -1;

		this.db = this.adapter.open();
		this.db.beginTransaction();
		try {
			this.entity = this.adapter.getByID(this.entity.getId()); // TODO Generate by @Id annotation
			if (this.entity != null)
				result = 0;

			this.db.setTransactionSuccessful();
		} finally {
			this.db.endTransaction();
			this.adapter.close();
		}
		
		Assert.assertTrue(result >= 0);
	}
	
	/** Test case Update Entity */
	public void testUpdate() {
		// TODO on all fields
		//this.model.setXxxx(newValue);
		
		int result = -1;

		this.db = this.adapter.open();
		this.db.beginTransaction();
		try {
			result = this.adapter.update(this.entity);

			this.db.setTransactionSuccessful();
		} finally {
			this.db.endTransaction();
			this.adapter.close();
		}
		
		Assert.assertTrue(result >= 0);

		// TODO on all fields
		//Assert.assertEquals(newValue, this.model.getXxxx()) 
	}
	
	/** Test case Update Entity */
	public void testDelete() {
		int result = -1;

		this.db = this.adapter.open();
		this.db.beginTransaction();
		try {
			result = this.adapter.remove(this.entity.getId());

			this.db.setTransactionSuccessful();
		} finally {
			this.db.endTransaction();
			this.adapter.close();
		}
		
		Assert.assertTrue(result >= 0);
	}
}

@@ -1038,16 +1038,143 @@
 ame%7D();%0A
+%09%09%0A%09%09this.db = this.adapter.open();%0A%09%09this.db.beginTransaction();%0A%09%09this.entity.setId((int) this.adapter.insert(this.entity));%0A
 %09%7D%0A%0A%09/* 
@@ -1303,16 +1303,71 @@
 Down();%0A
+%09%09%0A%09%09this.db.endTransaction();%0A%09%09this.adapter.close();%0A
 %09%7D%0A%09%0A%09/*
@@ -1449,240 +1449,37 @@
 %0A%0A%09%09
-this.db = this.adapter.open();%0A%09%09this.db.beginTransaction();%0A%09%09try %7B%0A%09%09%09result = (int) this.adapter.insert(this.entity);%0A%0A%09%09%09this.db.setTransactionSuccessful();%0A%09%09%7D finally %7B%0A%09%09%09this.db.endTransaction();%0A%09%09%09this.adapter.close();%0A%09%09%7D
+result = this.entity.getId();
 %0A%0A%09%09
@@ -1595,80 +1595,8 @@
 1;%0A%0A
-%09%09this.db = this.adapter.open();%0A%09%09this.db.beginTransaction();%0A%09%09try %7B%0A%09
 %09%09th
@@ -1687,17 +1687,16 @@
 ation%0A%09%09
-%09
 if (this
@@ -1715,17 +1715,16 @@
 ull)%0A%09%09%09
-%09
 result =
@@ -1730,120 +1730,8 @@
 = 0;
-%0A%0A%09%09%09this.db.setTransactionSuccessful();%0A%09%09%7D finally %7B%0A%09%09%09this.db.endTransaction();%0A%09%09%09this.adapter.close();%0A%09%09%7D
 %0A%09%09%0A
@@ -1916,675 +1916,305 @@
 %0A%0A%09%09
-this.db = this.adapter.open();%0A%09%09this.db.beginTransaction();%0A%09%09try %7B%0A%09%09%09result = this.adapter.update(this.entity);%0A%0A%09%09%09this.db.setTransactionSuccessful();%0A%09%09%7D finally %7B%0A%09%09%09this.db.endTransaction();%0A%09%09%09this.adapter.close();%0A%09%09%7D%0A%09%09%0A%09%09Assert.assertTrue(result %3E= 0);%0A%0A%09%09// TODO on all fields%0A%09%09//Assert.assertEquals(newValue, this.model.getXxxx()) %0A%09%7D%0A%09%0A%09/** Test case Update Entity */%0A%09public void testDelete() %7B%0A%09%09int result = -1;%0A%0A%09%09this.db = this.adapter.open();%0A%09%09this.db.beginTransaction();%0A%09%09try %7B%0A%09%09%09result = this.adapter.remove(this.entity.getId());%0A%0A%09%09%09this.db.setTransactionSuccessful();%0A%09%09%7D finally %7B%0A%09%09%09this.db.endTransaction();%0A%09%09%09this.adapter.close();%0A%09%09%7D
+result = this.adapter.update(this.entity);%0A%0A%09%09Assert.assertTrue(result %3E= 0);%0A%0A%09%09// TODO on all fields%0A%09%09//Assert.assertEquals(newValue, this.model.getXxxx()) %0A%09%7D%0A%09%0A%09/** Test case Update Entity */%0A%09public void testDelete() %7B%0A%09%09int result = -1;%0A%0A%09%09result = this.adapter.remove(this.entity.getId());
 %0A%09%09%0A

Update test db for fixtures