package edu.uci.lighthouse.core.controller.test;

import java.io.IOException;

import junit.framework.TestCase;

import org.dom4j.DocumentException;

import edu.uci.lighthouse.core.controller.PushModel;
import edu.uci.lighthouse.model.LighthouseDelta;
import edu.uci.lighthouse.model.LighthouseModelManagerPersistence;
import edu.uci.lighthouse.model.io.LHDeltaXMLPersistence;
import edu.uci.lighthouse.model.io.LighthouseModelXMLPersistence;
import edu.uci.lighthouse.model.jpa.JPAUtilityException;
import edu.uci.lighthouse.test.util.LHTestDataFiles;
import edu.uci.lighthouse.test.util.LighthouseModelTest;

public class PushModelTest extends TestCase {

	public void testExecute() throws DocumentException, IOException, JPAUtilityException {
		LighthouseModelTest xmlModel = new LighthouseModelTest();
		new LighthouseModelXMLPersistence(xmlModel).load(LHTestDataFiles.XML_LH_MODEL);
		
		// Save LH Model Into the database in order to help the
		// BuilderRelationship to handle the External classes
		new LighthouseModelManagerPersistence(xmlModel).saveAllIntoDataBase();
		
		// Load delta from xml file
		LighthouseDelta xmlDelta = new LighthouseDelta();
		new LHDeltaXMLPersistence(xmlDelta).load(LHTestDataFiles.XML_DELTA_ATM_CLASS);
		
		// Update Model
		new PushModel(xmlModel).execute(xmlDelta);
		
		// Load LH Updated Model in XML file
		LighthouseModelTest xmlUpdatedModel = new LighthouseModelTest();
		new LighthouseModelXMLPersistence(xmlUpdatedModel).load(LHTestDataFiles.XML_UPDATED_MODEL);
		
		assertEquals(true, xmlModel.getListEvents().containsAll(xmlUpdatedModel.getListEvents()));
	}

}

@@ -65,32 +65,85 @@
 io.IOException;%0D
+%0Aimport java.util.ArrayList;%0D%0Aimport java.util.List;%0D
 %0A%0D%0Aimport junit.
@@ -308,16 +308,66 @@
 Delta;%0D%0A
+import edu.uci.lighthouse.model.LighthouseEvent;%0D%0A
 import e
@@ -606,24 +606,73 @@
 Exception;%0D%0A
+import edu.uci.lighthouse.model.jpa.LHEventDAO;%0D%0A
 import edu.u
@@ -843,15 +843,28 @@
 test
-Execute
+UpdateModelFromDelta
 () t
@@ -1485,15 +1485,28 @@
 el).
-execute
+updateModelFromDelta
 (xml
@@ -1725,16 +1725,16 @@
 );%0D%0A%09%09%0D%0A
-
 %09%09assert
@@ -1822,14 +1822,905 @@
 ));%0D%0A%09%7D%0D
+%0A%09%0D%0A%09public void testUpdateCommittedEvents() throws DocumentException, JPAUtilityException %7B%0D%0A%09%09LighthouseModelTest xmlModel = new LighthouseModelTest();%0D%0A%09%09new LighthouseModelXMLPersistence(xmlModel).load(LHTestDataFiles.XML_LH_MODEL);%0D%0A%09%09%0D%0A%09%09// Save LH Model Into the database in order to help the%0D%0A%09%09// BuilderRelationship to handle the External classes%0D%0A%09%09new LighthouseModelManagerPersistence(xmlModel).saveAllIntoDataBase();%0D%0A%09%09%0D%0A%09%09List%3CString%3E listClazzFqn = new ArrayList%3CString%3E();%0D%0A%09%09listClazzFqn.add(%22edu.prenticehall.deitel.Screen%22);%0D%0A%09%09listClazzFqn.add(%22edu.prenticehall.deitel.Transaction%22);%0D%0A%09%09new PushModel(xmlModel).updateCommittedEvents(listClazzFqn, %22Max%22);%0D%0A%09%09%0D%0A%09%09String command = %22SELECT e FROM LighthouseEvent e WHERE e.committed=1%22;%0D%0A%09%09List%3CLighthouseEvent%3E listEvents = new LHEventDAO().executeDynamicQuery(command);%0D%0A%09%09assertEquals(true, listEvents.size()==12);%0D%0A%09%7D%0D
 %0A%0D%0A%7D%0D%0A

create method testUpdateCommittedEvents()