package com.perpetumobile.bit.orm.json;

import java.io.File;

import junit.framework.TestCase;
import junit.framework.TestSuite;


public class JSONParserManagerTest extends TestCase {
	
	public static TestSuite suite() {
		TestSuite suite = new TestSuite();
		suite.addTest(new JSONParserManagerTest("test1"));
		suite.addTest(new JSONParserManagerTest("test2"));
		return suite;
	}
	
	public JSONParserManagerTest() {
	}
	
	public JSONParserManagerTest(String testName) {
		super(testName);
	}
	
	protected void setUp() {
	}
	
	protected void tearDown() {
	}
	
	public void test1() {
		System.out.println("####################################");
		System.out.println("JSONParserManager Test 1");
		System.out.println("####################################");
		try {
			JSONRecord result = JSONParserManager.getInstance().parseImpl(new File("data/json/sample_1.txt"), "JSONSample1");
			StringBuilder buf = result.generateJSON(true);
			System.out.println(buf.toString());
		} catch (Exception e) {
			fail("Exception at JSONParserManagerTest.test1: " + e.getLocalizedMessage());
		}
	}
	
	public void test2() {
		System.out.println("####################################");
		System.out.println("JSONParserManager Test 2");
		System.out.println("####################################");
		try {
			JSONRecord result = JSONParserManager.getInstance().parseImpl(new File("data/json/sample_2.txt"), "JSONSample2");
			StringBuilder buf = result.generateJSON(true);
			System.out.println(buf.toString());
		} catch (Exception e) {
			fail("Exception at JSONParserManagerTest.test2: " + e.getLocalizedMessage());
		}
	}
}

@@ -54,16 +54,150 @@
 io.File;
+%0Aimport java.io.FileInputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.io.ObjectInputStream;%0Aimport java.io.ObjectOutputStream;
 %0A%0Aimport
@@ -315,16 +315,81 @@
 ase %7B%0A%09%0A
+%09public static final String JSON_DATA_FILE_NAME = %22json.data%22;%0A%09%0A
 %09public 
@@ -747,24 +747,799 @@
 earDown() %7B%0A
+%09%09File file = new File(JSON_DATA_FILE_NAME);%0A%09%09if(file.exists()) %7B%0A%09%09%09file.delete();%0A%09%09%7D%0A%09%7D%0A%09%0A%09protected void write(JSONRecord rec, String fileName) %7B%0A%09%09try %7B%09%09%09%0A%09%09%09ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(fileName, false));%0A%09%09%09out.writeObject(rec);%0A%09%09%09out.flush();%0A%09%09%09out.close();%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09fail(%22Exception at JSONParserManagerTest.write: %22 + e.getLocalizedMessage());%0A%09%09%7D%0A%09%7D%0A%09%0A%09protected JSONRecord read(String fileName) %7B%0A%09%09JSONRecord result = null;%0A%09%09try %7B%09%09%09%0A%09%09%09ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));%0A%09%09%09result = (JSONRecord)in.readObject();%0A%09%09%09in.close();%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09fail(%22Exception at JSONParserManagerTest.write: %22 + e.getLocalizedMessage());%0A%09%09%7D%0A%09%09return result;%0A
 %09%7D%0A%09%0A%09public
@@ -1907,34 +1907,244 @@
 e);%0A%09%09%09S
-ystem.out.println(
+tring jsonStr = buf.toString();%0A%09%09%09System.out.println(jsonStr);%0A%09%09%09// test serialization%0A%09%09%09write(result, JSON_DATA_FILE_NAME);%0A%09%09%09result = read(JSON_DATA_FILE_NAME);%0A%09%09%09buf = result.generateJSON(true);%0A%09%09%09assertEquals(jsonStr, 
 buf.toSt
@@ -2644,34 +2644,244 @@
 e);%0A%09%09%09S
-ystem.out.println(
+tring jsonStr = buf.toString();%0A%09%09%09System.out.println(jsonStr);%0A%09%09%09// test serialization%0A%09%09%09write(result, JSON_DATA_FILE_NAME);%0A%09%09%09result = read(JSON_DATA_FILE_NAME);%0A%09%09%09buf = result.generateJSON(true);%0A%09%09%09assertEquals(jsonStr, 
 buf.toSt

test serialization