AvailabilityTest.java :  » XML-UI » xui32 » com » xoetrope » service » test » Java Open Source

Java Open Source » XML UI » xui32 
xui32 » com » xoetrope » service » test » AvailabilityTest.java
package com.xoetrope.service.test;

import junit.framework.TestCase;
import net.xoetrope.optional.data.XOptionalDataSource;
import net.xoetrope.optional.service.XRouteManager;
import net.xoetrope.optional.service.XServiceModelNode;
import net.xoetrope.xui.XProjectManager;
import net.xoetrope.xui.data.XModel;

/**
 * <p>Copyright (c) Xoetrope Ltd. 2001-2004</p>
 * $Revision: 1.2 $
 */
public class AvailabilityTest extends TestCase
{
  String defaultURLStr = "http://localhost:8080/xserviceservletError";

  public AvailabilityTest()
  {
    XProjectManager.getCurrentProject().setStartupFile( "xlib.properties" );
    readDataSource();
  }

  public void testModelService()
  {
    XRouteManager routeMgr = (XRouteManager)XProjectManager.getCurrentProject().getObject( "Routes" );
    XServiceModelNode node = new XServiceModelNode();

    try {
      node = ( XServiceModelNode )XModel.getInstance().get( "calcArea64" );
      node.setAttribValue( 0, "a" );
      node.setAttribValue( 1, "b" );
      node.setAttribValue( 2, "c" );
      Object result = node.get();
      assertTrue( new Double( result.toString() ).doubleValue() == 101.64 );
    }
    catch ( Exception ex ) {
      ex.printStackTrace();
    }
  }

  public void testFallback()
  {
    try {
      XServiceModelNode node = ( XServiceModelNode )XModel.getInstance().get( "getNameError" );
      Object result = node.get();
      assertTrue( new Double( result.toString() ).doubleValue() == 101.64 );
    }
    catch ( Exception ex ) {
      ex.printStackTrace();
    }

  }

  /**
   * Read the model
   * @param f the frame
   */
  private void readDataSource()
  {
    String startupFile;
    XOptionalDataSource modelDataSource;
    try {
      modelDataSource = new XOptionalDataSource();
    }
    catch ( Exception ex2 ) {
      return;
    }

    try {
      String fileName = XProjectManager.getCurrentProject().getStartupParam( "ModelData" );
      modelDataSource.read( XProjectManager.getCurrentProject().getBufferedReader( fileName, "UTF8" ) );
    }
    catch ( Exception ex ) {
      ex.printStackTrace();
    }

    assertTrue( XModel.getInstance().getNumChildren() > 0 );
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.