Added: incubator/ode/scratch/ode/src/test/java/org/apache/ode/test/SerializeTester.java URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/test/java/org/apache/ode/test/SerializeTester.java?rev=381694&view=auto ============================================================================== --- incubator/ode/scratch/ode/src/test/java/org/apache/ode/test/SerializeTester.java (added) +++ incubator/ode/scratch/ode/src/test/java/org/apache/ode/test/SerializeTester.java Tue Feb 28 08:31:48 2006 @@ -0,0 +1,122 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +/* + * Created on Aug 28, 2003 + * + */ +package org.apache.ode.test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +//import java.util.Collection; +import java.util.Properties; + +import org.apache.ode.bped.DeployTypeEnum; +import org.apache.ode.bped.EventDirector; +import org.apache.ode.bped.EventDirectorFactory; +import org.apache.ode.bped.IDeployer; +import org.apache.ode.bped.IInternalEventDirector; +import org.apache.ode.definition.IPMDRoot; +import org.apache.ode.definition.service.DefinitionService; + +/** + * @author charper + * + */ +public class SerializeTester { + + private static final String tmpfile = System.getProperty("java.io.tmpdir") + + System.getProperty("file.separator") + "serializTesterTmpFile"; + private static final String keysfile = System.getProperty("java.io.tmpdir") + + System.getProperty("file.separator") + "serializTesterTmpFileProps"; + + public static void main(String[] args) throws Exception { + + if ( args[0].equals("-ser")) { + write(args[1]); + } else { + File f = new File(keysfile); + Properties props = new Properties(); + props.load(f.toURL().openStream()); + Object[] objs = read(); + for (int i = 0; i < objs.length; i++) { + IPMDRoot root = (IPMDRoot) objs[i]; + if ( props.getProperty( + root.getLabel()).equals(root.getProcess().getKey().getValue())) { + System.out.println("Id for de-serialized defintion " + + root.getLabel() + " is " + + props.getProperty(root.getLabel())); + } else { + System.err.println("Error:Id for de-serialized defintion " + + root.getLabel() + " is " + + root.getProcess().getKey().getValue()); + } + } + } + + } + + private static void write(String bpelFile) throws Exception { + + File defJar = new File(bpelFile); + EventDirector ed = EventDirectorFactory.createEventDirector(); + IDeployer deployer = ed.getDeployer(DeployTypeEnum.BPEL); + deployer.loadDefinition(new FileInputStream(defJar),false); + DefinitionService ds = ((IInternalEventDirector) ed) + .getProcessService().getInstanceService() + .getDefinitionService(); + + Object[] defs = ds.getRootDefinitions().toArray(); + + Properties props = new Properties(); + for (int i = 0; i < defs.length; i++) { + IPMDRoot root = (IPMDRoot)defs[i]; + props.put(root.getLabel(),root.getProcess().getKey().getValue()); + } + + FileOutputStream fos = null; + fos = new FileOutputStream(keysfile); + props.store(fos,"SerializeTester tmp file"); + + File f = new File(tmpfile); + f.delete(); + + fos = null; + ObjectOutputStream out = null; + + fos = new FileOutputStream(tmpfile); + out = new ObjectOutputStream(fos); + out.writeObject(defs); + out.close(); + + } + + private static Object[] read() throws Exception { + FileInputStream fis = null; + ObjectInputStream in = null; + Object obj = null; + fis = new FileInputStream(tmpfile); + in = new ObjectInputStream(fis); + obj = in.readObject(); + in.close(); + + return (Object[])obj; + } + +}
Added: incubator/ode/scratch/ode/src/test/java/org/apache/ode/uo/util/test/ApplicationLocalTest.java URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/test/java/org/apache/ode/uo/util/test/ApplicationLocalTest.java?rev=381694&view=auto ============================================================================== --- incubator/ode/scratch/ode/src/test/java/org/apache/ode/uo/util/test/ApplicationLocalTest.java (added) +++ incubator/ode/scratch/ode/src/test/java/org/apache/ode/uo/util/test/ApplicationLocalTest.java Tue Feb 28 08:31:48 2006 @@ -0,0 +1,69 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +package org.apache.ode.uo.util.test; + +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.TestCase; + +import org.apache.ode.uo.util.ApplicationLocalStore; + + +public class ApplicationLocalTest extends TestCase { + + public void testApplicationLocal() throws Exception { + + ClassLoader currentCL = Thread.currentThread().getContextClassLoader(); + + try { + String jar = System.getProperty("APP_LOCAL_JAR"); + File file = new File(jar); + if (!file.canRead()) { + throw new Exception(file + " doesn't exit!!!!"); + } + URL url = file.toURL(); + + ClassLoader cl1 = URLClassLoader.newInstance(new URL[]{url}); + ClassLoader cl2 = URLClassLoader.newInstance(new URL[]{url}); + + setCCL(cl1); + ApplicationLocalStore.set("key", "cl1"); + + setCCL(cl2); + ApplicationLocalStore.set("key", "cl2"); + + setCCL(cl1); + String str1 = (String) ApplicationLocalStore.get("key"); + + setCCL(cl2); + String str2 = (String) ApplicationLocalStore.get("key"); + + assertTrue(str1.equals("cl1") && str2.equals("cl2")); + + } catch (Exception e) { + throw e; + } finally { + setCCL(currentCL); + } + + } + + private static void setCCL(ClassLoader cl) { + Thread.currentThread().setContextClassLoader(cl); + } +} Added: incubator/ode/scratch/ode/src/test/java/org/apache/ode/uo/util/test/ServerApplicationLocalTest.java URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/test/java/org/apache/ode/uo/util/test/ServerApplicationLocalTest.java?rev=381694&view=auto ============================================================================== --- incubator/ode/scratch/ode/src/test/java/org/apache/ode/uo/util/test/ServerApplicationLocalTest.java (added) +++ incubator/ode/scratch/ode/src/test/java/org/apache/ode/uo/util/test/ServerApplicationLocalTest.java Tue Feb 28 08:31:48 2006 @@ -0,0 +1,89 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +/* + * Created on Sep 19, 2005 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.apache.ode.uo.util.test; + +import java.io.Serializable; + +import javax.naming.InitialContext; +import javax.rmi.PortableRemoteObject; + +import junit.framework.TestCase; + +import org.apache.ode.uo.util.ejb.ApplicationLocalStore; +import org.apache.ode.uo.util.ejb.ApplicationLocalStoreHome; + +/** + * @author charper + * + * To change the template for this generated type comment go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +public class ServerApplicationLocalTest extends TestCase { + + private ApplicationLocalStore apls1; + private ApplicationLocalStore apls2; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + + InitialContext ic = new InitialContext(); + + Object alsobj = ic.lookup("UOBASE/ApplicationLocalStore"); + ApplicationLocalStoreHome aplsh = + (ApplicationLocalStoreHome)PortableRemoteObject.narrow(alsobj, + ApplicationLocalStoreHome.class); + apls1 = aplsh.create(); + + Object alsobj2 = ic.lookup("UOBASE2/ApplicationLocalStore"); + ApplicationLocalStoreHome aplsh2 = + (ApplicationLocalStoreHome)PortableRemoteObject.narrow(alsobj2, + ApplicationLocalStoreHome.class); + apls2 = aplsh2.create(); + + } + + public void testApplicationLocal() throws Exception { + + apls1.set("key", "cl1"); + apls2.set("key", "cl2"); + String str1 = (String) apls1.get("key"); + String str2 = (String) apls2.get("key"); + + assertTrue(str1.equals("cl1") && str2.equals("cl2")); + } + + public void testApplicationLocalClear() throws Exception { + + apls1.set("key","cl1"); + apls2.set("key","cl2"); + apls1.clearStore(); + apls2.clearStore(); + Serializable obj1 = apls1.get("key"); + Serializable obj2 = apls2.get("key"); + + assertTrue(obj1 == null && obj2 == null ); + + } +}
