Ejemplo n.º 1
0
  /**
   * Initializes some class fields. Then creates DataSource, which serves as a single source for all
   * tables created in the test. This DataSource then registered in the global <code>DatabaseContext
   * </code> service. This data source's URL points to SOffice temp directory where tables are
   * copied from <code>TestDocuments</code> directory on every environment creation. To create
   * DataSource for MySQL database next parameters required in ini-file:
   *
   * <ul>
   *   <li><code>test.db.url</code> - URL to MySQL database. For example: <code>
   *       mysql://mercury:3306/api_current</code>
   *   <li><code>test.db.user</code> - user for MySQL database
   *   <li><code>test.db.password</code> - password for MySQL database
   * </ul>
   *
   * @throws StatusException if DataSource can not be created or registered.
   */
  protected void initialize(TestParameters Param, PrintWriter _log) throws StatusException {
    m_orb = (XMultiServiceFactory) Param.getMSF();

    String tmpDir = utils.getOfficeTemp(m_orb);

    origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf");

    dbTools = new DBTools(m_orb, _log);

    // creating DataSource and registering it in DatabaseContext
    String dbURL = (String) Param.get("test.db.url");
    String dbUser = (String) Param.get("test.db.user");
    String dbPassword = (String) Param.get("test.db.password");

    log.println("Creating and registering DataSource ...");
    srcInf = new DataSourceDescriptor(m_orb);
    if (dbURL != null && dbUser != null && dbPassword != null) {
      isMySQLDB = true;
      log.println("dbURL = " + dbURL);
      log.println("dbUSER = "******"dbPASSWORD = "******"soffice_test_table";
      srcInf.URL = "jdbc:" + dbURL;
      srcInf.IsPasswordRequired = new Boolean(true);
      srcInf.Password = dbPassword;
      srcInf.User = dbUser;
      PropertyValue[] propInfo = new PropertyValue[1];
      propInfo[0] = new PropertyValue();
      propInfo[0].Name = "JavaDriverClass";
      propInfo[0].Value = "org.gjt.mm.mysql.Driver";
      srcInf.Info = propInfo;
    } else {
      srcInf.URL = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir);
    }
    m_dataSource = srcInf.createDataSource();
    m_dataSource.registerAs(dbSourceName, true);
  }
  protected void initialize(TestParameters tParam, PrintWriter log) {
    // log.println( "creating a draw document" );
    // xTextDoc = WriterTools.createTextDoc(t((XMultiServiceFactory) Param.getMSF));
    tmpDir = utils.getOfficeTemp(((XMultiServiceFactory) tParam.getMSF()));

    origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf");

    dbTools = new DBTools((XMultiServiceFactory) tParam.getMSF(), log);

    // creating DataSource and registering it in DatabaseContext
    String dbURL = (String) tParam.get("test.db.url");
    String dbUser = (String) tParam.get("test.db.user");
    String dbPassword = (String) tParam.get("test.db.password");

    log.println("Creating and registering DataSource ...");
    srcInf = dbTools.newDataSourceInfo();

    if ((dbURL != null) && (dbUser != null) && (dbPassword != null)) {
      isMySQLDB = true;
      log.println("dbURL = " + dbURL);
      log.println("dbUSER = "******"dbPASSWORD = "******"soffice_test_table";
        srcInf.URL = "jdbc:" + dbURL;
        srcInf.IsPasswordRequired = new Boolean(true);
        srcInf.Password = dbPassword;
        srcInf.User = dbUser;

        PropertyValue[] propInfo = new PropertyValue[1];
        propInfo[0] = new PropertyValue();
        propInfo[0].Name = "JavaDriverClass";
        //                propInfo[0].Value = "org.gjt.mm.mysql.Driver";
        propInfo[0].Value = "util.dddriver.Driver";
        srcInf.Info = propInfo;

        dbSrc = srcInf.getDataSourceService();
        dbTools.reRegisterDB(dbSourceName, dbSrc);
      } catch (com.sun.star.uno.Exception e) {
        log.println("Error while object test initialization :");
        e.printStackTrace(log);
        throw new StatusException("Error while object test" + " initialization", e);
      }
    } else {
      // DataSource for sdbc db
      try {
        String myDbUrl = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir);
        srcInf.URL = myDbUrl;

        log.println("try to register '" + myDbUrl + "' as '" + dbSourceName + "'");

        dbSrc = srcInf.getDataSourceService();
        dbTools.reRegisterDB(dbSourceName, dbSrc);
      } catch (com.sun.star.uno.Exception e) {
        log.println("Error while object test initialization :");
        e.printStackTrace(log);
        throw new StatusException("Error while object test initialization", e);
      }

      String oldF = null;
      String newF = null;

      do {
        tableName = "ODatabaseForm_tmp" + uniqueSuffix;
        oldF = utils.getFullURL(origDB);
        newF = utils.getOfficeTemp((XMultiServiceFactory) tParam.getMSF()) + tableName + ".dbf";
      } while (!utils.tryOverwriteFile(((XMultiServiceFactory) tParam.getMSF()), oldF, newF)
          && (uniqueSuffix++ < 50));
    }
  }