package com.redknee.ib.PrepaidAccount_CORBAService; import org.omg.CORBA.LongHolder; import org.omg.CORBA.ORB; import org.omg.CosNaming.NamingContextExt; import org.omg.CosNaming.NamingContextExtHelper; import corba.param.Parameter; import corba.param.ParameterSetHolder; import corba.param.ParameterValue; import corba.v01.CorbaService; import corba.v01.UserAuth; import corba.v01.UserAuthHelper; public class CorbaServiceTest { private static CorbaService ppa = null; static Parameter[] pArray1 = new Parameter[3]; static Parameter p1,p2,p3; org.omg.CORBA.StringHolder stringValue = new org.omg.CORBA.StringHolder(); org.omg.CORBA.LongHolder longValue = new org.omg.CORBA.LongHolder(); org.omg.CORBA.LongHolder shortfall = new org.omg.CORBA.LongHolder(); ParameterSetHolder outputParamSet = new ParameterSetHolder(); org.omg.CORBA.LongHolder newBal = new LongHolder(); long amount; short extension; String msisdn; static UserAuth helloImpl=null; @BeforeClass public static void beforePrepaidAccountServiceImplTest() { try{ String args[] = {"-ORBInitialHost","localhost","-ORBInitialPort","20000"}; //String args[] = {"-ORBInitialHost","10.58.156.237","-ORBInitialPort","2061"}; System.out.println("Hit Main class"); // create and initialize the ORB ORB orb = ORB.init(args, null); // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt instead of NamingContext. This is // part of the Interoperable naming Service. NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // resolve the Object Reference in Naming String name = "CorbaServiceUserAuth"; helloImpl = UserAuthHelper.narrow(ncRef.resolve_str(name)); System.out.println("Obtained a handle on server object: " + helloImpl); short version = 10; ppa = helloImpl.loginUser("test","test",version); short parameterID1 = 100; ParameterValue pV1 = new ParameterValue(); pV1.intValue(1); p1 = new Parameter(parameterID1, pV1); pArray1[0] = p1; short parameterID2 = 101; ParameterValue pV2 = new ParameterValue(); pV2.intValue(200); p2 = new Parameter(parameterID2, pV2); pArray1[1] = p2; short parameterID3 = 103; ParameterValue pV3 = new ParameterValue(); pV3.intValue(1000); p3 = new Parameter(parameterID3, pV3); pArray1[2] = p3; } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } } @Test public void testEmployee() { //success amount = 10; extension = 50; System.out.println("\nTESTING .............. requestDebit()"); ppa.employee("100", 1l, "test", true, pArray1, "erReference", longValue, longValue, outputParamSet); long value = longValue.value; System.out.println("\nvalue" + value + "amount " + amount); assertEquals("Success scenario- Expected return = 0",0,ppa.employee("100", 1l, "test", true, pArray1, "erReference", longValue, longValue, outputParamSet)); assertEquals("New Balance = oldBalance-amount",(longValue.value-amount),longValue.value); assertEquals("Shortfall = amount-oldBalance",(amount-longValue.value),shortfall.value); System.out.println("balance = " + longValue.value + " shortfall = " + shortfall.value); } }