ALMA Computing Group

XmlComponentClient.java

Go to the documentation of this file.
00001 /* 00002 * ALMA - Atacama Large Millimiter Array (c) European Southern Observatory, 00003 * 2002 Copyright by ESO (in the framework of the ALMA collaboration), All 00004 * rights reserved 00005 * 00006 * This library is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published by the 00008 * Free Software Foundation; either version 2.1 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, but WITHOUT 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00014 * for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this library; if not, write to the Free Software Foundation, 00018 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 package alma.demo.client; 00021 00022 import java.util.logging.Level; 00023 00024 import org.omg.CORBA.DATA_CONVERSION; 00025 00026 import alma.JContExmplErrTypeTest.XmlComponentErrorEx; 00027 import alma.JContExmplErrTypeTest.wrappers.AcsJXmlComponentErrorEx; 00028 import alma.acs.component.client.ComponentClientTestCase; 00029 import alma.acs.exceptions.AcsJException; 00030 import alma.demo.SchedBlockHolder; 00031 import alma.demo.XmlComponent; 00032 import alma.demo.XmlComponentJ; 00033 import alma.demo.XmlComponentOperations; 00034 import alma.entities.commonentity.EntityT; 00035 import alma.xmlentity.XmlEntityStruct; 00036 import alma.xmljbind.test.obsproposal.ObsProposal; 00037 import alma.xmljbind.test.schedblock.SchedBlock; 00038 00046 public class XmlComponentClient extends ComponentClientTestCase 00047 { 00048 // standard CORBA interface 00049 private XmlComponent m_xmlComp; 00050 00051 // transparent-XML interface 00052 private XmlComponentJ m_xmlCompJ; 00053 00054 00055 public XmlComponentClient() throws Exception { 00056 super("XmlComponentClient"); 00057 } 00058 00059 00060 protected void setUp() throws Exception { 00061 super.setUp(); 00062 00063 org.omg.CORBA.Object compObj = getContainerServices().getComponent("XMLCOMP1"); 00064 assertNotNull(compObj); 00065 00066 m_xmlComp = alma.demo.XmlComponentHelper.narrow(compObj); 00067 assertNotNull(m_xmlComp); 00068 00069 m_xmlCompJ = getContainerServices().getTransparentXmlComponent( 00070 XmlComponentJ.class, m_xmlComp, XmlComponentOperations.class); 00071 assertNotNull(m_xmlCompJ); 00072 } 00073 00074 00078 public void testSayHelloUsingHelloDemoComponent() { 00079 String reply = m_xmlCompJ.sayHello(); 00080 assertNotNull(reply); 00081 System.out.println("received reply " + reply); 00082 assertEquals("reply must be 'hello'", "hello", reply); 00083 } 00084 00088 public void testCreateObsProposal() { 00089 ObsProposal obsProp = m_xmlCompJ.createObsProposal(); 00090 assertNotNull(obsProp); 00091 00092 EntityT ent = obsProp.getObsProposalEntity(); 00093 assertNotNull(ent); 00094 00095 String id = ent.getEntityId(); 00096 assertNotNull(id); 00097 00098 System.out.println("received ObsProposal with id " + id); 00099 } 00100 00105 public void testAddNewSchedBlocks() { 00106 XmlEntityStruct[] xesArray = new XmlEntityStruct[1]; 00107 00108 // first use valid xml 00109 xesArray[0] = createSchedBlockXml(false); 00110 m_xmlComp.addNewSchedBlocks(xesArray); 00111 00112 // now make Castor unmarshalling fail 00113 xesArray[0] = createSchedBlockXml(true); 00114 try { 00115 m_xmlComp.addNewSchedBlocks(xesArray); 00116 fail("illegal XML should have caused an exception in the server-side unmarshalling."); 00117 } 00118 catch (DATA_CONVERSION ex) { 00119 m_logger.log(Level.INFO, "illegal XML yielded exception as expected: " + ex.toString() ); 00120 } 00121 } 00122 00123 00127 private XmlEntityStruct createSchedBlockXml(boolean breakUnmarshaller) { 00128 String sbXML = 00129 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + 00130 "<ns1:SchedBlock xmlns:ns1=\"AlmaTest/SchedBlock\">" + 00131 "<ns1:SchedBlockEntity " + 00132 "entityIdEncrypted=\"-- id encryption not yet implemented --\" " + 00133 "entityId=\"uid://X0000000000000064/X10000001\" entityTypeName=\"SchedBlock\"/> " + 00134 "<ns1:SchedBlockControl repeatCount=\"1\" entityPartId=\"X00000008\" />"; 00135 if (breakUnmarshaller) { 00136 sbXML += "<ns1:ElementTooMany whyIsThis=\"to martially break the unmarshaller\" />"; 00137 } 00138 sbXML += "</ns1:SchedBlock>"; 00139 00140 XmlEntityStruct entStruct = new XmlEntityStruct(); 00141 entStruct.xmlString = sbXML; 00142 entStruct.entityId = "uid://X0000000000000064/X10000001"; 00143 entStruct.entityTypeName = "SchedBlock"; 00144 entStruct.schemaVersion = ""; 00145 entStruct.timeStamp = ""; 00146 return entStruct; 00147 } 00148 00149 00150 public void testXmlInOutMethod() { 00151 ObsProposal obsProp = m_xmlCompJ.createObsProposal(); 00152 assertNotNull(obsProp); 00153 SchedBlockHolder sbh = new SchedBlockHolder(); 00154 00155 m_xmlCompJ.xmlInOutMethod(obsProp, sbh); 00156 00157 SchedBlock schedBlock = sbh.value; 00158 assertNotNull(schedBlock); 00159 00160 EntityT ent = schedBlock.getSchedBlockEntity(); 00161 assertNotNull(ent); 00162 String id = ent.getEntityId(); 00163 assertNotNull(id); 00164 00165 System.out.println("received out-param SchedBlock with id " + id); 00166 } 00167 00173 public void testException() throws Exception { 00174 boolean gotException = false; 00175 00176 try { 00177 m_xmlCompJ.exceptionMethod(); 00178 } 00179 catch (XmlComponentErrorEx e) { 00180 gotException = true; 00181 m_logger.info("received " + XmlComponentErrorEx.class.getName() + " as intended. Log messages of ErrorTrace follow:"); 00182 AcsJException acsJEx = AcsJXmlComponentErrorEx.fromXmlComponentErrorEx(e); 00183 acsJEx.log(m_logger); 00184 } 00185 00186 assertTrue("must receive " + XmlComponentErrorEx.class.getName(), gotException); 00187 } 00188 } 00189