/*
 * @(#)AgentTest.java   01/12/2007
 *
 * Copyright 2007 GigaSpaces Technologies Inc.
 */

package org.deuce.test.agent;

import java.lang.reflect.Method;

import org.deuce.transaction.tl2.Context;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 * TODO	add Javadoc
 *
 * @author	Guy
 * @version	1.0
 * @since	5.0
 */
public class AgentTest
{

	@Test
	public void createMethod()
	{
		try
		{
//			MyClassLoader cl = new MyClassLoader();
//			Class c = Class.forName(className)( .getName());
			assertNotNull( CCC.class.getMethod("foo", Integer.TYPE, String.class));
			assertNotNull( CCC.class.getMethod("foo__jstm", Integer.TYPE, String.class));
		}
		catch( Exception e)
		{
			throw new RuntimeException( e);
		}
	}

	@Test
	public void createConstructor()
	{
		try
		{
//			MyClassLoader cl = new MyClassLoader();
//			Class c = cl.findClass( CCC.class.getName());
			assertNotNull( CCC.class.getConstructor());
			assertNotNull( CCC.class.getConstructor( Context.class));
		}
		catch( Exception e)
		{
			throw new RuntimeException( e);
		}
	}

	@Test
	public void createMethodWithCode()
	{
		try
		{
//			MyClassLoader cl = new MyClassLoader();
//			Class c = cl.findClass( CCC.class.getName());
			Method m = CCC.class.getMethod("foo__jstm", new Class[] { Integer.TYPE, String.class});
			assertEquals( m.invoke(new CCC(), 4, "AAA"), "AAA"+4);
		}
		catch( Exception e)
		{
			throw new RuntimeException( e);
		}
	}

	public static class CCC
	{
		public CCC()
		{

		}

		public String foo(int x, String y)
		{
			return y + x;
		}

		public String foo2(int x, String y)
		{
			return y + x;
		}
	}

//	public static class MyClassLoader extends ClassLoader {
//
//		@Override
//		protected Class findClass(String name) throws ClassNotFoundException {
//			ClassReader cr;
//			try
//			{
//				cr = new ClassReader(name);
//			}
//			catch (IOException e)
//			{
//				throw new ClassNotFoundException( e.toString() ,e);
//			}
//			ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
//			ClassVisitor cv = new Adapter(cw);
//			cr.accept(cv, 0);
//			byte[] b = cw.toByteArray();
//			return defineClass(name, b, 0, b.length);
//		}
//	}

}

@@ -157,24 +157,71 @@
 .Method;%0D%0A%0D%0A
+import org.deuce.transaction.AbstractContext;%0D%0A
 import org.d
@@ -324,24 +324,74 @@
 %0A * 
-TODO%09add Javadoc
+Check that duplicate methods are created with the right signutre. 
 %0D%0A *
@@ -410,25 +410,16 @@
 %09Guy
-%0D%0A * @version%091.0
+ Korland
 %0D%0A *
@@ -430,11 +430,11 @@
 nce%09
-5.0
+0.3
 %0D%0A *
@@ -522,109 +522,8 @@
 %09%7B%0D%0A
-//%09%09%09MyClassLoader cl = new MyClassLoader();%0D%0A//%09%09%09Class c = Class.forName(className)( .getName());%0D%0A
 %09%09%09a
@@ -636,22 +636,16 @@
 hod(%22foo
-__jstm
 %22, Integ
@@ -661,24 +661,47 @@
 String.class
+, AbstractContext.class
 ));%0D%0A%09%09%7D%0D%0A%09%09
@@ -835,106 +835,8 @@
 %09%7B%0D%0A
-//%09%09%09MyClassLoader cl = new MyClassLoader();%0D%0A//%09%09%09Class c = cl.findClass( CCC.class.getName());%0D%0A
 %09%09%09a
@@ -923,16 +923,24 @@
 ructor( 
+Abstract
 Context.
@@ -1094,106 +1094,8 @@
 %09%7B%0D%0A
-//%09%09%09MyClassLoader cl = new MyClassLoader();%0D%0A//%09%09%09Class c = cl.findClass( CCC.class.getName());%0D%0A
 %09%09%09M
@@ -1132,30 +1132,10 @@
 %22foo
-__jstm%22, new Class%5B%5D %7B
+%22,
  Int
@@ -1157,17 +1157,39 @@
 ng.class
-%7D
+, AbstractContext.class
 );%0D%0A%09%09%09a
@@ -1229,16 +1229,31 @@
 4, %22AAA%22
+, new Context()
 ), %22AAA%22
@@ -1541,581 +1541,7 @@
 %09%7D%0D%0A
-%0D%0A//%09public static class MyClassLoader extends ClassLoader %7B%0D%0A//%0D%0A//%09%09@Override%0D%0A//%09%09protected Class findClass(String name) throws ClassNotFoundException %7B%0D%0A//%09%09%09ClassReader cr;%0D%0A//%09%09%09try%0D%0A//%09%09%09%7B%0D%0A//%09%09%09%09cr = new ClassReader(name);%0D%0A//%09%09%09%7D%0D%0A//%09%09%09catch (IOException e)%0D%0A//%09%09%09%7B%0D%0A//%09%09%09%09throw new ClassNotFoundException( e.toString() ,e);%0D%0A//%09%09%09%7D%0D%0A//%09%09%09ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);%0D%0A//%09%09%09ClassVisitor cv = new Adapter(cw);%0D%0A//%09%09%09cr.accept(cv, 0);%0D%0A//%09%09%09byte%5B%5D b = cw.toByteArray();%0D%0A//%09%09%09return defineClass(name, b, 0, b.length);%0D%0A//%09%09%7D%0D%0A//%09%7D%0D%0A%0D%0A
 %7D%0D%0A

Fix JUnit test