package com.hohai.juncao;

import java.util.Properties;

import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class HelloClientStdTest {

	static String serverIiopPort = System.getProperty("serverIiop");

	SendingSessionStdLocal callingBean;
	private String sendingname = "New Data";

	public void setUp() throws Exception {
       try {
    	    Properties props = new Properties();
    	    props.setProperty("java.naming.factory.initial", 
    	                             "com.sun.enterprise.naming.SerialInitContextFactory");
    	    props.setProperty("java.naming.factory.url.pkgs", 
    	                             "com.sun.enterprise.naming");
    	    props.setProperty("java.naming.factory.state",
    	                             "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
    	    props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    	    props.setProperty("org.omg.CORBA.ORBInitialPort", serverIiopPort);

			InitialContext ctx = new InitialContext(props);
			Object o = ctx.lookup(SendingSessionStdHome.class.getName());
			SendingSessionStdHome callingBeanHome = (SendingSessionStdHome)
									PortableRemoteObject.narrow(o, SendingSessionStdHome.class);
			for (int i=0;i<10; i++)
			{
				callingBean = callingBeanHome.create();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void testHello(){
		
		try{   
		   TranEntityStd data = new TranEntityStd();   
		   callingBean.createEntity();
		   data = callingBean.updateEntityWithSleep(sendingname);
		   try {
				Thread.sleep(70000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		   callingBean.mergeEntity(data);
		   data = callingBean.getEntity();
		   System.out.println(data.getName());
		   System.out.println("Test Completed!");
		}catch (Exception e){
		}
	}
}
