001: package com.xoetrope.service.test;
002:
003: import junit.framework.TestCase;
004: import net.xoetrope.optional.data.XOptionalDataSource;
005: import net.xoetrope.xui.XProjectManager;
006: import net.xoetrope.xui.data.XModel;
007:
008: /**
009: * <p>Copyright (c) Xoetrope Ltd. 2001-2004</p>
010: * $Revision: 1.2 $
011: */
012: public class XServiceTest extends TestCase {
013: protected String defaultURLStr = "http://localhost:8080/xserviceservlet";
014:
015: public XServiceTest() {
016: XProjectManager.getCurrentProject().setStartupFile(
017: "xlib.properties");
018: readDataSource();
019: }
020:
021: /* public void testService()
022: {
023: XServiceModelNode node = new XServiceModelNode();
024: node.setupService( "getName", new CalcTestService(), null );
025: Object result = node.get();
026: assertTrue( result.toString().compareTo( CalcTestService.class.getName()) == 0 );
027: }
028: public void testHttpService()
029: {
030: XServiceModelNode node = new XServiceModelNode();
031: XHttpClientServiceProxy s = new XHttpClientServiceProxy();
032: s.setUrl( defaultURLStr );
033: s.setRouteName( "remote" );
034: node.setupService( "getName", s, null );
035: Object result = node.get();
036: assertTrue( result.toString().compareTo( CalcTestService.class.getName()) == 0 );
037: }
038: public void testServiceFactory()
039: {
040: assertTrue( XModel.getInstance().getNumChildren() > 0 );
041: XRouteManager routeMgr = XRouteManager.getInstance();
042: XServiceModelNode node = new XServiceModelNode();
043: try {
044: node.setupService( "getName", routeMgr.getRoute( "calcRoute", "com.xoetrope.service.test.CalcTestService" ), null );
045: Object result = node.get();
046: assertTrue( result.toString().compareTo( CalcTestService.class.getName() ) == 0 );
047: node.setupService( "getName64", routeMgr.getRoute( "calcRoute64", "com.xoetrope.service.test.CalcTestService" ), null );
048: result = node.get();
049: assertTrue( result.toString().compareTo( "2.64" ) == 0 );
050: // Test the exception handling
051: Object exception = null;
052: try {
053: node.setupService( "getName", routeMgr.getRoute( "throwsException", "" ), null );
054: }
055: catch ( XServiceProxyNotFoundException ex1 ) {
056: exception = ex1;
057: }
058: assertTrue( exception instanceof XServiceProxyNotFoundException );
059: // Test via the model
060: XModel model = XModel.getInstance();
061: Object modelNode = ((XModel)model.get( "getName", null )).get();
062: assertTrue( modelNode instanceof XServiceModelNode );
063: result = ((XModel)modelNode).get();
064: assertTrue( result.toString().compareTo( CalcTestService.class.getName() ) == 0 );
065: modelNode = ((XModel)model.get( "getName", "value" ));
066: assertTrue( modelNode instanceof XServiceModelNode );
067: result = ((XModel)modelNode).get();
068: assertTrue( result.toString().compareTo( CalcTestService.class.getName() ) == 0 );
069: modelNode = ((XModel)model.get( "getName" ));
070: assertTrue( modelNode instanceof XServiceModelNode );
071: result = ((XModel)modelNode).get();
072: assertTrue( result.toString().compareTo( CalcTestService.class.getName() ) == 0 );
073: }
074: catch ( XServiceProxyNotFoundException ex ) {
075: ex.printStackTrace();
076: }
077: }
078: public void testModelService()
079: {
080: assertTrue( XModel.getInstance().getNumChildren() > 0 );
081: try {
082: XServiceModelNode node = (XServiceModelNode)XModel.getInstance().get( "calcArea64" );
083: node.setAttribValue( 0, "a" );
084: node.setAttribValue( 1, "b" );
085: node.setAttribValue( 2, "c" );
086: Object result = node.get();
087: //assertTrue( result instanceof Double );
088: assertTrue( Double.parseDouble(result.toString()) == 101.64 );
089: }
090: catch ( Exception ex ) {
091: ex.printStackTrace();
092: }
093: }
094: */
095: /**
096: * Read the model
097: * @param f the frame
098: */
099: private void readDataSource() {
100: String startupFile;
101: XOptionalDataSource modelDataSource;
102: try {
103: modelDataSource = new XOptionalDataSource();
104: } catch (Exception ex2) {
105: return;
106: }
107:
108: try {
109: String fileName = XProjectManager.getCurrentProject()
110: .getStartupParam("ModelData");
111: modelDataSource.read(XProjectManager.getCurrentProject()
112: .getBufferedReader(fileName, "UTF8"));
113: } catch (Exception ex) {
114: ex.printStackTrace();
115: }
116:
117: assertTrue(XModel.getInstance().getNumChildren() > 0);
118: }
119: }
|