ALMA Computing Group

ComponentClientTestCaseTest.java

Go to the documentation of this file.
00001 /* 00002 * ALMA - Atacama Large Millimiter Array 00003 * (c) European Southern Observatory, 2002 00004 * Copyright by ESO (in the framework of the ALMA collaboration), 00005 * All rights reserved 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00020 * MA 02111-1307 USA 00021 */ 00022 package alma.acs.component.client; 00023 00024 00025 import java.util.logging.Logger; 00026 00027 import com.cosylab.CDB.DAL; 00028 import com.cosylab.CDB.DALChangeListener; 00029 import com.cosylab.CDB.DALChangeListenerHelper; 00030 import com.cosylab.CDB.DALChangeListenerPOA; 00031 00032 import alma.ACS.CBDescIn; 00033 import alma.ACS.CBDescOut; 00034 import alma.ACS.CBvoid; 00035 import alma.ACS.CBvoidPOA; 00036 import alma.ACSErr.Completion; 00037 import alma.ACS.OffShoot; 00038 import alma.ACS.RWdouble; 00039 import alma.acsexmplLamp.Lamp; 00040 import alma.acsexmplLamp.LampHelper; 00041 00047 public class ComponentClientTestCaseTest extends ComponentClientTestCase 00048 { 00049 // C++ component that takes a callback object 00050 private static final String m_lampCurl = "LAMP1"; 00051 00052 00057 public ComponentClientTestCaseTest() throws Exception 00058 { 00059 super(ComponentClientTestCaseTest.class.getName()); 00060 } 00061 00065 protected void setUp() throws Exception 00066 { 00067 super.setUp(); 00068 } 00069 00073 protected void tearDown() throws Exception 00074 { 00075 super.tearDown(); 00076 } 00077 00078 public void testGetDAL() throws Exception 00079 { 00080 DAL dal = getContainerServices().getCDB(); 00081 assertNotNull(dal); 00082 00083 String managerDAOString = dal.get_DAO("MACI/Managers/Manager"); 00084 assertNotNull(managerDAOString); 00085 00086 m_logger.info("received manager DAO string from the CDB:\n" + managerDAOString); 00087 } 00088 00089 public void testActivateOffShoot() throws Exception 00090 { 00091 // activate callback object 00092 MyTestCBvoid cb = new MyTestCBvoid(m_logger); 00093 m_logger.info("MyTestCBvoid instantiated..."); 00094 CBvoid cbvoid = alma.ACS.CBvoidHelper.narrow( 00095 getContainerServices().activateOffShoot(cb) ); 00096 m_logger.info("MyTestCBvoid activated."); 00097 00098 00099 // activate dal listener object 00100 m_logger.info("activating dal listener offshoot..."); 00101 DALChangeListenerPOA dalListenerSrv = new MyTestDALChangeListener(); 00102 OffShoot offshoot2 = getContainerServices().activateOffShoot(dalListenerSrv); 00103 DALChangeListener dalListenerRef = DALChangeListenerHelper.narrow(offshoot2); 00104 m_logger.info("done activating dal listener offshoot."); 00105 00106 00107 // check if dal listener works... 00108 m_logger.info("calling dal listener..."); 00109 dalListenerRef.object_changed("happyCurl"); 00110 m_logger.info("done calling dal listener."); 00111 00112 00113 // check if callback works... 00114 RWdouble brightness = null; 00115 Lamp lamp = 00116 LampHelper.narrow( 00117 getContainerServices().getComponent(m_lampCurl)); 00118 00119 assertNotNull("reference to Lamp component not null", lamp); 00120 00121 brightness = lamp.brightness(); 00122 assertNotNull("brightness property of lamp not null", brightness); 00123 00124 CBDescIn desc = new CBDescIn(); 00125 m_logger.info("m_desc instantiated..."); 00126 00127 m_logger.info("before setting callback..."); 00128 brightness.set_async(7.345, cbvoid, desc); 00129 m_logger.finer("callback set..."); 00130 00131 //todo: do something and get feedback from the callback object 00132 // m_logger.finer("changing value (sync)..."); 00133 // brightness.set_sync(8.456); 00134 } 00135 00136 00137 00138 public static void main(String[] args) 00139 { 00140 junit.textui.TestRunner.run(ComponentClientTestCaseTest.class); 00141 } 00142 00143 00144 private class MyTestDALChangeListener extends DALChangeListenerPOA 00145 { 00146 public void object_changed(String curl) 00147 { 00148 m_logger.fine("called object_changed with " + curl); 00149 } 00150 } 00151 00152 00153 } 00154 00155 00156 00157 class MyTestCBvoid extends CBvoidPOA 00158 { 00159 private Logger m_logger; 00160 00161 public MyTestCBvoid(Logger logger) 00162 { 00163 m_logger = logger; 00164 } 00165 00169 public void working(Completion completion, CBDescOut desc) 00170 { 00171 m_logger.fine("called working()..."); 00172 } 00176 public void done(Completion completion, CBDescOut desc) 00177 { 00178 m_logger.fine("called done()..."); 00179 } 00183 public boolean negotiate(long myLong, CBDescOut desc) 00184 { 00185 m_logger.fine("called negotiate()..."); 00186 return true; 00187 } 00188 } 00189 00190