Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / tests / JavaCodeGeneratorTest.java
package tests;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.junit.Test;

import algorithms.*;
import code.ast.CompilationUnit;
import code.ast.FieldDeclaration;
import code.ast.MethodDeclaration;
import code.ast.TypeDeclaration;
import code.ast.VariableDeclaration;
import generators.CodeGenerator;
import generators.CodeGeneratorFromDataFlowGraph;
import generators.DataTransferMethodAnalyzer;
import generators.JavaSpecific;
import generators.StandaloneSpecific;
import generators.TypeInference;
import models.Edge;
import models.dataFlowModel.*;
import parser.*;
import parser.exceptions.ExpectedAssignment;
import parser.exceptions.ExpectedChannel;
import parser.exceptions.ExpectedChannelName;
import parser.exceptions.ExpectedColon;
import parser.exceptions.ExpectedDoubleQuotation;
import parser.exceptions.ExpectedEquals;
import parser.exceptions.ExpectedInOrOutOrRefOrSubKeyword;
import parser.exceptions.ExpectedLeftCurlyBracket;
import parser.exceptions.ExpectedRHSExpression;
import parser.exceptions.ExpectedRightBracket;
import parser.exceptions.ExpectedRightCurlyBracket;
import parser.exceptions.ExpectedStateTransition;
import parser.exceptions.WrongJsonExpression;
import parser.exceptions.WrongLHSExpression;
import parser.exceptions.WrongPathExpression;
import parser.exceptions.WrongRHSExpression;

public class JavaCodeGeneratorTest {
	
	@Test
	public void test() {
		testAccounts();
		testClock();
		testCustomerManagement();		// Two methods with the same signature are generated. 
		testGroupChat();
		testInventoryManagement();
//		testOnlineBattleGame();			// A feature has not been implemented for Java prototype generation.
		testOnlineBattleGame2();		// Two methods with the same signature are generated. PUSH-first implementation still does not work.
		testPOS();
		testSimpleTwitter();
		testVotingSystem();
		testWeatherObservationSystem();
	}
	
	private void testAccounts() {
		try {
			ArrayList<CompilationUnit> generatedCode = generateCode("models/Accounts.model", null);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   1))),
																   Map.entry("getAccount", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of("int"),
																									 1))),
																   Map.entry("getName", Map.entry("String", 
																								  Map.entry(List.of("int"),
																								  1))),
																   Map.entry("changeName", Map.entry("void", 
																									 Map.entry(List.of("int","String"),
																									 1))),
																   Map.entry("getAccounts", Map.entry("List<Account>", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("signup", Map.entry("void", 
																								 Map.entry(List.of("String"),
																								 1))))));
			exprectedStructure.put("Account", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("getName", Map.entry("String", 
																									 Map.entry(List.of(),
																									 1))),
																	  Map.entry("changeName", Map.entry("void", 
																										Map.entry(List.of("int","String"),
																										1))),
																	  Map.entry("Account", Map.entry("void", 
																									 Map.entry(List.of("String"),
																									 1))))));
			exprectedStructure.put("Accounts", Map.entry(Map.ofEntries(),
														 Map.ofEntries(Map.entry("getValue", Map.entry("List<Account>", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("getAccount", Map.entry("Account", 
																										 Map.entry(List.of("int"),
																										 1))),
																	   Map.entry("signup", Map.entry("void", 
																									 Map.entry(List.of("String"),
																									 1))))));
			
			checkStructure(generatedCode, exprectedStructure);						
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	private void testClock() {
		try {
			// check PULL-first
			ArrayList<CompilationUnit> generatedCode = generateCode("models/Clock.model", PushPullValue.PULL);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("hour", "Hour"),
																   Map.entry("hour_ang", "Hour_ang"),
																   Map.entry("min", "Min"),
																   Map.entry("min_ang", "Min_ang")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   4))),
																   Map.entry("getHour", Map.entry("int", 
																								  Map.entry(List.of(),
																								  1))),
																   Map.entry("getHour_ang", Map.entry("double", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("getMin", Map.entry("int", 
																								 Map.entry(List.of(),
																								 1))),
																   Map.entry("tick", Map.entry("void", 
																							   Map.entry(List.of(),
																							   1))),
																   Map.entry("getMin_ang", Map.entry("double", 
																									 Map.entry(List.of(),
																									 1))))));
			exprectedStructure.put("Hour", Map.entry(Map.ofEntries(),
													 Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("updateFromMin", Map.entry("void", 
																										Map.entry(List.of("int"),
																										1))))));
			exprectedStructure.put("Hour_ang", Map.entry(Map.ofEntries(),
														 Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("Hour_ang", Map.entry("void", 
																									   Map.entry(List.of("Hour"),
																									   1))))));
			exprectedStructure.put("Min", Map.entry(Map.ofEntries(Map.entry("value", "int"),
																  Map.entry("hour", "Hour")),
													Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																								  Map.entry(List.of(),
																								  1))),
																  Map.entry("tick", Map.entry("void", 
																							  Map.entry(List.of(),
																							  2))),
																  Map.entry("Min", Map.entry("void", 
																							 Map.entry(List.of("Hour"),
																							 1))))));
			exprectedStructure.put("Min_ang", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("Min_ang", Map.entry("void", 
																									 Map.entry(List.of("Min"),
																									 1))))));
			
			checkStructure(generatedCode, exprectedStructure);
//			generateCheckCode(generatedCode);
			
			// check PUSH-first
			generatedCode = generateCode("models/Clock.model", PushPullValue.PUSH);
			exprectedStructure.clear();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("hour_ang", "Hour_ang"),
																   Map.entry("min_ang", "Min_ang"),
																   Map.entry("hour", "Hour"),
																   Map.entry("min", "Min")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   4))),
																   Map.entry("getHour_ang", Map.entry("double", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("getMin_ang", Map.entry("double", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("getHour", Map.entry("int", 
																								  Map.entry(List.of(),
																								  1))),
																   Map.entry("getMin", Map.entry("int", 
																								 Map.entry(List.of(),
																								 1))),
																   Map.entry("tick", Map.entry("void", 
																							   Map.entry(List.of(),
																							   1))))));
			exprectedStructure.put("Hour_ang", Map.entry(Map.ofEntries(),
														 Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("updateFromHour", Map.entry("void", 
																											 Map.entry(List.of("int"),
																											 1))))));
			exprectedStructure.put("Min_ang", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("updateFromMin", Map.entry("void", 
																										   Map.entry(List.of("int"),
																										   1))))));
			exprectedStructure.put("Hour", Map.entry(Map.ofEntries(Map.entry("value", "int"),
																   Map.entry("hour_ang", "Hour_ang")),
													 Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("updateFromMin", Map.entry("void", 
																										Map.entry(List.of("int"),
																										2))),
																   Map.entry("Hour", Map.entry("void", 
																							   Map.entry(List.of("Hour_ang"),
																							   1))))));
			exprectedStructure.put("Min", Map.entry(Map.ofEntries(Map.entry("value", "int"),
																  Map.entry("min_ang", "Min_ang"),
																  Map.entry("hour", "Hour")),
													Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																								  Map.entry(List.of(),
																								  1))),
																  Map.entry("tick", Map.entry("void", 
																							  Map.entry(List.of(),
																							  3))),
																  Map.entry("Min", Map.entry("void", 
																							 Map.entry(List.of("Min_ang","Hour"),
																							 2))))));
			
			checkStructure(generatedCode, exprectedStructure);
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	private void testCustomerManagement() {
		try {
			ArrayList<CompilationUnit> generatedCode = generateCode("models/CustomerManagement.model", null);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("companies", "Companies"),
																   Map.entry("customers", "Customers")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   2))),
																   Map.entry("getAddress", Map.entry("String", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("setAddress", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))),
																   Map.entry("getCustomer", Map.entry("Map<String, Object>", 
																									  Map.entry(List.of("String"),
																									  1))),
																   Map.entry("getCompanies", Map.entry("Map<String, Company>", 
																									   Map.entry(List.of(),
																									   1))),
																   Map.entry("addCampany", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))),
																   Map.entry("getOrganization", Map.entry("String", 
																										  Map.entry(List.of("String"),
																										  1))),
																   Map.entry("setOrganization", Map.entry("void", 
																										  Map.entry(List.of("String","String"),
																										  1))),
//																   Map.entry("getAddress", Map.entry("String", 
//																									 Map.entry(List.of("String"),
//																									 1))),
																   Map.entry("getCompany", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("getCustomers", Map.entry("Map<String, Customer>", 
																									   Map.entry(List.of(),
																									   1))),
																   Map.entry("addCustomer", Map.entry("void", 
																									  Map.entry(List.of("String","String"),
																									  1))))));
			exprectedStructure.put("Customer", Map.entry(Map.ofEntries(Map.entry("organization", "String"),
																	   Map.entry("company", "Company"),
																	   Map.entry("companies", "Companies")),
														 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("getOrganization", Map.entry("String", 
																											  Map.entry(List.of(),
																											  1))),
																	   Map.entry("getAddress", Map.entry("String", 
																										 Map.entry(List.of(),
																										 1))),
																	   Map.entry("setOrganization", Map.entry("void", 
																											  Map.entry(List.of("String","String"),
																											  2))),
																	   Map.entry("Customer", Map.entry("void", 
																									   Map.entry(List.of("String","Companies"),
																									   3))))));
			exprectedStructure.put("Companies", Map.entry(Map.ofEntries(),
														  Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Company>", 
																										Map.entry(List.of(),
																										1))),
																		Map.entry("getCompany", Map.entry("Company", 
																										  Map.entry(List.of("String"),
																										  1))),
																		Map.entry("addCampany", Map.entry("void", 
																										  Map.entry(List.of("String","String"),
																										  1))))));
			exprectedStructure.put("Company", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("getAddress", Map.entry("String", 
																										Map.entry(List.of(),
																										1))),
																	  Map.entry("setAddress", Map.entry("void", 
																										Map.entry(List.of("String","String"),
																										1))),
																	  Map.entry("Company", Map.entry("void", 
																									 Map.entry(List.of("String"),
																									 1))))));
			exprectedStructure.put("Customers", Map.entry(Map.ofEntries(Map.entry("value", "Map<String, Customer>"),
																		Map.entry("companies", "Companies")),
														  Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Customer>", 
																										Map.entry(List.of(),
																										1))),
																		Map.entry("getCustomer", Map.entry("Customer", 
																										   Map.entry(List.of("String"),
																										   1))),
																		Map.entry("addCustomer", Map.entry("void", 
																										   Map.entry(List.of("String","String"),
																										   1))),
																		Map.entry("Customers", Map.entry("void", 
																										 Map.entry(List.of("Companies"),
																										 1))))));
			
			checkStructure(generatedCode, exprectedStructure);
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	private void testGroupChat() {
		try {
			ArrayList<CompilationUnit> generatedCode = generateCode("models/GroupChat.model", null);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("accounts", "Accounts"),
																   Map.entry("groups", "Groups")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   2))),
																   Map.entry("getAccounts", Map.entry("Map<String, Account>", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("signUp", Map.entry("void", 
																								 Map.entry(List.of("String"),
																								 1))),
																   Map.entry("getGroup", Map.entry("Map<String, Object>", 
																								   Map.entry(List.of("String"),
																								   1))),
																   Map.entry("getMessages", Map.entry("List<String>", 
																									  Map.entry(List.of("String"),
																									  1))),
																   Map.entry("postMessage", Map.entry("void", 
																									  Map.entry(List.of("String","String"),
																									  1))),
																   Map.entry("getAccount", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("getMember", Map.entry("String", 
																									Map.entry(List.of("String","int"),
																									1))),
																   Map.entry("getNotifications", Map.entry("Map<String, Boolean>", 
																										   Map.entry(List.of("String"),
																										   1))),
																   Map.entry("hasRead", Map.entry("void", 
																								  Map.entry(List.of("String","String"),
																								  1))),
																   Map.entry("getMembers", Map.entry("List<String>", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("addGroupMember", Map.entry("void", 
																										 Map.entry(List.of("String","String"),
																										 1))),
																   Map.entry("getGroups", Map.entry("Map<String, Group>", 
																									Map.entry(List.of(),
																									1))),
																   Map.entry("createGroup", Map.entry("void", 
																									  Map.entry(List.of("String"),
																									  1))))));
			exprectedStructure.put("Accounts", Map.entry(Map.ofEntries(),
														 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Account>", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("getAccount", Map.entry("Account", 
																										 Map.entry(List.of("String"),
																										 1))),
																	   Map.entry("signUp", Map.entry("void", 
																									 Map.entry(List.of("String"),
																									 1))))));
			exprectedStructure.put("Group", Map.entry(Map.ofEntries(Map.entry("messages", "List<String>"),
																	Map.entry("account", "Account"),
																	Map.entry("accounts", "Accounts"),
																	Map.entry("members", "List<String>")),
													  Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									Map.entry(List.of(),
																									1))),
																	Map.entry("getMessages", Map.entry("List<String>", 
																									   Map.entry(List.of(),
																									   1))),
																	Map.entry("getMember", Map.entry("String", 
																									 Map.entry(List.of("int"),
																									 1))),
																	Map.entry("getMembers", Map.entry("List<String>", 
																									  Map.entry(List.of(),
																									  1))),
																	Map.entry("postMessage", Map.entry("void", 
																									   Map.entry(List.of("String","String"),
																									   2))),
																	Map.entry("addGroupMember", Map.entry("void", 
																										  Map.entry(List.of("String","String"),
																										  1))),
																	Map.entry("Group", Map.entry("void", 
																								 Map.entry(List.of("List<String>","Accounts","List<String>"),
																								 3))))));
			exprectedStructure.put("Account", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("getNotifications", Map.entry("Map<String, Boolean>", 
																											  Map.entry(List.of(),
																											  1))),
																	  Map.entry("updateNotificationsFromMessages", Map.entry("void", 
																															 Map.entry(List.of("String","String","int","List<String>","String"),
																															 1))),
																	  Map.entry("hasRead", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))),
																	  Map.entry("Account", Map.entry("void", 
																									 Map.entry(List.of("Map<String, Boolean>"),
																									 1))))));
			exprectedStructure.put("Groups", Map.entry(Map.ofEntries(Map.entry("value", "Map<String, Group>"),
																	 Map.entry("accounts", "Accounts")),
													   Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Group>", 
																									 Map.entry(List.of(),
																									 1))),
																	 Map.entry("getGroup", Map.entry("Group", 
																									 Map.entry(List.of("String"),
																									 1))),
																	 Map.entry("createGroup", Map.entry("void", 
																										Map.entry(List.of("String"),
																										1))),
																	 Map.entry("Groups", Map.entry("void", 
																								   Map.entry(List.of("Accounts"),
																								   1))))));

			checkStructure(generatedCode, exprectedStructure);			
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	private void testInventoryManagement() {
		try {
			ArrayList<CompilationUnit> generatedCode = generateCode("models/InventoryManagement.model", null);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   1))),
																   Map.entry("getInventoryElement", Map.entry("Map<String, Object>", 
																											  Map.entry(List.of("String"),
																											  1))),
																   Map.entry("getInventory", Map.entry("Map<String, InventoryElement>", 
																									   Map.entry(List.of(),
																									   1))),
																   Map.entry("registerItem", Map.entry("void", 
																									   Map.entry(List.of("String","int","String"),
																									   1))),
																   Map.entry("getCount", Map.entry("int", 
																								   Map.entry(List.of("String"),
																								   1))),
																   Map.entry("receiveOrShip", Map.entry("void", 
																										Map.entry(List.of("String","int"),
																										1))))));
			exprectedStructure.put("InventoryElement", Map.entry(Map.ofEntries(),
																 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																											   Map.entry(List.of(),
																											   1))),
																			   Map.entry("getCount", Map.entry("int", 
																											   Map.entry(List.of(),
																											   1))),
																			   Map.entry("receiveOrShip", Map.entry("void", 
																													Map.entry(List.of("String","int"),
																													1))),
																			   Map.entry("InventoryElement", Map.entry("void", 
																													   Map.entry(List.of("int"),
																													   1))))));
			exprectedStructure.put("Inventory", Map.entry(Map.ofEntries(),
														  Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, InventoryElement>", 
																										Map.entry(List.of(),
																										1))),
																		Map.entry("getInventoryElement", Map.entry("InventoryElement", 
																												   Map.entry(List.of("String"),
																												   1))),
																		Map.entry("registerItem", Map.entry("void", 
																											Map.entry(List.of("String","int","String"),
																											1))))));
			
			checkStructure(generatedCode, exprectedStructure);						
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	private void testOnlineBattleGame() {
		try {
			// check PULL-first
			ArrayList<CompilationUnit> generatedCode = generateCode("models/OnlineBattleGame.model", PushPullValue.PULL);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("accounts", "Accounts"),
																   Map.entry("rooms", "Rooms")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   2))),
																   Map.entry("getRoom", Map.entry("Map<String, Object>", 
																								  Map.entry(List.of("String"),
																								  1))),
																   Map.entry("getName", Map.entry("String", 
																								  Map.entry(List.of("String"),
																								  1))),
																   Map.entry("changeName", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))),
																   Map.entry("getAccount", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("getBlue_id", Map.entry("String", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("changeBlueId", Map.entry("void", 
																									   Map.entry(List.of("String","String"),
																									   1))),
																   Map.entry("getRed_id", Map.entry("String", 
																									Map.entry(List.of("String"),
																									1))),
																   Map.entry("changeRedId", Map.entry("void", 
																									  Map.entry(List.of("String","String"),
																									  1))),
																   Map.entry("getAccounts", Map.entry("Map<String, Account>", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("signUp", Map.entry("void", 
																								 Map.entry(List.of("String","String"),
																								 1))),
																   Map.entry("getRooms", Map.entry("Map<String, Room>", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("createRoom", Map.entry("void", 
																									 Map.entry(List.of("String","String","String"),
																									 1))),
																   Map.entry("getRed_name", Map.entry("String", 
																									  Map.entry(List.of("String"),
																									  1))),
																   Map.entry("getBlue_name", Map.entry("String", 
																									   Map.entry(List.of("String"),
																									   1))))));
			exprectedStructure.put("Room", Map.entry(Map.ofEntries(Map.entry("blue_id", "String"),
																   Map.entry("red_id", "String"),
																   Map.entry("account", "Account"),
																   Map.entry("accounts", "Accounts")),
													 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("getBlue_id", Map.entry("String", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("getRed_id", Map.entry("String", 
																									Map.entry(List.of(),
																									1))),
																   Map.entry("getRed_name", Map.entry("String", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("getBlue_name", Map.entry("String", 
																									   Map.entry(List.of(),
																									   1))),
																   Map.entry("changeRedId", Map.entry("void", 
																									  Map.entry(List.of("String","String"),
																									  2))),
																   Map.entry("changeBlueId", Map.entry("void", 
																									   Map.entry(List.of("String","String"),
																									   2))),
																   Map.entry("Room", Map.entry("void", 
																							   Map.entry(List.of("String","String","Accounts"),
																							   5))))));
			exprectedStructure.put("Account", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("getName", Map.entry("String", 
																									 Map.entry(List.of(),
																									 1))),
																	  Map.entry("changeName", Map.entry("void", 
																										Map.entry(List.of("String","String"),
																										1))),
																	  Map.entry("Account", Map.entry("void", 
																									 Map.entry(List.of("String"),
																									 1))))));
			exprectedStructure.put("Accounts", Map.entry(Map.ofEntries(),
														 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Account>", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("getAccount", Map.entry("Account", 
																										 Map.entry(List.of("String"),
																										 1))),
																	   Map.entry("signUp", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))))));
			exprectedStructure.put("Rooms", Map.entry(Map.ofEntries(Map.entry("value", "Map<String, Room>"),
																	Map.entry("accounts", "Accounts")),
													  Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Room>", 
																									Map.entry(List.of(),
																									1))),
																	Map.entry("getRoom", Map.entry("Room", 
																								   Map.entry(List.of("String"),
																								   1))),
																	Map.entry("createRoom", Map.entry("void", 
																									  Map.entry(List.of("String","String","String"),
																									  1))),
																	Map.entry("Rooms", Map.entry("void", 
																								 Map.entry(List.of("Accounts"),
																								 1))))));
			
			checkStructure(generatedCode, exprectedStructure);
//			generateCheckCode(generatedCode);
			
			// check PUSH-first
			generatedCode = generateCode("models/OnlineBattleGame.model", PushPullValue.PUSH);
			exprectedStructure.clear();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("accounts", "Accounts"),
																   Map.entry("rooms", "Rooms")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   2))),
																   Map.entry("getAccount", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("getBlue_name", Map.entry("String", 
																									   Map.entry(List.of("String"),
																									   1))),
																   Map.entry("getBlue_id", Map.entry("String", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("changeBlueId", Map.entry("void", 
																									   Map.entry(List.of("String","String"),
																									   1))),
																   Map.entry("getRed_name", Map.entry("String", 
																									  Map.entry(List.of("String"),
																									  1))),
																   Map.entry("getRed_id", Map.entry("String", 
																									Map.entry(List.of("String"),
																									1))),
																   Map.entry("changeRedId", Map.entry("void", 
																									  Map.entry(List.of("String","String"),
																									  1))),
																   Map.entry("getName", Map.entry("String", 
																								  Map.entry(List.of("String"),
																								  1))),
																   Map.entry("changeName", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))),
																   Map.entry("getAccounts", Map.entry("Map<String, Account>", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("signUp", Map.entry("void", 
																								 Map.entry(List.of("String","String"),
																								 1))),
																   Map.entry("getRooms", Map.entry("Map<String, Room>", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("createRoom", Map.entry("void", 
																									 Map.entry(List.of("String","String","String"),
																									 1))),
																   Map.entry("getRoom", Map.entry("Map<String, Object>", 
																								  Map.entry(List.of("String"),
																								  1))))));
			exprectedStructure.put("Account", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("getName", Map.entry("String", 
																									 Map.entry(List.of(),
																									 1))),
																	  Map.entry("changeName", Map.entry("void", 
																										Map.entry(List.of("String","String"),
																										1))),
																	  Map.entry("Account", Map.entry("void", 
																									 Map.entry(List.of("String"),
																									 1))))));
			exprectedStructure.put("Accounts", Map.entry(Map.ofEntries(),
														 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Account>", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("getAccount", Map.entry("Account", 
																										 Map.entry(List.of("String"),
																										 1))),
																	   Map.entry("signUp", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))))));
			exprectedStructure.put("Rooms", Map.entry(Map.ofEntries(Map.entry("value", "Map<String, Room>"),
																	Map.entry("accounts", "Accounts")),
													  Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Room>", 
																									Map.entry(List.of(),
																									1))),
																	Map.entry("getRoom", Map.entry("Room", 
																								   Map.entry(List.of("String"),
																								   1))),
																	Map.entry("createRoom", Map.entry("void", 
																									  Map.entry(List.of("String","String","String"),
																									  1))),
																	Map.entry("Rooms", Map.entry("void", 
																								 Map.entry(List.of("Accounts"),
																								 1))))));
			exprectedStructure.put("Room", Map.entry(Map.ofEntries(Map.entry("account", "Account"),
																   Map.entry("accounts", "Accounts"),
																   Map.entry("blue_id", "String"),
																   Map.entry("red_id", "String")),
													 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("getBlue_name", Map.entry("String", 
																									   Map.entry(List.of(),
																									   1))),
																   Map.entry("getBlue_id", Map.entry("String", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("getRed_name", Map.entry("String", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("getRed_id", Map.entry("String", 
																									Map.entry(List.of(),
																									1))),
																   Map.entry("updateBlue_nameFromBlue_id", Map.entry("void", 
																													 Map.entry(List.of("String","String","String"),
																													 2))),
																   Map.entry("updateRed_nameFromRed_id", Map.entry("void", 
																												   Map.entry(List.of("String","String","String"),
																												   2))),
																   Map.entry("changeRedId", Map.entry("void", 
																									  Map.entry(List.of("String","String"),
																									  3))),
																   Map.entry("changeBlueId", Map.entry("void", 
																									   Map.entry(List.of("String","String"),
																									   3))),
																   Map.entry("Room", Map.entry("void", 
																							   Map.entry(List.of("Accounts","String","String"),
																							   5))))));
			
			checkStructure(generatedCode, exprectedStructure);			
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	
	private void testOnlineBattleGame2() {
		try {
			ArrayList<CompilationUnit> generatedCode = generateCode("models/OnlineBattleGame2.model", null);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("accounts", "Accounts"),
																   Map.entry("rooms", "Rooms")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   2))),
																   Map.entry("getAccount", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("getMember", Map.entry("Map<String, Object>", 
																									Map.entry(List.of("String","int"),
																									1))),
																   Map.entry("getMembers", Map.entry("List<Member>", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("addRoomMember", Map.entry("void", 
																										Map.entry(List.of("String","String"),
																										1))),
																   Map.entry("getAccounts", Map.entry("Map<String, Account>", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("signUp", Map.entry("void", 
																								 Map.entry(List.of("String","String"),
																								 1))),
																   Map.entry("getRoom", Map.entry("Map<String, Object>", 
																								  Map.entry(List.of("String"),
																								  1))),
																   Map.entry("getId", Map.entry("String", 
																								Map.entry(List.of("String","int"),
																								1))),
																   Map.entry("getName", Map.entry("String", 
																								  Map.entry(List.of("String"),
																								  1))),
																   Map.entry("changeName", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))),
																   Map.entry("getRooms", Map.entry("Map<String, Room>", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("createRoom", Map.entry("void", 
																									 Map.entry(List.of("String"),
																									 1))),
//																   Map.entry("getName", Map.entry("String", 
//																								  Map.entry(List.of("String","int"),
//																								  1))),
																   Map.entry("getBattle", Map.entry("boolean", 
																									Map.entry(List.of("String"),
																									1))),
																   Map.entry("battle", Map.entry("void", 
																								 Map.entry(List.of("String","boolean"),
																								 1))),
																   Map.entry("getPoint", Map.entry("int", 
																								   Map.entry(List.of("String"),
																								   1))))));
			exprectedStructure.put("Account", Map.entry(Map.ofEntries(Map.entry("name", "String"),
																	  Map.entry("point", "int")),
														Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("getName", Map.entry("String", 
																									 Map.entry(List.of(),
																									 1))),
																	  Map.entry("getPoint", Map.entry("int", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("updatePointFromBattle", Map.entry("void", 
																												   Map.entry(List.of("String","String","int","boolean","String"),
																												   1))),
																	  Map.entry("changeName", Map.entry("void", 
																										Map.entry(List.of("String","String"),
																										1))),
																	  Map.entry("Account", Map.entry("void", 
																									 Map.entry(List.of("String","int"),
																									 2))))));
			exprectedStructure.put("Member", Map.entry(Map.ofEntries(Map.entry("id", "String"),
																	 Map.entry("account", "Account"),
																	 Map.entry("accounts", "Accounts")),
													   Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of(),
																									 1))),
																	 Map.entry("getId", Map.entry("String", 
																								  Map.entry(List.of(),
																								  1))),
																	 Map.entry("getName", Map.entry("String", 
																									Map.entry(List.of(),
																									1))),
																	 Map.entry("Member", Map.entry("void", 
																								   Map.entry(List.of("String","Accounts"),
																								   2))))));
			exprectedStructure.put("Members", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("List<Member>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("getMember", Map.entry("Member", 
																									   Map.entry(List.of("int"),
																									   1))),
																	  Map.entry("addRoomMember", Map.entry("void", 
																										   Map.entry(List.of("String","String"),
																										   1))))));
			exprectedStructure.put("Accounts", Map.entry(Map.ofEntries(),
														 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Account>", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("getAccount", Map.entry("Account", 
																										 Map.entry(List.of("String"),
																										 1))),
																	   Map.entry("signUp", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))))));
			exprectedStructure.put("Room", Map.entry(Map.ofEntries(Map.entry("members", "Members"),
																   Map.entry("battle", "boolean"),
																   Map.entry("account", "Account"),
																   Map.entry("accounts", "Accounts")),
													 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("getMembers", Map.entry("Members", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("getBattle", Map.entry("boolean", 
																									Map.entry(List.of(),
																									1))),
																   Map.entry("battle", Map.entry("void", 
																								 Map.entry(List.of("String","boolean"),
																								 2))),
																   Map.entry("Room", Map.entry("void", 
																							   Map.entry(List.of("boolean","Accounts"),
																							   2))))));
			exprectedStructure.put("Rooms", Map.entry(Map.ofEntries(Map.entry("value", "Map<String, Room>"),
																	Map.entry("accounts", "Accounts")),
													  Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Room>", 
																									Map.entry(List.of(),
																									1))),
																	Map.entry("getRoom", Map.entry("Room", 
																								   Map.entry(List.of("String"),
																								   1))),
																	Map.entry("createRoom", Map.entry("void", 
																									  Map.entry(List.of("String"),
																									  1))),
																	Map.entry("Rooms", Map.entry("void", 
																								 Map.entry(List.of("Accounts"),
																								 1))))));
			
			checkStructure(generatedCode, exprectedStructure);
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	private void testPOS() {
		try {
			// check PULL-first
			ArrayList<CompilationUnit> generatedCode = generateCode("models/POS.model", PushPullValue.PULL);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("history", "History"),
																   Map.entry("total", "Total"),
																   Map.entry("payment", "Payment"),
																   Map.entry("points", "Points")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   4))),
																   Map.entry("getHistory", Map.entry("List<Integer>", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("getTotal", Map.entry("int", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("getPayment", Map.entry("int", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("purchase", Map.entry("void", 
																								   Map.entry(List.of("int"),
																								   1))),
																   Map.entry("getPoints", Map.entry("int", 
																									Map.entry(List.of(),
																									1))))));
			exprectedStructure.put("History", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("List<Integer>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("updateFromPayment", Map.entry("void", 
																											   Map.entry(List.of("int"),
																											   1))))));
			exprectedStructure.put("Total", Map.entry(Map.ofEntries(),
													  Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																									Map.entry(List.of(),
																									1))),
																	Map.entry("Total", Map.entry("void", 
																								 Map.entry(List.of("History"),
																								 1))))));
			exprectedStructure.put("Payment", Map.entry(Map.ofEntries(Map.entry("value", "int"),
																	  Map.entry("history", "History")),
														Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("purchase", Map.entry("void", 
																									  Map.entry(List.of("int"),
																									  2))),
																	  Map.entry("Payment", Map.entry("void", 
																									 Map.entry(List.of("History"),
																									 1))))));
			exprectedStructure.put("Points", Map.entry(Map.ofEntries(),
													   Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																									 Map.entry(List.of(),
																									 1))),
																	 Map.entry("Points", Map.entry("void", 
																								   Map.entry(List.of("Payment"),
																								   1))))));
			
			checkStructure(generatedCode, exprectedStructure);
//			generateCheckCode(generatedCode);
			
			// check PUSH-first
			generatedCode = generateCode("models/POS.model", PushPullValue.PUSH);
			exprectedStructure.clear();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("points", "Points"),
																   Map.entry("total", "Total"),
																   Map.entry("history", "History"),
																   Map.entry("payment", "Payment")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   4))),
																   Map.entry("getPoints", Map.entry("int", 
																									Map.entry(List.of(),
																									1))),
																   Map.entry("getTotal", Map.entry("int", 
																								   Map.entry(List.of(),
																								   1))),
																   Map.entry("getHistory", Map.entry("List<Integer>", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("getPayment", Map.entry("int", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("purchase", Map.entry("void", 
																								   Map.entry(List.of("int"),
																								   1))))));
			exprectedStructure.put("Points", Map.entry(Map.ofEntries(),
													   Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																									 Map.entry(List.of(),
																									 1))),
																	 Map.entry("updateFromPayment", Map.entry("void", 
																											  Map.entry(List.of("int"),
																											  1))))));
			exprectedStructure.put("Total", Map.entry(Map.ofEntries(),
													  Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																									Map.entry(List.of(),
																									1))),
																	Map.entry("updateFromHistory", Map.entry("void", 
																											 Map.entry(List.of("List<Integer>"),
																											 1))))));
			exprectedStructure.put("History", Map.entry(Map.ofEntries(Map.entry("value", "List<Integer>"),
																	  Map.entry("total", "Total")),
														Map.ofEntries(Map.entry("getValue", Map.entry("List<Integer>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("updateFromPayment", Map.entry("void", 
																											   Map.entry(List.of("int"),
																											   2))),
																	  Map.entry("History", Map.entry("void", 
																									 Map.entry(List.of("Total"),
																									 1))))));
			exprectedStructure.put("Payment", Map.entry(Map.ofEntries(Map.entry("value", "int"),
																	  Map.entry("points", "Points"),
																	  Map.entry("history", "History")),
														Map.ofEntries(Map.entry("getValue", Map.entry("int", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("purchase", Map.entry("void", 
																									  Map.entry(List.of("int"),
																									  3))),
																	  Map.entry("Payment", Map.entry("void", 
																									 Map.entry(List.of("Points","History"),
																									 2))))));
			
			checkStructure(generatedCode, exprectedStructure);						
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	private void testSimpleTwitter() {
		try {
			ArrayList<CompilationUnit> generatedCode = generateCode("models/SimpleTwitter.model", null);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   1))),
																   Map.entry("getAccount", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("getAccounts", Map.entry("Map<String, Account>", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("signUp", Map.entry("void", 
																								 Map.entry(List.of("String","String"),
																								 1))),
																   Map.entry("getTweets", Map.entry("List<String>", 
																									Map.entry(List.of("String"),
																									1))),
																   Map.entry("tweet", Map.entry("void", 
																								Map.entry(List.of("String","String"),
																								1))))));
			exprectedStructure.put("Account", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("getTweets", Map.entry("List<String>", 
																									   Map.entry(List.of(),
																									   1))),
																	  Map.entry("tweet", Map.entry("void", 
																								   Map.entry(List.of("String","String"),
																								   1))),
																	  Map.entry("Account", Map.entry("void", 
																									 Map.entry(List.of("List<String>"),
																									 1))))));
			exprectedStructure.put("Accounts", Map.entry(Map.ofEntries(),
														 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Account>", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("getAccount", Map.entry("Account", 
																										 Map.entry(List.of("String"),
																										 1))),
																	   Map.entry("signUp", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))))));

			checkStructure(generatedCode, exprectedStructure);
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	private void testVotingSystem() {
		try {
			ArrayList<CompilationUnit> generatedCode = generateCode("models/VotingSystem.model", null);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("accounts", "Accounts"),
																   Map.entry("counts", "Counts")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   2))),
																   Map.entry("getAccounts", Map.entry("Map<String, Account>", 
																									  Map.entry(List.of(),
																									  1))),
																   Map.entry("signUp", Map.entry("void", 
																								 Map.entry(List.of("String","String"),
																								 1))),
																   Map.entry("getVote", Map.entry("String", 
																								  Map.entry(List.of("String"),
																								  1))),
																   Map.entry("cast", Map.entry("void", 
																							   Map.entry(List.of("String","String"),
																							   1))),
																   Map.entry("getAccount", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of("String"),
																									 1))),
																   Map.entry("getCounts", Map.entry("Map<String, Object>", 
																									Map.entry(List.of(),
																									1))))));
			exprectedStructure.put("Accounts", Map.entry(Map.ofEntries(),
														 Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Account>", 
																									   Map.entry(List.of(),
																									   1))),
																	   Map.entry("getAccount", Map.entry("Account", 
																										 Map.entry(List.of("String"),
																										 1))),
																	   Map.entry("signUp", Map.entry("void", 
																									 Map.entry(List.of("String","String"),
																									 1))))));
			exprectedStructure.put("Account", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("getVote", Map.entry("String", 
																									 Map.entry(List.of(),
																									 1))),
																	  Map.entry("cast", Map.entry("void", 
																								  Map.entry(List.of("String","String"),
																								  1))),
																	  Map.entry("Account", Map.entry("void", 
																									 Map.entry(List.of("String"),
																									 1))))));
			exprectedStructure.put("Counts", Map.entry(Map.ofEntries(Map.entry("value", "Map<String, Object>"),
																	 Map.entry("account", "Account"),
																	 Map.entry("accounts", "Accounts")),
													   Map.ofEntries(Map.entry("getValue", Map.entry("Map<String, Object>", 
																									 Map.entry(List.of(),
																									 5))),
																	 Map.entry("Counts", Map.entry("void", 
																								   Map.entry(List.of("Accounts"),
																								   1))))));

			checkStructure(generatedCode, exprectedStructure);
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}
	
	private void testWeatherObservationSystem() {
		try {
			// check PULL-first
			ArrayList<CompilationUnit> generatedCode = generateCode("models/WeatherObservationSystem.model", PushPullValue.PULL);
			Map<String, 									// class name
					Entry<Map<String, String>,  			// field name to type
						  Map<String, 						// method name to			
						          Entry<String, 			// return type
						          		Entry<List<String>,	// arg types
						          			  Integer>>>>>	// lines of code
				exprectedStructure = new HashMap<>();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("highest", "Highest"),
																   Map.entry("temp_f", "Temp_f"),
																   Map.entry("temp_c", "Temp_c")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   3))),
																   Map.entry("getHighest", Map.entry("double", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("reset", Map.entry("void", 
																								Map.entry(List.of("double"),
																								1))),
																   Map.entry("getTemp_f", Map.entry("double", 
																									Map.entry(List.of(),
																									1))),
																   Map.entry("observe", Map.entry("void", 
																								  Map.entry(List.of("double"),
																								  1))),
																   Map.entry("getTemp_c", Map.entry("double", 
																									Map.entry(List.of(),
																									1))))));
			exprectedStructure.put("Highest", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("updateFromTemp_f", Map.entry("void", 
																											  Map.entry(List.of("double"),
																											  1))),
																	  Map.entry("reset", Map.entry("void", 
																								   Map.entry(List.of("double"),
																								   1))))));
			exprectedStructure.put("Temp_f", Map.entry(Map.ofEntries(Map.entry("value", "double"),
																	 Map.entry("highest", "Highest")),
													   Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									 Map.entry(List.of(),
																									 1))),
																	 Map.entry("observe", Map.entry("void", 
																									Map.entry(List.of("double"),
																									2))),
																	 Map.entry("Temp_f", Map.entry("void", 
																								   Map.entry(List.of("Highest"),
																								   1))))));
			exprectedStructure.put("Temp_c", Map.entry(Map.ofEntries(),
													   Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									 Map.entry(List.of(),
																									 1))),
																	 Map.entry("Temp_c", Map.entry("void", 
																								   Map.entry(List.of("Temp_f"),
																								   1))))));
			
			checkStructure(generatedCode, exprectedStructure);
//			generateCheckCode(generatedCode);
			
			// check PUSH-first
			generatedCode = generateCode("models/WeatherObservationSystem.model", PushPullValue.PUSH);
			exprectedStructure.clear();
			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("temp_c", "Temp_c"),
																   Map.entry("highest", "Highest"),
																   Map.entry("temp_f", "Temp_f")),
													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
																							   Map.entry(List.of(),
																							   3))),
																   Map.entry("getTemp_c", Map.entry("double", 
																									Map.entry(List.of(),
																									1))),
																   Map.entry("getHighest", Map.entry("double", 
																									 Map.entry(List.of(),
																									 1))),
																   Map.entry("reset", Map.entry("void", 
																								Map.entry(List.of("double"),
																								1))),
																   Map.entry("getTemp_f", Map.entry("double", 
																									Map.entry(List.of(),
																									1))),
																   Map.entry("observe", Map.entry("void", 
																								  Map.entry(List.of("double"),
																								  1))))));
			exprectedStructure.put("Temp_c", Map.entry(Map.ofEntries(),
													   Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									 Map.entry(List.of(),
																									 1))),
																	 Map.entry("updateFromTemp_f", Map.entry("void", 
																											 Map.entry(List.of("double"),
																											 1))))));
			exprectedStructure.put("Highest", Map.entry(Map.ofEntries(),
														Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									  Map.entry(List.of(),
																									  1))),
																	  Map.entry("updateFromTemp_f", Map.entry("void", 
																											  Map.entry(List.of("double"),
																											  1))),
																	  Map.entry("reset", Map.entry("void", 
																								   Map.entry(List.of("double"),
																								   1))))));
			exprectedStructure.put("Temp_f", Map.entry(Map.ofEntries(Map.entry("value", "double"),
																	 Map.entry("highest", "Highest"),
																	 Map.entry("temp_c", "Temp_c")),
													   Map.ofEntries(Map.entry("getValue", Map.entry("double", 
																									 Map.entry(List.of(),
																									 1))),
																	 Map.entry("observe", Map.entry("void", 
																									Map.entry(List.of("double"),
																									3))),
																	 Map.entry("Temp_f", Map.entry("void", 
																								   Map.entry(List.of("Highest","Temp_c"),
																								   2))))));
			
			checkStructure(generatedCode, exprectedStructure);			
//			generateCheckCode(generatedCode);
		} catch (FileNotFoundException 
				| ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword
				| ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression
				| WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket 
				| WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
			e.printStackTrace();
		}
	}

	private ArrayList<CompilationUnit> generateCode(String fileName, PushPullValue pushPullValue) throws FileNotFoundException, 
					ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedRightCurlyBracket, ExpectedInOrOutOrRefOrSubKeyword, 
					ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment, 
					WrongPathExpression, WrongJsonExpression, ExpectedColon, ExpectedDoubleQuotation {
		File file = new File(fileName);
		Parser parser = new Parser(new BufferedReader(new FileReader(file)));
		DataTransferModel model;
		model = parser.doParse();
		DataFlowGraph graph = DataTransferModelAnalyzer.createDataFlowGraphWithStateStoringAttribute(model);
		DataTransferModelAnalyzer.annotateWithSelectableDataTransferAttiribute(graph);
		if (pushPullValue != null) {
			// Select a specified push/pull transfer method if possible.
			for (Edge e : graph.getEdges()) {
				if (!((DataFlowEdge) e).isChannelToResource() && ((DataFlowEdge) e).getAttribute() instanceof PushPullAttribute) {
					PushPullAttribute ppat = (PushPullAttribute) ((DataFlowEdge) e).getAttribute();
					ppat.selectOption(pushPullValue);
				}
			}
		}
		TypeInference typeInference = new TypeInference(new JavaSpecific());
		typeInference.infer(model);
		DataTransferMethodAnalyzer.decideToStoreResourceStates(graph);
//		ArrayList<CompilationUnit> codetree = JavaMethodBodyGenerator.doGenerate(graph, model, JavaCodeGenerator.doGenerate(graph, model));
		CodeGenerator codeGenerator = new CodeGeneratorFromDataFlowGraph(new StandaloneSpecific(), new JavaSpecific());
		ArrayList<CompilationUnit> codetree = codeGenerator.generateCode(model, graph);
		return codetree;
	}

	private void checkStructure(ArrayList<CompilationUnit> generatedCode,
			Map<String, Entry<Map<String, String>, Map<String, Entry<String, Entry<List<String>, Integer>>>>> exprectedStructure) {
		for (var classEnt: exprectedStructure.entrySet()) {
			String expectedClassName = classEnt.getKey();
			Entry<Map<String, String>, Map<String, Entry<String, Entry<List<String>, Integer>>>> expectedClassStructure = classEnt.getValue();
			TypeDeclaration generatedClass = null; 
			for (CompilationUnit cu: generatedCode) {
				for (TypeDeclaration type: cu.types()) {
					if (type.getTypeName().equals(expectedClassName)) {
						generatedClass = type;
						break;
					}
				}
			}
			assertNotNull(generatedClass);
			
			Map<String, String> exprectedFields = expectedClassStructure.getKey();
			Map<String, Entry<String, Entry<List<String>, Integer>>> exprectedMethods = expectedClassStructure.getValue();
			
			for (String expectedFieldName: exprectedFields.keySet()) {
				FieldDeclaration generatedField = null;
				for (FieldDeclaration field: generatedClass.getFields()) {
					if (field.getName().equals(expectedFieldName)) {
						generatedField = field;
						break;
					}
				}
				assertNotNull(generatedField);
				
				String expectedFieldType = exprectedFields.get(expectedFieldName);
				if (expectedFieldType.equals("void")) {
					assertNull(generatedField.getType());
				} else {
					assertEquals(expectedFieldType, generatedField.getType().getInterfaceTypeName());
				}
			}
			
			for (String expectedMethodName: exprectedMethods.keySet()) {
				MethodDeclaration generatedMethod= null;
				for (MethodDeclaration method: generatedClass.getMethods()) {
					if (method.getName().equals(expectedMethodName)) {
						generatedMethod = method;
						break;
					}
				}
				assertNotNull(generatedMethod);
				
				Entry<String, Entry<List<String>, Integer>> expectedMethodInfo = exprectedMethods.get(expectedMethodName);
				String expectedReturnType = expectedMethodInfo.getKey();
				if (expectedReturnType.equals("void")) {
					if (generatedMethod.getReturnType() != null) {
						assertEquals(expectedReturnType, generatedMethod.getReturnType().getInterfaceTypeName());
					} else {
						assertNull(generatedMethod.getReturnType());
					}
				} else {
					assertEquals(expectedReturnType, generatedMethod.getReturnType().getInterfaceTypeName());
				}
				Entry<List<String>, Integer> expectedMethodInfo2 = expectedMethodInfo.getValue();
				List<String> expectedArgTypes = expectedMethodInfo2.getKey();
				for (String expectedArgType: expectedArgTypes) {
					boolean existsArg = false;
					for (VariableDeclaration var: generatedMethod.getParameters()) {
						if (expectedArgType.equals(var.getType().getInterfaceTypeName())) {
							existsArg = true;
						}
					}
					assertTrue(existsArg);
				}
				int expectedLinesOfCode = expectedMethodInfo2.getValue();
				assertEquals(expectedLinesOfCode, generatedMethod.getBody().getStatements().size());
			}
		}
	}

	private void generateCheckCode(ArrayList<CompilationUnit> generatedCode) {
//			exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("history", "History"),
//																   Map.entry("total", "Total"),
//																   Map.entry("payment", "Payment"),
//																   Map.entry("points", "Points")), 
//													 Map.ofEntries(Map.entry("Main", Map.entry("void", 
//																							   Map.entry(List.of(), 
//																							   4))),
//																   Map.entry("getHistory", Map.entry("List",
//																									 Map.entry(List.of(),
//																									 1))),
//																   Map.entry("getTotal", Map.entry("int",
//																									Map.entry(List.of(),
//																									1))),
//																   Map.entry("getPayment", Map.entry("int",
//																									 Map.entry(List.of(),
//																									 1))),
//																   Map.entry("purchase", Map.entry("void",
//																								   Map.entry(List.of("int"),
//																								   1))),
//																   Map.entry("getPoints", Map.entry("int",
//																								    Map.entry(List.of(),
//																									1))))));
		for (CompilationUnit cu: generatedCode) {
			for (TypeDeclaration type: cu.types()) {
				List<FieldDeclaration> fields = type.getFields();
				List<MethodDeclaration> methods = type.getMethods();
				// fields
				if (fields.size() == 0) {
					System.out.println("\t\t\texprectedStructure.put(\"" + type.getTypeName() + "\", Map.entry(Map.ofEntries(),");
				} if (fields.size() == 1) {
					System.out.println("\t\t\texprectedStructure.put(\"" + type.getTypeName() + "\", Map.entry(Map.ofEntries(),");
				} else {
					int i = 0;
					for (FieldDeclaration field: fields) {
						if (i == 0) {
							System.out.println("\t\t\texprectedStructure.put(\"" + type.getTypeName() + "\", Map.entry(Map.ofEntries(Map.entry(\"" + field.getName() + "\", \"" + field.getType().getInterfaceTypeName() + "\"),");
						} else {
							System.out.print("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
							for (int j = 0; j < (type.getTypeName().length() + 3) / 4; j++) {
								System.out.print("\t");
							}
							for (int j = 0; j < (type.getTypeName().length() + 3) % 4; j++) {
								System.out.print(" ");
							}
							if (i < fields.size() - 1) {
								System.out.println("Map.entry(\"" + field.getName() + "\", \"" + field.getType().getInterfaceTypeName() + "\"),");
							} else {
								System.out.println("Map.entry(\"" + field.getName() + "\", \"" + field.getType().getInterfaceTypeName() + "\")),");
							}
						}
						i++;
					}
				}
				// methods
				if (methods.size() == 0) {
					System.out.print("\t\t\t\t\t\t\t\t\t\t\t\t");
					for (int j = 0; j < (type.getTypeName().length() + 1) / 4; j++) {
						System.out.print("\t");
					}
					for (int j = 0; j < (type.getTypeName().length() + 1) % 4; j++) {
						System.out.print(" ");
					}
					System.out.println("Map.ofEntries())));");
				} else {
					int i = 0;
					for (MethodDeclaration method: methods) {
						// method name and return type
						if (i == 0) {
							System.out.print("\t\t\t\t\t\t\t\t\t\t\t\t");
							for (int j = 0; j < (type.getTypeName().length() + 1) / 4; j++) {
								System.out.print("\t");
							}
							for (int j = 0; j < (type.getTypeName().length() + 1) % 4; j++) {
								System.out.print(" ");
							}
							if (method.getReturnType() == null) {
								System.out.println("Map.ofEntries(Map.entry(\"" + method.getName() + "\", Map.entry(\"void\", ");
							} else {
								System.out.println("Map.ofEntries(Map.entry(\"" + method.getName() + "\", Map.entry(\"" + method.getReturnType().getInterfaceTypeName() + "\", ");
							}
						} else {
							System.out.print("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
							for (int j = 0; j < (type.getTypeName().length() + 3) / 4; j++) {
								System.out.print("\t");
							}
							for (int j = 0; j < (type.getTypeName().length() + 3) % 4; j++) {
								System.out.print(" ");
							}
							if (method.getReturnType() == null) {
								System.out.println("Map.entry(\"" + method.getName() + "\", Map.entry(\"void\", ");
							} else {
								System.out.println("Map.entry(\"" + method.getName() + "\", Map.entry(\"" + method.getReturnType().getInterfaceTypeName() + "\", ");
							}
						}
						// method parameters
						System.out.print("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
						for (int j = 0; j < (type.getTypeName().length() + method.getName().length() + 3) / 4; j++) {
							System.out.print("\t");
						}
						for (int j = 0; j < (type.getTypeName().length() + method.getName().length() + 3) % 4; j++) {
							System.out.print(" ");
						}
						if (method.getParameters() == null || method.getParameters().size() == 0) {
							System.out.println("Map.entry(List.of(),");
						} else {
							System.out.print("Map.entry(List.of(");
							String delim = "";
							for (VariableDeclaration arg: method.getParameters()) {
								System.out.print(delim + "\"" + arg.getType().getInterfaceTypeName() + "\"");
								delim = ",";
							}
							System.out.println("),");
						}
						// method lines of code
						System.out.print("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
						for (int j = 0; j < (type.getTypeName().length() + method.getName().length() + 3) / 4; j++) {
							System.out.print("\t");
						}
						for (int j = 0; j < (type.getTypeName().length() + method.getName().length() + 3) % 4; j++) {
							System.out.print(" ");
						}
						if (i < methods.size() - 1) {
							System.out.println("" + method.getBody().getStatements().size() + "))),");
						} else {
							System.out.println("" + method.getBody().getStatements().size() + "))))));");
						}
						i++;
					}
				}
			}
		}
	}
}