You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/12/30 12:04:55 UTC
svn commit: r1225802 - in
/incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests:
Base.java BaseDerby.java BaseHSQLDB.java BaseHSQLDBext.java BaseMySQL.java
BasePostgresql.java
Author: kwright
Date: Fri Dec 30 11:04:55 2011
New Revision: 1225802
URL: http://svn.apache.org/viewvc?rev=1225802&view=rev
Log:
Reorganize test base classes for extendibility. Part of CONNECTORS-346, and may also address issues related to CONNECTORS-341.
Added:
incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/Base.java (with props)
Modified:
incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseDerby.java
incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDB.java
incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java
incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseMySQL.java
incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BasePostgresql.java
Added: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/Base.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/Base.java?rev=1225802&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/Base.java (added)
+++ incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/Base.java Fri Dec 30 11:04:55 2011
@@ -0,0 +1,221 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.core.tests;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.core.system.ManifoldCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+
+/** This is a testing base class that is the base class of all ManifoldCF testing classes, at least the ones
+* that manage configuration files and database setup. */
+public class Base
+{
+ protected File currentPath = null;
+ protected File configFile = null;
+ protected File loggingFile = null;
+ protected File logOutputFile = null;
+
+ protected void initialize()
+ throws Exception
+ {
+ if (currentPath == null)
+ {
+ currentPath = new File(".").getCanonicalFile();
+
+ // First, write a properties file and a logging file, in the current directory.
+ configFile = new File("properties.xml").getCanonicalFile();
+ loggingFile = new File("logging.ini").getCanonicalFile();
+ logOutputFile = new File("manifoldcf.log").getCanonicalFile();
+
+ // Set a system property that will point us to the proper place to find the properties file
+ System.setProperty("org.apache.manifoldcf.configfile",configFile.getCanonicalFile().getAbsolutePath());
+ }
+ }
+
+ protected boolean isInitialized()
+ {
+ return configFile.exists();
+ }
+
+ @Before
+ public void setUp()
+ throws Exception
+ {
+ try
+ {
+ localCleanUp();
+ }
+ catch (Exception e)
+ {
+ System.out.println("Warning: Preclean error: "+e.getMessage());
+ }
+ try
+ {
+ localSetUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ /** Method to write the logging.ini contents.
+ * Override this method if you want different contents, or you want to your own stuff.
+ */
+ protected void writeLoggingIni(StringBuilder output)
+ throws Exception
+ {
+ output.append(
+ "log4j.appender.MAIN.File="+logOutputFile.getAbsolutePath().replaceAll("\\\\","/")+"\n" +
+ "log4j.rootLogger=WARN, MAIN\n" +
+ "log4j.appender.MAIN=org.apache.log4j.RollingFileAppender\n" +
+ "log4j.appender.MAIN.layout=org.apache.log4j.PatternLayout\n" +
+ "log4j.appender.MAIN.layout.ConversionPattern=%5p %d{ISO8601} (%t) - %m%n\n"
+ );
+ }
+
+ /** Method to write the properties.xml contents.
+ * Override this method if you want dto replace everything
+ * with your own stuff.
+ */
+ protected void writePropertiesXML(StringBuilder output)
+ throws Exception
+ {
+ output.append(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
+ "<configuration>\n"+
+ " <property name=\"org.apache.manifoldcf.logconfigfile\" value=\""+loggingFile.getAbsolutePath().replaceAll("\\\\","/")+"\"/>\n"
+ );
+ writeProperties(output);
+ output.append(
+ "</configuration>\n"
+ );
+ }
+
+ /** Method to add properties to properties.xml contents.
+ * Override this method to add properties clauses to the property file.
+ */
+ protected void writeProperties(StringBuilder output)
+ throws Exception
+ {
+ output.append(
+ " <property name=\"org.apache.manifoldcf.logconfigfile\" value=\""+loggingFile.getAbsolutePath().replaceAll("\\\\","/")+"\"/>\n"
+ );
+ }
+
+ /** Method to get database superuser name.
+ */
+ protected String getDatabaseSuperuserName()
+ throws Exception
+ {
+ return "";
+ }
+
+ /** Method to get database superuser password.
+ */
+ protected String getDatabaseSuperuserPassword()
+ throws Exception
+ {
+ return "";
+ }
+
+ protected void localSetUp()
+ throws Exception
+ {
+ initialize();
+
+ StringBuilder loggingIniContents = new StringBuilder();
+ writeLoggingIni(loggingIniContents);
+ writeFile(loggingFile,loggingIniContents.toString());
+
+ StringBuilder propertiesXMLContents = new StringBuilder();
+ writePropertiesXML(propertiesXMLContents);
+ writeFile(configFile,propertiesXMLContents.toString());
+
+ ManifoldCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
+
+ // Create the database
+ ManifoldCF.createSystemDatabase(tc,getDatabaseSuperuserName(),getDatabaseSuperuserPassword());
+
+ }
+
+ @After
+ public void cleanUp()
+ throws Exception
+ {
+ try
+ {
+ localCleanUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ protected void localCleanUp()
+ throws Exception
+ {
+ initialize();
+ if (isInitialized())
+ {
+ ManifoldCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
+
+ // Remove the database
+ ManifoldCF.dropSystemDatabase(tc,getDatabaseSuperuserName(),getDatabaseSuperuserPassword());
+
+ // Get rid of the property and logging files.
+ logOutputFile.delete();
+ configFile.delete();
+ loggingFile.delete();
+
+ ManifoldCF.resetEnvironment();
+ }
+ }
+
+ protected static void writeFile(File f, String fileContents)
+ throws IOException
+ {
+ OutputStream os = new FileOutputStream(f);
+ try
+ {
+ Writer w = new OutputStreamWriter(os,"UTF-8");
+ try
+ {
+ w.write(fileContents);
+ }
+ finally
+ {
+ w.close();
+ }
+ }
+ finally
+ {
+ os.close();
+ }
+ }
+
+}
Propchange: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/Base.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/Base.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseDerby.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseDerby.java?rev=1225802&r1=1225801&r2=1225802&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseDerby.java (original)
+++ incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseDerby.java Fri Dec 30 11:04:55 2011
@@ -26,75 +26,18 @@ import java.util.*;
import org.junit.*;
/** This is a testing base class that is responsible for setting up/tearing down the core Derby database. */
-public class BaseDerby
+public class BaseDerby extends Base
{
- protected File currentPath = null;
- protected File configFile = null;
- protected File loggingFile = null;
- protected File logOutputFile = null;
- protected void initialize()
+ /** Method to add properties to properties.xml contents.
+ * Override this method to add properties clauses to the property file.
+ */
+ protected void writeProperties(StringBuilder output)
throws Exception
{
- if (currentPath == null)
- {
- currentPath = new File(".").getCanonicalFile();
-
- // First, write a properties file and a logging file, in the current directory.
- configFile = new File("properties.xml").getCanonicalFile();
- loggingFile = new File("logging.ini").getCanonicalFile();
- logOutputFile = new File("manifoldcf.log").getCanonicalFile();
-
- // Set a system property that will point us to the proper place to find the properties file
- System.setProperty("org.apache.manifoldcf.configfile",configFile.getCanonicalFile().getAbsolutePath());
- }
- }
-
- protected boolean isInitialized()
- {
- return configFile.exists();
- }
-
- @Before
- public void setUp()
- throws Exception
- {
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- System.out.println("Warning: Preclean error: "+e.getMessage());
- }
- try
- {
- localSetUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
-
-
- protected void localSetUp()
- throws Exception
- {
- initialize();
+ super.writeProperties(output);
String currentPathString = currentPath.getAbsolutePath();
- writeFile(loggingFile,
- "log4j.appender.MAIN.File="+logOutputFile.getAbsolutePath().replaceAll("\\\\","/")+"\n" +
- "log4j.rootLogger=WARN, MAIN\n" +
- "log4j.appender.MAIN=org.apache.log4j.RollingFileAppender\n" +
- "log4j.appender.MAIN.layout=org.apache.log4j.PatternLayout\n" +
- "log4j.appender.MAIN.layout.ConversionPattern=%5p %d{ISO8601} (%t) - %m%n\n"
- );
-
- writeFile(configFile,
- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
- "<configuration>\n"+
+ output.append(
" <property name=\"org.apache.manifoldcf.databaseimplementationclass\" value=\"org.apache.manifoldcf.core.database.DBInterfaceDerby\"/>\n" +
" <property name=\"org.apache.manifoldcf.derbydatabasepath\" value=\""+currentPathString.replaceAll("\\\\","/")+"\"/>\n" +
" <property name=\"org.apache.manifoldcf.database.maxquerytime\" value=\"30\"/>\n" +
@@ -102,74 +45,7 @@ public class BaseDerby
" <property name=\"org.apache.manifoldcf.crawler.expirethreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.crawler.cleanupthreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.crawler.deletethreads\" value=\"10\"/>\n" +
- " <property name=\"org.apache.manifoldcf.database.maxhandles\" value=\"80\"/>\n" +
- " <property name=\"org.apache.manifoldcf.logconfigfile\" value=\""+loggingFile.getAbsolutePath().replaceAll("\\\\","/")+"\"/>\n" +
- "</configuration>\n");
-
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Create the database
- ManifoldCF.createSystemDatabase(tc,"","");
-
- }
-
- @After
- public void cleanUp()
- throws Exception
- {
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
-
- protected void localCleanUp()
- throws Exception
- {
- initialize();
- if (isInitialized())
- {
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Remove the database
- ManifoldCF.dropSystemDatabase(tc,"","");
-
- // Get rid of the property and logging files.
- logOutputFile.delete();
- configFile.delete();
- loggingFile.delete();
-
- ManifoldCF.resetEnvironment();
- }
- }
-
- protected static void writeFile(File f, String fileContents)
- throws IOException
- {
- OutputStream os = new FileOutputStream(f);
- try
- {
- Writer w = new OutputStreamWriter(os,"utf-8");
- try
- {
- w.write(fileContents);
- }
- finally
- {
- w.close();
- }
- }
- finally
- {
- os.close();
- }
+ " <property name=\"org.apache.manifoldcf.database.maxhandles\" value=\"80\"/>\n"
+ );
}
-
}
Modified: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDB.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDB.java?rev=1225802&r1=1225801&r2=1225802&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDB.java (original)
+++ incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDB.java Fri Dec 30 11:04:55 2011
@@ -26,75 +26,17 @@ import java.util.*;
import org.junit.*;
/** This is a testing base class that is responsible for setting up/tearing down the core Derby database. */
-public class BaseHSQLDB
+public class BaseHSQLDB extends Base
{
- protected File currentPath = null;
- protected File configFile = null;
- protected File loggingFile = null;
- protected File logOutputFile = null;
-
- protected void initialize()
- throws Exception
- {
- if (currentPath == null)
- {
- currentPath = new File(".").getCanonicalFile();
-
- // First, write a properties file and a logging file, in the current directory.
- configFile = new File("properties.xml").getCanonicalFile();
- loggingFile = new File("logging.ini").getCanonicalFile();
- logOutputFile = new File("manifoldcf.log").getCanonicalFile();
-
- // Set a system property that will point us to the proper place to find the properties file
- System.setProperty("org.apache.manifoldcf.configfile",configFile.getCanonicalFile().getAbsolutePath());
- }
- }
-
- protected boolean isInitialized()
- {
- return configFile.exists();
- }
-
- @Before
- public void setUp()
- throws Exception
- {
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- System.out.println("Warning: Preclean error: "+e.getMessage());
- }
- try
- {
- localSetUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
-
-
- protected void localSetUp()
+ /** Method to add properties to properties.xml contents.
+ * Override this method to add properties clauses to the property file.
+ */
+ protected void writeProperties(StringBuilder output)
throws Exception
{
- initialize();
+ super.writeProperties(output);
String currentPathString = currentPath.getAbsolutePath();
- writeFile(loggingFile,
- "log4j.appender.MAIN.File="+logOutputFile.getAbsolutePath().replaceAll("\\\\","/")+"\n" +
- "log4j.rootLogger=WARN, MAIN\n" +
- "log4j.appender.MAIN=org.apache.log4j.RollingFileAppender\n" +
- "log4j.appender.MAIN.layout=org.apache.log4j.PatternLayout\n" +
- "log4j.appender.MAIN.layout.ConversionPattern=%5p %d{ISO8601} (%t) - %m%n\n"
- );
-
- writeFile(configFile,
- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
- "<configuration>\n"+
+ output.append(
" <property name=\"org.apache.manifoldcf.databaseimplementationclass\" value=\"org.apache.manifoldcf.core.database.DBInterfaceHSQLDB\"/>\n" +
" <property name=\"org.apache.manifoldcf.hsqldbdatabasepath\" value=\""+currentPathString.replaceAll("\\\\","/")+"\"/>\n" +
" <property name=\"org.apache.manifoldcf.database.maxquerytime\" value=\"30\"/>\n" +
@@ -102,74 +44,8 @@ public class BaseHSQLDB
" <property name=\"org.apache.manifoldcf.crawler.expirethreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.crawler.cleanupthreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.crawler.deletethreads\" value=\"10\"/>\n" +
- " <property name=\"org.apache.manifoldcf.database.maxhandles\" value=\"80\"/>\n" +
- " <property name=\"org.apache.manifoldcf.logconfigfile\" value=\""+loggingFile.getAbsolutePath().replaceAll("\\\\","/")+"\"/>\n" +
- "</configuration>\n");
-
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Create the database
- ManifoldCF.createSystemDatabase(tc,"","");
-
- }
-
- @After
- public void cleanUp()
- throws Exception
- {
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
-
- protected void localCleanUp()
- throws Exception
- {
- initialize();
- if (isInitialized())
- {
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Remove the database
- ManifoldCF.dropSystemDatabase(tc,"","");
-
- // Get rid of the property and logging files.
- logOutputFile.delete();
- configFile.delete();
- loggingFile.delete();
-
- ManifoldCF.resetEnvironment();
- }
- }
-
- protected static void writeFile(File f, String fileContents)
- throws IOException
- {
- OutputStream os = new FileOutputStream(f);
- try
- {
- Writer w = new OutputStreamWriter(os,"utf-8");
- try
- {
- w.write(fileContents);
- }
- finally
- {
- w.close();
- }
- }
- finally
- {
- os.close();
- }
+ " <property name=\"org.apache.manifoldcf.database.maxhandles\" value=\"80\"/>\n"
+ );
}
}
Modified: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java?rev=1225802&r1=1225801&r2=1225802&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java (original)
+++ incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java Fri Dec 30 11:04:55 2011
@@ -27,81 +27,18 @@ import org.junit.*;
import java.lang.reflect.*;
/** This is a testing base class that is responsible for setting up/tearing down the core HSQLDB remote database. */
-public class BaseHSQLDBext
+public class BaseHSQLDBext extends Base
{
- protected File currentPath = null;
- protected File configFile = null;
- protected File loggingFile = null;
- protected File logOutputFile = null;
-
protected DatabaseThread databaseThread = null;
- protected void initialize()
- throws Exception
- {
- if (currentPath == null)
- {
- // Start "remote" hsqldb instance
- startDatabase();
-
- currentPath = new File(".").getCanonicalFile();
-
- // First, write a properties file and a logging file, in the current directory.
- configFile = new File("properties.xml").getCanonicalFile();
- loggingFile = new File("logging.ini").getCanonicalFile();
- logOutputFile = new File("manifoldcf.log").getCanonicalFile();
-
- // Set a system property that will point us to the proper place to find the properties file
- System.setProperty("org.apache.manifoldcf.configfile",configFile.getCanonicalFile().getAbsolutePath());
- }
- }
-
- protected boolean isInitialized()
- {
- return configFile.exists();
- }
-
- @Before
- public void setUp()
- throws Exception
- {
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- System.out.println("Warning: Preclean error: "+e.getMessage());
- }
- try
- {
- localSetUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
-
-
- protected void localSetUp()
+ /** Method to add properties to properties.xml contents.
+ * Override this method to add properties clauses to the property file.
+ */
+ protected void writeProperties(StringBuilder output)
throws Exception
{
- // Initialize
- initialize();
- String currentPathString = currentPath.getAbsolutePath();
- writeFile(loggingFile,
- "log4j.appender.MAIN.File="+logOutputFile.getAbsolutePath().replaceAll("\\\\","/")+"\n" +
- "log4j.rootLogger=WARN, MAIN\n" +
- "log4j.appender.MAIN=org.apache.log4j.RollingFileAppender\n" +
- "log4j.appender.MAIN.layout=org.apache.log4j.PatternLayout\n" +
- "log4j.appender.MAIN.layout.ConversionPattern=%5p %d{ISO8601} (%t) - %m%n\n"
- );
-
- writeFile(configFile,
- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
- "<configuration>\n"+
+ super.writeProperties(output);
+ output.append(
" <property name=\"org.apache.manifoldcf.databaseimplementationclass\" value=\"org.apache.manifoldcf.core.database.DBInterfaceHSQLDB\"/>\n" +
" <property name=\"org.apache.manifoldcf.hsqldbdatabaseprotocol\" value=\"hsql\"/>\n" +
" <property name=\"org.apache.manifoldcf.hsqldbdatabaseserver\" value=\"localhost\"/>\n" +
@@ -111,55 +48,40 @@ public class BaseHSQLDBext
" <property name=\"org.apache.manifoldcf.crawler.expirethreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.crawler.cleanupthreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.crawler.deletethreads\" value=\"10\"/>\n" +
- " <property name=\"org.apache.manifoldcf.database.maxhandles\" value=\"80\"/>\n" +
- " <property name=\"org.apache.manifoldcf.logconfigfile\" value=\""+loggingFile.getAbsolutePath().replaceAll("\\\\","/")+"\"/>\n" +
- "</configuration>\n");
-
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Create the database
- ManifoldCF.createSystemDatabase(tc,"sa","");
+ " <property name=\"org.apache.manifoldcf.database.maxhandles\" value=\"80\"/>\n"
+ );
+ }
+ /** Method to get database superuser name.
+ */
+ protected String getDatabaseSuperuserName()
+ throws Exception
+ {
+ return "sa";
}
- @After
- public void cleanUp()
+ /** Method to get database superuser password.
+ */
+ protected String getDatabaseSuperuserPassword()
throws Exception
{
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
+ return "";
}
- protected void localCleanUp()
+ @Before
+ public void startHSQLDBInstance()
throws Exception
{
- initialize();
- if (isInitialized())
- {
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Remove the database
- ManifoldCF.dropSystemDatabase(tc,"sa","");
-
- // Get rid of the property and logging files.
- logOutputFile.delete();
- configFile.delete();
- loggingFile.delete();
-
- ManifoldCF.resetEnvironment();
- stopDatabase();
- }
+ startDatabase();
}
-
+
+ @After
+ public void stopHSQLDBInstance()
+ throws Exception
+ {
+ stopDatabase();
+ }
+
protected void startDatabase()
throws Exception
{
@@ -180,28 +102,6 @@ public class BaseHSQLDBext
databaseThread.join();
}
- protected static void writeFile(File f, String fileContents)
- throws IOException
- {
- OutputStream os = new FileOutputStream(f);
- try
- {
- Writer w = new OutputStreamWriter(os,"utf-8");
- try
- {
- w.write(fileContents);
- }
- finally
- {
- w.close();
- }
- }
- finally
- {
- os.close();
- }
- }
-
protected static class DatabaseThread extends Thread
{
public DatabaseThread()
Modified: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseMySQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseMySQL.java?rev=1225802&r1=1225801&r2=1225802&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseMySQL.java (original)
+++ incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseMySQL.java Fri Dec 30 11:04:55 2011
@@ -26,78 +26,19 @@ import java.util.*;
import org.junit.*;
/** This is a testing base class that is responsible for setting up/tearing down the core MySQL database. */
-public class BaseMySQL
+public class BaseMySQL extends Base
{
protected final static String SUPER_USER_NAME = "root";
protected final static String SUPER_USER_PASSWORD = "mysql";
- protected File currentPath = null;
- protected File configFile = null;
- protected File loggingFile = null;
- protected File logOutputFile = null;
-
- protected void initialize()
- throws Exception
- {
- if (currentPath == null)
- {
- currentPath = new File(".").getCanonicalFile();
-
- // First, write a properties file and a logging file, in the current directory.
- configFile = new File("properties.xml").getCanonicalFile();
- loggingFile = new File("logging.ini").getCanonicalFile();
- logOutputFile = new File("manifoldcf.log").getCanonicalFile();
-
- // Set a system property that will point us to the proper place to find the properties file
- System.setProperty("org.apache.manifoldcf.configfile",configFile.getCanonicalFile().getAbsolutePath());
- }
- }
-
- protected boolean isInitialized()
- {
- return configFile.exists();
- }
-
- @Before
- public void setUp()
+ /** Method to add properties to properties.xml contents.
+ * Override this method to add properties clauses to the property file.
+ */
+ protected void writeProperties(StringBuilder output)
throws Exception
{
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- System.out.println("Warning: Preclean error: "+e.getMessage());
- }
- try
- {
- localSetUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
-
-
- protected void localSetUp()
- throws Exception
- {
- initialize();
- String currentPathString = currentPath.getAbsolutePath();
- writeFile(loggingFile,
- "log4j.appender.MAIN.File="+logOutputFile.getAbsolutePath().replaceAll("\\\\","/")+"\n" +
- "log4j.rootLogger=WARN, MAIN\n" +
- "log4j.appender.MAIN=org.apache.log4j.RollingFileAppender\n" +
- "log4j.appender.MAIN.layout=org.apache.log4j.PatternLayout\n" +
- "log4j.appender.MAIN.layout.ConversionPattern=%5p %d{ISO8601} (%t) - %m%n\n"
- );
-
- writeFile(configFile,
- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
- "<configuration>\n"+
+ super.writeProperties(output);
+ output.append(
" <property name=\"org.apache.manifoldcf.databaseimplementationclass\" value=\"org.apache.manifoldcf.core.database.DBInterfaceMySQL\"/>\n" +
" <property name=\"org.apache.manifoldcf.database.name\" value=\"testdb\"/>\n" +
" <property name=\"org.apache.manifoldcf.database.username\" value=\"testuser\"/>\n" +
@@ -107,74 +48,24 @@ public class BaseMySQL
" <property name=\"org.apache.manifoldcf.crawler.cleanupthreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.crawler.deletethreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.database.maxhandles\" value=\"80\"/>\n" +
- " <property name=\"org.apache.manifoldcf.database.maxquerytime\" value=\"15\"/>\n" +
- " <property name=\"org.apache.manifoldcf.logconfigfile\" value=\""+loggingFile.getAbsolutePath().replaceAll("\\\\","/")+"\"/>\n" +
- "</configuration>\n");
-
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Create the database
- ManifoldCF.createSystemDatabase(tc,SUPER_USER_NAME,SUPER_USER_PASSWORD);
-
+ " <property name=\"org.apache.manifoldcf.database.maxquerytime\" value=\"15\"/>\n"
+ );
}
-
- @After
- public void cleanUp()
+
+ /** Method to get database superuser name.
+ */
+ protected String getDatabaseSuperuserName()
throws Exception
{
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
+ return SUPER_USER_NAME;
}
-
- protected void localCleanUp()
+
+ /** Method to get database superuser password.
+ */
+ protected String getDatabaseSuperuserPassword()
throws Exception
{
- initialize();
- if (isInitialized())
- {
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Remove the database
- ManifoldCF.dropSystemDatabase(tc,SUPER_USER_NAME,SUPER_USER_PASSWORD);
-
- // Get rid of the property and logging files.
- logOutputFile.delete();
- configFile.delete();
- loggingFile.delete();
-
- ManifoldCF.resetEnvironment();
- }
+ return SUPER_USER_PASSWORD;
}
- protected static void writeFile(File f, String fileContents)
- throws IOException
- {
- OutputStream os = new FileOutputStream(f);
- try
- {
- Writer w = new OutputStreamWriter(os,"utf-8");
- try
- {
- w.write(fileContents);
- }
- finally
- {
- w.close();
- }
- }
- finally
- {
- os.close();
- }
- }
-
}
Modified: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BasePostgresql.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BasePostgresql.java?rev=1225802&r1=1225801&r2=1225802&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BasePostgresql.java (original)
+++ incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BasePostgresql.java Fri Dec 30 11:04:55 2011
@@ -26,78 +26,19 @@ import java.util.*;
import org.junit.*;
/** This is a testing base class that is responsible for setting up/tearing down the core Postgresql database. */
-public class BasePostgresql
+public class BasePostgresql extends Base
{
protected final static String SUPER_USER_NAME = "postgres";
protected final static String SUPER_USER_PASSWORD = "postgres";
-
- protected File currentPath = null;
- protected File configFile = null;
- protected File loggingFile = null;
- protected File logOutputFile = null;
-
- protected void initialize()
- throws Exception
- {
- if (currentPath == null)
- {
- currentPath = new File(".").getCanonicalFile();
- // First, write a properties file and a logging file, in the current directory.
- configFile = new File("properties.xml").getCanonicalFile();
- loggingFile = new File("logging.ini").getCanonicalFile();
- logOutputFile = new File("manifoldcf.log").getCanonicalFile();
-
- // Set a system property that will point us to the proper place to find the properties file
- System.setProperty("org.apache.manifoldcf.configfile",configFile.getCanonicalFile().getAbsolutePath());
- }
- }
-
- protected boolean isInitialized()
- {
- return configFile.exists();
- }
-
- @Before
- public void setUp()
+ /** Method to add properties to properties.xml contents.
+ * Override this method to add properties clauses to the property file.
+ */
+ protected void writeProperties(StringBuilder output)
throws Exception
{
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- System.out.println("Warning: Preclean error: "+e.getMessage());
- }
- try
- {
- localSetUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
-
-
- protected void localSetUp()
- throws Exception
- {
- initialize();
- String currentPathString = currentPath.getAbsolutePath();
- writeFile(loggingFile,
- "log4j.appender.MAIN.File="+logOutputFile.getAbsolutePath().replaceAll("\\\\","/")+"\n" +
- "log4j.rootLogger=WARN, MAIN\n" +
- "log4j.appender.MAIN=org.apache.log4j.RollingFileAppender\n" +
- "log4j.appender.MAIN.layout=org.apache.log4j.PatternLayout\n" +
- "log4j.appender.MAIN.layout.ConversionPattern=%5p %d{ISO8601} (%t) - %m%n\n"
- );
-
- writeFile(configFile,
- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
- "<configuration>\n"+
+ super.writeProperties(output);
+ output.append(
" <property name=\"org.apache.manifoldcf.databaseimplementationclass\" value=\"org.apache.manifoldcf.core.database.DBInterfacePostgreSQL\"/>\n" +
" <property name=\"org.apache.manifoldcf.database.name\" value=\"testdb\"/>\n" +
" <property name=\"org.apache.manifoldcf.database.username\" value=\"testuser\"/>\n" +
@@ -107,74 +48,24 @@ public class BasePostgresql
" <property name=\"org.apache.manifoldcf.crawler.cleanupthreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.crawler.deletethreads\" value=\"10\"/>\n" +
" <property name=\"org.apache.manifoldcf.database.maxhandles\" value=\"80\"/>\n" +
- " <property name=\"org.apache.manifoldcf.database.maxquerytime\" value=\"15\"/>\n" +
- " <property name=\"org.apache.manifoldcf.logconfigfile\" value=\""+loggingFile.getAbsolutePath().replaceAll("\\\\","/")+"\"/>\n" +
- "</configuration>\n");
-
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Create the database
- ManifoldCF.createSystemDatabase(tc,SUPER_USER_NAME,SUPER_USER_PASSWORD);
-
+ " <property name=\"org.apache.manifoldcf.database.maxquerytime\" value=\"15\"/>\n"
+ );
}
-
- @After
- public void cleanUp()
+
+ /** Method to get database superuser name.
+ */
+ protected String getDatabaseSuperuserName()
throws Exception
{
- try
- {
- localCleanUp();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
+ return SUPER_USER_NAME;
}
-
- protected void localCleanUp()
+
+ /** Method to get database superuser password.
+ */
+ protected String getDatabaseSuperuserPassword()
throws Exception
{
- initialize();
- if (isInitialized())
- {
- ManifoldCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- // Remove the database
- ManifoldCF.dropSystemDatabase(tc,SUPER_USER_NAME,SUPER_USER_PASSWORD);
-
- // Get rid of the property and logging files.
- logOutputFile.delete();
- configFile.delete();
- loggingFile.delete();
-
- ManifoldCF.resetEnvironment();
- }
+ return SUPER_USER_PASSWORD;
}
- protected static void writeFile(File f, String fileContents)
- throws IOException
- {
- OutputStream os = new FileOutputStream(f);
- try
- {
- Writer w = new OutputStreamWriter(os,"utf-8");
- try
- {
- w.write(fileContents);
- }
- finally
- {
- w.close();
- }
- }
- finally
- {
- os.close();
- }
- }
-
}