|
From: <mwl...@us...> - 2007-08-06 19:14:56
|
Revision: 460
http://cishell.svn.sourceforge.net/cishell/?rev=460&view=rev
Author: mwlinnem
Date: 2007-08-06 12:14:53 -0700 (Mon, 06 Aug 2007)
Log Message:
-----------
Initial commit for most of this. Converter Tester Phase II rough working version. Needs lots of improvement but does the basics.
Modified Paths:
--------------
trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithm.java
trunk/testing/org.cishell.testing.convertertester.commandline/src/org/cishell/testing/convertertester/commandline/Activator.java
trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester/ConverterTester.java
Added Paths:
-----------
trunk/testing/org.cishell.testing.convertertester.commandline/src/org/cishell/testing/convertertester/commandline/OldActivator.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/test_files/filetypes.conf
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester/OldTestResult.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/ConverterTester2.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/DefaultTestRunner.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestConfigData.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestFileKeeper.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestResult.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestRunner.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/ComparePhaseFailure.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/ConvertPhaseFailure.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/FilePassResult.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/FilePassSuccess.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/IdsNotPreservedComparer.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/IdsPreservedComparer.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/LossyComparer.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/NewGraphComparer.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/SimpleGraphComparer.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/ConvResultGenerator.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/ConverterReportGenerator.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/OverviewReportGenerator.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/ReportGenerator.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/SampleResultReportGenerator.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/TestSuiteReportGenerator.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/results/
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/results/ConvBasedResult.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/results/ConvFailureInfo.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/results/ConvFilePass.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/results/ConvFilePassFailure.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/reportgen/results/ConvFilePassSuccess.java
Modified: trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithm.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithm.java 2007-08-06 15:41:41 UTC (rev 459)
+++ trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithm.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -6,45 +6,55 @@
import org.cishell.framework.CIShellContext;
import org.cishell.framework.algorithm.Algorithm;
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.algorithm.AlgorithmProperty;
+import org.cishell.framework.data.BasicData;
import org.cishell.framework.data.Data;
-import org.cishell.testing.convertertester.core.tester.ConverterTester;
+import org.cishell.framework.data.DataProperty;
+import org.cishell.testing.convertertester.core.tester2.ConverterTester2;
+import org.cishell.testing.convertertester.core.tester2.reportgen.ConverterReportGenerator;
+import org.cishell.testing.convertertester.core.tester2.reportgen.OverviewReportGenerator;
+import org.cishell.testing.convertertester.core.tester2.reportgen.ReportGenerator;
+import org.cishell.testing.convertertester.core.tester2.reportgen.SampleResultReportGenerator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
-//TODO: OMG Fix this whole thing as soon as possible.
+//TODO: Only just barely usable to run converter tester from GUI.
+//TODO: Make it nice eventually
-public class ConverterTesterAlgorithm implements Algorithm {
+public class ConverterTesterAlgorithm implements Algorithm, AlgorithmProperty {
private static File currentDir;
- Data[] data;
- Dictionary parameters;
- CIShellContext context;
- ConverterTester tester;
+ private Data[] data;
+ private Dictionary parameters;
+ private CIShellContext cContext;
+ private BundleContext bContext;
+ private LogService logger;
public ConverterTesterAlgorithm(Data[] data, Dictionary parameters,
- CIShellContext csContext, BundleContext bContext ) {
+ CIShellContext cContext, BundleContext bContext ) {
this.data = data;
this.parameters = parameters;
- this.context = csContext;
+ this.cContext = cContext;
+ this.bContext = bContext;
- this.tester = new ConverterTester(bContext, csContext);
-// ServiceReference ctReference = bContext.getServiceReference(ConverterTester.class.getName());
-// this.tester = (ConverterTester) bContext.getService(ctReference);
+ this.logger = (LogService) cContext.getService(
+ LogService.class.getName());
}
public Data[] execute() {
-// int counter = PlatformUI.getWorkbench().getWorkbenchWindowCount();
-// System.out.println("counter is "+counter);
-// ?? why getActiveWorkbenchWindow() didn't work??
Data[] returnDM;
final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
- if (windows.length ==0){
+ if (windows.length == 0) {
return null;
}
@@ -103,21 +113,71 @@
}
}
dialog.setFilterPath(currentDir.getPath());
- dialog.setText("Select a File");
+ dialog.setText("Select a File: Too bad we aren't using it, haha!");
String fileName = dialog.open();
if (fileName == null) {
return;
}
-
- File file = new File(fileName);
try {
- tester.runTests(file);
+ ConverterTester2 ct = new ConverterTester2(logger);
+ ServiceReference[] refs = getServiceReferences();
+ OverviewReportGenerator overviewGen =
+ new OverviewReportGenerator();
+ SampleResultReportGenerator sampleGen =
+ new SampleResultReportGenerator(10, 5);
+ ConverterReportGenerator convGen =
+ new ConverterReportGenerator();
+
+ ct.execute(refs, cContext, bContext, logger,
+ new ReportGenerator[] {overviewGen, sampleGen, convGen});
+
+ File overviewReport = overviewGen.getReport();
+ BasicData overviewReportData =
+ createReportData(overviewReport, "Overview");
+ returnList.add(overviewReportData);
+
+
+ File sampleReport = sampleGen.getReport();
+ BasicData sampleReportData =
+ createReportData(sampleReport, "Sample Test Results");
+ returnList.add(sampleReportData);
+
+
+ File convReport = convGen.getReport();
+ BasicData convReportData =
+ createReportData(convReport, "Basic Converter Results");
+ returnList.add(convReportData);
+
} catch (Exception e) {
System.out.println("Why oh why am I catching type Exception?");
System.out.println(e);
+ e.printStackTrace();
}
}
}
+ private BasicData createReportData(Object report, String label) {
+ BasicData reportData = new BasicData(report, "file:text/plain");
+ Dictionary metadata = reportData.getMetaData();
+ metadata.put(DataProperty.LABEL, label);
+ metadata.put(DataProperty.TYPE, DataProperty.TEXT_TYPE);
+ return reportData;
+ }
+
+ private ServiceReference[] getServiceReferences() {
+ String filter = "(&("+ALGORITHM_TYPE+"="+TYPE_CONVERTER+"))";// +
+
+ try {
+ ServiceReference[] refs = bContext.getServiceReferences(
+ AlgorithmFactory.class.getName(), filter);
+
+ return refs;
+ } catch (InvalidSyntaxException e) {
+ System.out.println("OOPS!");
+ System.out.println(e);
+ return null;
+ }
+ }
+
}
\ No newline at end of file
Modified: trunk/testing/org.cishell.testing.convertertester.commandline/src/org/cishell/testing/convertertester/commandline/Activator.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.commandline/src/org/cishell/testing/convertertester/commandline/Activator.java 2007-08-06 15:41:41 UTC (rev 459)
+++ trunk/testing/org.cishell.testing.convertertester.commandline/src/org/cishell/testing/convertertester/commandline/Activator.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -6,16 +6,24 @@
import org.cishell.framework.CIShellContext;
import org.cishell.framework.LocalCIShellContext;
-import org.cishell.testing.convertertester.core.tester.ConverterTester;
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.algorithm.AlgorithmProperty;
+import org.cishell.testing.convertertester.core.tester2.ConverterTester2;
+import org.cishell.testing.convertertester.core.tester2.reportgen.OverviewReportGenerator;
+import org.cishell.testing.convertertester.core.tester2.reportgen.ReportGenerator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
-public class Activator implements BundleActivator{
- private ConverterTester ct;
+public class Activator implements BundleActivator, AlgorithmProperty {
+ private ConverterTester2 ct;
private BundleContext b;
private CIShellContext c;
private File configFile;
+ private LogService logger;
public static final String QUIT = "q";
@@ -23,11 +31,27 @@
this.b = b;
this.c = new LocalCIShellContext(b);
+ this.logger = (LogService) c.getService(
+ LogService.class.getName());
startCommandLine();
}
+ public ServiceReference[] getServiceReferences() {
+ String filter = "(&("+ALGORITHM_TYPE+"="+TYPE_CONVERTER+"))";// +
+ try {
+ ServiceReference[] refs = b.getServiceReferences(
+ AlgorithmFactory.class.getName(), filter);
+
+ return refs;
+ } catch (InvalidSyntaxException e) {
+ System.out.println("OOPS!");
+ System.out.println(e);
+ return null;
+ }
+ }
+
public void stop(BundleContext b){
System.out.println("Goodbye!");
@@ -62,29 +86,17 @@
}
}
- private void processConfigurationFile(File f)
- throws FileNotFoundException {
+ private void processConfigurationFile(File f) throws FileNotFoundException {
System.out.println("Processing " + f.getName());
- if(!f.isHidden() && (f.getName().charAt(0) != '.')){
- if(f.isDirectory()){
- File[] files = f.listFiles();
- for (int ii = 0; ii < files.length; ii++) {
- File ff = files[ii];
- processConfigurationFile(ff);
- }
- }
- else{
- try{
- ct = new ConverterTester(b, c, f);
- System.out.println(ct);
- ct.testFiles();
- ct.printResults();
- }catch(Exception ex){
- System.out.println("Failed to create " +
- "ConverterTester\n\n");
- ex.printStackTrace();
- }
- }
+ try {
+ ServiceReference[] refs = getServiceReferences();
+ ct = new ConverterTester2(this.logger);
+ ReportGenerator overview = new OverviewReportGenerator();
+ ct.execute(refs, c, b, logger, new ReportGenerator[] {overview});
+ System.out.println(ct);
+ } catch (Exception ex) {
+ System.out.println("Failed to create " + "ConverterTester\n\n");
+ ex.printStackTrace();
}
}
}
Added: trunk/testing/org.cishell.testing.convertertester.commandline/src/org/cishell/testing/convertertester/commandline/OldActivator.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.commandline/src/org/cishell/testing/convertertester/commandline/OldActivator.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.commandline/src/org/cishell/testing/convertertester/commandline/OldActivator.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,91 @@
+package org.cishell.testing.convertertester.commandline;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Scanner;
+
+import org.cishell.framework.CIShellContext;
+import org.cishell.framework.LocalCIShellContext;
+import org.cishell.testing.convertertester.core.tester.ConverterTester;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+
+public class OldActivator implements BundleActivator{
+ private ConverterTester ct;
+ private BundleContext b;
+ private CIShellContext c;
+ private File configFile;
+
+ public static final String QUIT = "q";
+
+ public void start(BundleContext b){
+ this.b = b;
+ this.c = new LocalCIShellContext(b);
+
+ startCommandLine();
+ }
+
+
+
+ public void stop(BundleContext b){
+ System.out.println("Goodbye!");
+
+ b = null;
+ c = null;
+ configFile = null;
+ ct = null;
+ }
+
+ public void startCommandLine(){
+ Scanner in = new Scanner(System.in);
+ while(true) {
+ System.out.println("Welcome to NWB's Converter Tester");
+ System.out.println( "Please enter the name of a configuration " +
+ "file or\n a directory of configuration files (" + QUIT +
+ ") to quit): ");
+
+ String s = in.nextLine();
+ if(s.trim().equalsIgnoreCase(QUIT))
+ break;
+ try{
+ configFile = new File(s);
+ processConfigurationFile(configFile);
+ }
+ catch (NullPointerException ex){
+ System.out.println("Invalid file name");;
+ }
+ catch(FileNotFoundException fnfe){
+ System.out.println("Could not find the specified " +
+ "configuration file");
+ }
+ }
+ }
+
+ private void processConfigurationFile(File f)
+ throws FileNotFoundException {
+ System.out.println("Processing " + f.getName());
+ if(!f.isHidden() && (f.getName().charAt(0) != '.')){
+ if(f.isDirectory()){
+ File[] files = f.listFiles();
+ for (int ii = 0; ii < files.length; ii++) {
+ File ff = files[ii];
+ processConfigurationFile(ff);
+ }
+ }
+ else{
+ try{
+ ct = new ConverterTester(b, c, f);
+ System.out.println(ct);
+ ct.testFiles();
+ ct.printResults();
+ }catch(Exception ex){
+ System.out.println("Failed to create " +
+ "ConverterTester\n\n");
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+}
+
Modified: trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF 2007-08-06 15:41:41 UTC (rev 459)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF 2007-08-06 19:14:53 UTC (rev 460)
@@ -15,4 +15,7 @@
org.osgi.service.metatype;version="1.1.0",
org.osgi.service.prefs;version="1.1.0"
Require-Bundle: org.prefuse.lib
-Export-Package: org.cishell.testing.convertertester.core.tester
+Export-Package: org.cishell.testing.convertertester.core.tester,
+ org.cishell.testing.convertertester.core.tester2,
+ org.cishell.testing.convertertester.core.tester2.reportgen,
+ org.cishell.testing.convertertester.core.tester2.reportgen.results
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/test_files/filetypes.conf
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/test_files/filetypes.conf (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/test_files/filetypes.conf 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,6 @@
+file:text/edge=Edge Files
+file:text/graphml+xml=GraphML Files
+file:application/pajek=Net Files
+file:text/nwb=NWB Files
+file:text/treeml+xml=TreeML Files
+file:text/xgmml_xml=XGMML Files
Modified: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester/ConverterTester.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester/ConverterTester.java 2007-08-06 15:41:41 UTC (rev 459)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester/ConverterTester.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -121,6 +121,7 @@
System.out.println("Converting " + f.getCanonicalPath());
Data inData = new BasicData(f.getCanonicalPath(),"");
Data dm = cnv.convert(inData);
+
if(dm != null){
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester/OldTestResult.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester/OldTestResult.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester/OldTestResult.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,17 @@
+package org.cishell.testing.convertertester.core.tester;
+
+public abstract class OldTestResult {
+ public abstract String getType();
+ public abstract String[] getTestConverterNames();
+ public abstract String[] getComparisonConverterNames();
+
+ public boolean hasExplanation() {return false;}
+ public boolean hasFailedConverterName() {return false;}
+ public boolean hasOriginalGraphName() {return false;}
+ public boolean hasResultingGraphNames() {return false;}
+
+ public String getExplanation() {return "";}
+ public String getFailedConverterName() {return "";}
+ public String getOriginalGraphName() {return "";}
+ public String[] getResultGraphNames() {return new String[0];}
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/ConverterTester2.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/ConverterTester2.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/ConverterTester2.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,214 @@
+package org.cishell.testing.convertertester.core.tester2;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.cishell.framework.CIShellContext;
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.algorithm.AlgorithmProperty;
+import org.cishell.framework.data.BasicData;
+import org.cishell.framework.data.Data;
+import org.cishell.testing.convertertester.core.converter.graph.ConverterGraph;
+import org.cishell.testing.convertertester.core.converter.graph.ConverterPath;
+import org.cishell.testing.convertertester.core.tester2.filepassresults.FilePassResult;
+import org.cishell.testing.convertertester.core.tester2.graphcomparison.IdsNotPreservedComparer;
+import org.cishell.testing.convertertester.core.tester2.graphcomparison.IdsPreservedComparer;
+import org.cishell.testing.convertertester.core.tester2.graphcomparison.LossyComparer;
+import org.cishell.testing.convertertester.core.tester2.graphcomparison.NewGraphComparer;
+import org.cishell.testing.convertertester.core.tester2.reportgen.ReportGenerator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+/**
+ * Test Suites are arrays of test paths, where each test path starts
+ * from the same file format.
+ *
+ * Compare Paths are paths of converters that convert from the original file
+ * format to the in-memory comparison format. For each test suite there
+ * is a single corresponding compare path.
+ *
+ * @author mwlinnem
+ *
+ */
+public class ConverterTester2 implements AlgorithmProperty {
+
+ private LogService log;
+
+ private TestFileKeeper testFileKeeper;
+ private TestRunner testRunner;
+
+
+ public ConverterTester2(LogService log) {
+ this.log = log;
+ this.testFileKeeper =
+ new TestFileKeeper(TestFileKeeper.DEFAULT_ROOT_DIR, log);
+ this.testRunner = new DefaultTestRunner(log);
+ }
+
+
+ /**
+ * Tests the provided converters, and passes the results of those tests to
+ * the report generators. Report Generators are side-effected, which takes
+ * the place of a return value.
+ *
+ * @param converterRefs the converters to be tested
+ * @param cContext the CIShell Context
+ * @param bContext the Bundle Context
+ * @param log The log written to should an error occur (other than the
+ * errors resulting from the converters, which are included in the test
+ * results)
+ * @param reportGenerators process the test results.
+ */
+ public void execute(ServiceReference[] converterRefs,
+ CIShellContext cContext,
+ BundleContext bContext,
+ LogService log,
+ ReportGenerator[] reportGenerators) {
+
+ this.log = log;
+
+ //generate test paths
+
+ ConverterGraph converterGraph = new ConverterGraph(converterRefs);
+
+ ConverterPath[][] testSuites = converterGraph.getTestPaths();
+ ConverterPath[] comparePaths = converterGraph.getComparePaths();
+
+ //run tests on test paths
+
+ TestResult[] results = runTests(testSuites, comparePaths,
+ cContext, bContext);
+
+ //generate reports based on test results
+
+ for (int ii = 0; ii < reportGenerators.length; ii++) {
+ ReportGenerator reportGenerator = reportGenerators[ii];
+
+ reportGenerator.generateReport(results);
+ }
+ }
+
+
+ public TestResult[] runTests(ConverterPath[][] testSuites,
+ ConverterPath[] comparePaths, CIShellContext cContext,
+ BundleContext bContext) {
+
+ List testResults = new ArrayList();
+
+ for (int ii = 0; ii < testSuites.length; ii++) {
+ ConverterPath[] testSuite = testSuites[ii];
+ ConverterPath testSuiteComparePath = comparePaths[ii];
+
+ for (int jj = 0; jj < testSuite.length; jj++) {
+ ConverterPath testPath = testSuite[jj];
+
+ TestResult testResult = runATest(testPath,
+ testSuiteComparePath, cContext, bContext);
+
+ if (testResult != null) {
+ testResults.add(testResult);
+ }
+ }
+
+ }
+
+ return (TestResult[]) testResults.toArray(new TestResult[0]);
+ }
+
+
+ private TestResult runATest(ConverterPath testConvs,
+ ConverterPath comparisonConvs, CIShellContext cContext,
+ BundleContext bContext) {
+
+ ServiceReference[] testConvRefs = testConvs.getPathAsArray();
+ ServiceReference[] compareConvRefs = comparisonConvs.getPathAsArray();
+
+ AlgorithmFactory[] testConvAlgs = extractAlgorithms(
+ testConvRefs, bContext);
+ AlgorithmFactory[] compareConvAlgs = extractAlgorithms(
+ compareConvRefs, bContext);
+
+ if (testConvRefs.length <= 0) {
+ System.out.println("Must have at least one test converter..");
+ return null;
+ }
+
+ //get test files corresponding to the format these converters accept.
+
+ String fileFormat =
+ (String) testConvRefs[0].getProperty(AlgorithmProperty.OUT_DATA);
+ String[] testFilePaths = testFileKeeper.getTestFilePaths(fileFormat);
+ Data[][] fileData = wrapInData(testFilePaths, fileFormat);
+
+ //determine how we will compare the graphs
+
+ boolean areLossy = areLossy(testConvRefs) && areLossy(compareConvRefs);
+ boolean preserveIds = false; //TODO: determine this somehow
+ NewGraphComparer comparer = getComparer(areLossy, preserveIds);
+
+ //pack all the data relevant to the test into a single object.
+ TestConfigData testData = new TestConfigData(comparer, testConvAlgs,
+ compareConvAlgs, cContext, fileData);
+
+ //run the test
+ FilePassResult[] results = this.testRunner.runTest(testData);
+
+ //return the results of the test
+ return new TestResult(results);
+ }
+
+
+ private AlgorithmFactory[] extractAlgorithms(ServiceReference[] convRefs,
+ BundleContext bContext) {
+ AlgorithmFactory[] results = new AlgorithmFactory[convRefs.length];
+ for (int ii = 0; ii < convRefs.length; ii++) {
+ results[ii] = (AlgorithmFactory) bContext.getService(convRefs[ii]);
+ }
+ return results;
+ }
+
+
+ private Data[][] wrapInData(String[] testFilePaths, String format) {
+
+ Data[][] results = new Data[testFilePaths.length][1];
+ for (int ii = 0; ii < testFilePaths.length; ii++) {
+ String filePath = testFilePaths[ii];
+
+ results[ii] =
+ new Data[] {new BasicData(new File(filePath), format)};
+ }
+
+ return results;
+ }
+
+
+ private boolean areLossy(ServiceReference[] refs) {
+
+ String lossiness = LOSSLESS;
+ for (int i=0; i < refs.length; i++) {
+ if (LOSSY.equals(refs[i].getProperty(CONVERSION))) {
+ lossiness = LOSSY;
+ }
+ }
+
+ boolean result = lossiness.equals(LOSSY);
+ return result;
+ }
+
+
+ private NewGraphComparer getComparer(boolean areLossy,
+ boolean idsPreserved) {
+
+ if (areLossy) {
+ return new LossyComparer();
+ } else if (! idsPreserved) {
+ return new IdsNotPreservedComparer();
+ } else {
+ return new IdsPreservedComparer();
+ }
+ }
+
+
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/DefaultTestRunner.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/DefaultTestRunner.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/DefaultTestRunner.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,219 @@
+package org.cishell.testing.convertertester.core.tester2;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.cishell.framework.algorithm.Algorithm;
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.data.BasicData;
+import org.cishell.framework.data.Data;
+import org.cishell.testing.convertertester.core.tester.graphcomparison.ComparisonResult;
+import org.cishell.testing.convertertester.core.tester2.filepassresults.ComparePhaseFailure;
+import org.cishell.testing.convertertester.core.tester2.filepassresults.ConvertPhaseFailure;
+import org.cishell.testing.convertertester.core.tester2.filepassresults.FilePassResult;
+import org.cishell.testing.convertertester.core.tester2.filepassresults.FilePassSuccess;
+import org.cishell.testing.convertertester.core.tester2.graphcomparison.NewGraphComparer;
+import org.cishell.testing.convertertester.core.tester2.reportgen.results.ConvFailureInfo;
+import org.osgi.service.log.LogService;
+
+import prefuse.data.Graph;
+
+public class DefaultTestRunner implements TestRunner {
+
+ private LogService log;
+
+ public DefaultTestRunner(LogService log) {
+ this.log = log;
+ }
+
+ public FilePassResult[] runTest(TestConfigData testData) {
+
+ Data[][] testFileData = testData.getTestFileData();
+ AlgorithmFactory[] testConverters = testData.getTestConverters();
+ AlgorithmFactory[] comparisonConverters = testData
+ .getComparisonConverters();
+
+
+ // list of FilePassResult
+ final List testResults = new ArrayList();
+
+ for (int ii = 0; ii < testFileData.length; ii++) {
+ Data[] originalFileData = testFileData[ii];
+
+ // test conversion phase
+
+ ConvertResult testPhaseResult = convert(originalFileData,
+ testConverters, testData);
+
+ if (!testPhaseResult.succeeded()) {
+ ConvertPhaseFailure failure = new ConvertPhaseFailure(
+ originalFileData, testConverters, comparisonConverters,
+ testPhaseResult.getFailInfo(),
+ ConvertPhaseFailure.TEST_PHASE);
+ testResults.add(failure);
+ continue;
+ }
+ Data[] resultFileData = testPhaseResult.getResult();
+
+ // comparison conversion phase
+
+ ConvertResult comparisonPhaseResult1 = convert(originalFileData,
+ comparisonConverters, testData);
+
+ if (!comparisonPhaseResult1.succeeded()) {
+ ConvertPhaseFailure failure = new ConvertPhaseFailure(
+ originalFileData, testConverters, comparisonConverters,
+ comparisonPhaseResult1.getFailInfo(),
+ ConvertPhaseFailure.TEST_PHASE);
+ testResults.add(failure);
+ continue;
+ }
+ Data[] originalInMemory = comparisonPhaseResult1.getResult();
+
+ ConvertResult comparisonPhaseResult2 = convert(resultFileData,
+ comparisonConverters, testData);
+
+ if (!comparisonPhaseResult2.succeeded()) {
+ ConvertPhaseFailure failure = new ConvertPhaseFailure(
+ originalFileData, testConverters, comparisonConverters,
+ comparisonPhaseResult2.getFailInfo(),
+ ConvertPhaseFailure.COMPARISON_PHASE);
+ testResults.add(failure);
+ continue;
+ }
+ Data[] resultInMemory = comparisonPhaseResult2.getResult();
+
+ // graph comparison phase
+
+ Graph origGraph = (Graph) resultInMemory[0].getData();
+ Graph resultGraph = (Graph) originalInMemory[0].getData();
+
+ NewGraphComparer comparer = testData.getComparer();
+ ComparisonResult graphComparisonPhaseResult = comparer.compare(
+ origGraph, resultGraph);
+
+ if (!graphComparisonPhaseResult.comparisonSucceeded()) {
+ String explanation = graphComparisonPhaseResult.getLog();
+ ComparePhaseFailure failure = new ComparePhaseFailure(
+ originalFileData, testConverters, comparisonConverters,
+ explanation);
+ testResults.add(failure);
+ continue;
+ }
+
+ FilePassSuccess success = new FilePassSuccess(originalFileData,
+ testConverters, comparisonConverters);
+ testResults.add(success);
+ }
+
+ FilePassResult[] result = new FilePassResult[testResults.size()];
+ result = (FilePassResult[]) testResults.toArray(result);
+ return result;
+ }
+
+ private ConvertResult convert(Data[] startData,
+ AlgorithmFactory[] converters, TestConfigData testData) {
+
+ // validator takes a string file path, all others just take files or
+ // graphs or whatever);
+ Data[] currentData = getFilePathData(startData);
+
+ AlgorithmFactory currentConverter = converters[0];
+ try {
+ for (int ii = 0; ii < converters.length; ii++) {
+ currentConverter = converters[ii];
+ Algorithm currentAlgorithm = currentConverter.createAlgorithm(
+ currentData, new Hashtable(), testData.getContext());
+ currentData = currentAlgorithm.execute();
+
+ if (currentData == null) {
+ ConvFailureInfo failInfo = new ConvFailureInfo(
+ "null result data", currentConverter);
+ ConvertResult result = new ConvertResult(failInfo);
+ return result;
+ }
+
+ BasicData currentDataImpl = (BasicData) currentData[0];
+ if (currentDataImpl.getData() == null) {
+ ConvFailureInfo failInfo = new ConvFailureInfo(
+ "null result data contents", currentConverter);
+ ConvertResult result = new ConvertResult(failInfo);
+ return result;
+ }
+ }
+ } catch (Throwable t) {
+ ConvFailureInfo failInfo = new ConvFailureInfo(t.toString()
+ + getStackTrace(t), currentConverter);
+ ConvertResult result = new ConvertResult(failInfo);
+ return result;
+ }
+
+ Data[] resultData = currentData;
+ ConvertResult result = new ConvertResult(resultData);
+ return result;
+ }
+
+ private class ConvertResult {
+
+ private boolean succeeded;
+
+ private Data[] result;
+
+ private ConvFailureInfo failInfo;
+
+ public ConvertResult(Data[] result) {
+ this.result = result;
+
+ this.succeeded = true;
+ }
+
+ public ConvertResult(ConvFailureInfo failInfo) {
+ this.failInfo = failInfo;
+
+ this.succeeded = false;
+ }
+
+ public boolean succeeded() {
+ return this.succeeded;
+ }
+
+ public Data[] getResult() {
+ return result;
+ }
+
+ public ConvFailureInfo getFailInfo() {
+ return this.failInfo;
+ }
+ }
+
+ private String getStackTrace(Throwable t) {
+ final Writer writer = new StringWriter();
+ final PrintWriter printWriter = new PrintWriter(writer);
+ t.printStackTrace(printWriter);
+ return writer.toString();
+
+ }
+
+ private Data[] getFilePathData(Data[] fileData) {
+ BasicData basicData = (BasicData) fileData[0];
+ String format = basicData.getFormat();
+ File actualFile = (File) basicData.getData();
+ try {
+ String filePath = actualFile.getCanonicalPath();
+ BasicData result = new BasicData(filePath, format);
+ return new Data[] { result };
+ } catch (IOException e) {
+ System.out.println(e);
+ e.printStackTrace();
+
+ return null;
+ }
+
+ }
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestConfigData.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestConfigData.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestConfigData.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,48 @@
+package org.cishell.testing.convertertester.core.tester2;
+
+import org.cishell.framework.CIShellContext;
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.data.Data;
+import org.cishell.testing.convertertester.core.tester2.graphcomparison.NewGraphComparer;
+
+public class TestConfigData {
+
+ private NewGraphComparer comparer;
+ private AlgorithmFactory[] testConverters;
+ private AlgorithmFactory[] comparisonConverters;
+ private CIShellContext context;
+ private Data[][] testFileData;
+
+ public TestConfigData(NewGraphComparer comparer,
+ AlgorithmFactory[] testConverters,
+ AlgorithmFactory[] comparisonConverters,
+ CIShellContext context,
+ Data[][] testFileData) {
+ this.comparer = comparer;
+ this.testConverters = testConverters;
+ this.comparisonConverters = comparisonConverters;
+ this.context = context;
+ this.testFileData = testFileData;
+ }
+
+ public NewGraphComparer getComparer() {
+ return this.comparer;
+ }
+
+ public AlgorithmFactory[] getComparisonConverters() {
+ return this.comparisonConverters;
+ }
+
+ public CIShellContext getContext() {
+ return this.context;
+ }
+
+ public AlgorithmFactory[] getTestConverters() {
+ return this.testConverters;
+ }
+
+ public Data[][] getTestFileData() {
+ return this.testFileData;
+ }
+
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestFileKeeper.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestFileKeeper.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestFileKeeper.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,102 @@
+package org.cishell.testing.convertertester.core.tester2;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.osgi.service.log.LogService;
+
+public class TestFileKeeper {
+
+ public static final String DEFAULT_ROOT_DIR = "workspace/org.cishell."
+ + "testing.convertertester.core.new/src/org/cishell/testing/"
+ + "convertertester/core/test_files/";
+
+ public static final String CONF_FILE_NAME = "filetypes.conf";
+
+ public static final Pattern LINE_FORMAT =
+ Pattern.compile("^file:[^=]*?=[^=]*$");
+
+ private Map formatToDir = new HashMap();
+ private LogService log;
+
+ public TestFileKeeper(String rootDir, LogService log) {
+ this.log = log;
+
+ String line;
+ BufferedReader reader = null;
+ try {
+ String filePath = System.getProperty("user.home") + "/" +
+ rootDir + CONF_FILE_NAME;
+ reader = new BufferedReader(new FileReader(filePath));
+ while ((line = reader.readLine()) != null) {
+
+ Matcher matcher = LINE_FORMAT.matcher(line);
+ if (matcher.matches()) {
+ String[] splitLine = line.split("=");
+
+ String fileFormat = splitLine[0];
+ String dir = splitLine[1];
+
+ String testFilePath = System.getProperty("user.home") +
+ "/" + rootDir + dir;
+
+ formatToDir.put(fileFormat, testFilePath);
+ } else {
+ this.log.log(LogService.LOG_ERROR, "the line '" + line +
+ "' is not formatted correctly");
+ }
+ }
+ } catch (IOException e) {
+ this.log.log(LogService.LOG_ERROR, "Incorrect directory for " +
+ "test file specified", e);
+ e.printStackTrace();
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ this.log.log(LogService.LOG_ERROR, "Cannot close reader.",
+ e);
+ }
+ }
+ }
+ }
+
+ //TODO: maybe make it cache the files instead of getting them every time?
+ public String[] getTestFilePaths(String format) {
+
+ List results = new ArrayList();
+
+ String testFileDirPath = (String) this.formatToDir.get(format);
+ if (testFileDirPath == null) {
+ this.log.log(LogService.LOG_ERROR, "Could not load directory " +
+ "for files of format " + format);
+ return new String[0];
+ }
+ File testFileDir = new File(testFileDirPath);
+ File[] dirContents = testFileDir.listFiles();
+
+ for (int ii = 0; ii < dirContents.length; ii++) {
+ if (! dirContents[ii].isHidden()) {
+ try {
+ String fullTestFilePath = dirContents[ii].getCanonicalPath();
+ results.add(fullTestFilePath);
+ } catch (IOException e) {
+ this.log.log(LogService.LOG_ERROR, "Could not open " +
+ "file " + dirContents[ii], e);
+ }
+ }
+ }
+
+ return (String[]) results.toArray(new String[0]);
+ }
+
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestResult.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestResult.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestResult.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,77 @@
+package org.cishell.testing.convertertester.core.tester2;
+
+import org.cishell.testing.convertertester.core.tester2.filepassresults.FilePassResult;
+
+public class TestResult {
+
+ private FilePassResult[] fprs;
+
+ private boolean cachedSuccesses = false;
+ private boolean[] successes;
+
+
+
+ public TestResult(FilePassResult[] fprs) {
+ this.fprs = fprs;
+ this.successes = new boolean[fprs.length];
+ }
+
+ public FilePassResult[] getFilePassResults() {
+ return fprs;
+ }
+
+ public boolean allSucceeded() {
+ if (! cachedSuccesses) cacheSuccesses();
+
+ boolean allSucceeded = true;
+ for (int ii = 0; ii < successes.length; ii++) {
+ if (successes[ii] == false) {
+ allSucceeded = false;
+ break;
+ }
+ }
+
+ return allSucceeded;
+ }
+
+ public boolean allFailed() {
+ if (! cachedSuccesses) cacheSuccesses();
+
+ boolean allFailed = true;
+ for (int ii = 0; ii < successes.length; ii++) {
+ if (successes[ii] == true) {
+ allFailed = false;
+ break;
+ }
+ }
+
+ return allFailed;
+ }
+
+ public boolean someSucceeded() {
+ return ! allFailed();
+ }
+
+ public boolean someFailed() {
+ return ! allSucceeded();
+ }
+
+ private void cacheSuccesses() {
+ for (int ii = 0; ii < fprs.length; ii++) {
+ FilePassResult fpr = fprs[ii];
+
+ if (fpr.getType().equals(FilePassResult.SUCCESS)) {
+ this.successes[ii] = true;
+ } else {
+ this.successes[ii] = false;
+ }
+ }
+
+ this.cachedSuccesses = true;
+ }
+
+
+
+
+
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestRunner.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestRunner.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/TestRunner.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,7 @@
+package org.cishell.testing.convertertester.core.tester2;
+
+import org.cishell.testing.convertertester.core.tester2.filepassresults.FilePassResult;
+
+public interface TestRunner {
+ public FilePassResult[] runTest(TestConfigData testData);
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/ComparePhaseFailure.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/ComparePhaseFailure.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/ComparePhaseFailure.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,27 @@
+package org.cishell.testing.convertertester.core.tester2.filepassresults;
+
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.data.Data;
+
+public class ComparePhaseFailure extends FilePassResult {
+
+ private String explanation;
+
+ public ComparePhaseFailure(
+ Data[] originalData,
+ AlgorithmFactory[] testConverters,
+ AlgorithmFactory[] comparisonConverters,
+ String explanation) {
+ super(originalData, testConverters, comparisonConverters);
+ this.explanation = explanation;
+ }
+
+ public String getExplanation() {
+ return this.explanation;
+ }
+
+ public String getType() {
+ return FilePassResult.COMPARE_FAILURE;
+ }
+
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/ConvertPhaseFailure.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/ConvertPhaseFailure.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/ConvertPhaseFailure.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,44 @@
+package org.cishell.testing.convertertester.core.tester2.filepassresults;
+
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.data.Data;
+import org.cishell.testing.convertertester.core.tester2.reportgen.results.ConvFailureInfo;
+
+public class ConvertPhaseFailure extends FilePassResult {
+
+ public static final String TEST_PHASE = "test conversion phase";
+ public static final String COMPARISON_PHASE = "comparison conversion phase";
+
+ private String explanation;
+ private AlgorithmFactory failedConverter;
+ private String phase;
+
+ public ConvertPhaseFailure(
+ Data[] originalData,
+ AlgorithmFactory[] testConverters,
+ AlgorithmFactory[] comparisonConverters,
+ ConvFailureInfo convertFailInfo,
+ String phase) {
+ super(originalData, testConverters, comparisonConverters);
+ this.explanation = convertFailInfo.getExplanation();
+ this.failedConverter = convertFailInfo.getFailedConverter();
+ this.phase = phase;
+ }
+
+ public String getPhase() {
+ return this.phase;
+ }
+
+ public String getExplanation() {
+ return this.explanation;
+ }
+
+ public AlgorithmFactory getFailedConverter() {
+ return this.failedConverter;
+ }
+
+ public String getType() {
+ return FilePassResult.CONVERT_FAILURE;
+ }
+
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/FilePassResult.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/FilePassResult.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/FilePassResult.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,60 @@
+package org.cishell.testing.convertertester.core.tester2.filepassresults;
+
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.data.Data;
+
+public abstract class FilePassResult {
+
+ public static final String SUCCESS = "success";
+ public static final String CONVERT_FAILURE = "convert failure";
+ public static final String COMPARE_FAILURE = "compare failure";
+
+ private AlgorithmFactory[] testConverters;
+ private AlgorithmFactory[] comparisonConverters;
+ private AlgorithmFactory[] allConverters;
+ private Data[] originalData;
+
+ public FilePassResult(
+ Data[] originalData,
+ AlgorithmFactory[] testConverters,
+ AlgorithmFactory[] comparisonConverters) {
+ this.originalData = originalData;
+ this.testConverters = testConverters;
+ this.comparisonConverters = comparisonConverters;
+ }
+
+ public AlgorithmFactory[] getTestConverters() {
+ return this.testConverters;
+ }
+
+ public AlgorithmFactory[] getComparisonConverters() {
+ return this.comparisonConverters;
+ }
+
+ public AlgorithmFactory[] getAllConverters() {
+ if (this.allConverters == null) {
+ initializeAllConverters();
+ }
+
+ return this.allConverters;
+ }
+
+ public Data[] getOriginalData() {
+ return this.originalData;
+ }
+
+ public abstract String getType();
+
+ private void initializeAllConverters() {
+ this.allConverters = new AlgorithmFactory[testConverters.length +
+ comparisonConverters.length];
+ for (int ii = 0; ii < testConverters.length; ii++) {
+ allConverters[ii] = testConverters[ii];
+ }
+
+ int startIndex = testConverters.length;
+ for (int ii = startIndex; ii < startIndex + comparisonConverters.length; ii++) {
+ allConverters[ii] = comparisonConverters[ii - startIndex];
+ }
+ }
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/FilePassSuccess.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/FilePassSuccess.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/filepassresults/FilePassSuccess.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,18 @@
+package org.cishell.testing.convertertester.core.tester2.filepassresults;
+
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.data.Data;
+
+public class FilePassSuccess extends FilePassResult {
+
+ public FilePassSuccess(
+ Data[] originalData,
+ AlgorithmFactory[] testConverters,
+ AlgorithmFactory[] comparisonConverters) {
+ super(originalData, testConverters, comparisonConverters);
+ }
+
+ public String getType() {
+ return FilePassResult.SUCCESS;
+ }
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/IdsNotPreservedComparer.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/IdsNotPreservedComparer.java (rev 0)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/IdsNotPreservedComparer.java 2007-08-06 19:14:53 UTC (rev 460)
@@ -0,0 +1,257 @@
+package org.cishell.testing.convertertester.core.tester2.graphcomparison;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.cishell.testing.convertertester.core.tester.graphcomparison.ComparisonResult;
+import org.cishell.testing.convertertester.core.tester.graphcomparison.GraphUtil;
+import org.cishell.testing.convertertester.core.tester.graphcomparison.RunningLog;
+
+import prefuse.data.Graph;
+import prefuse.data.Node;
+import prefuse.data.Table;
+import prefuse.data.Tuple;
+import prefuse.util.collections.IntIterator;
+
+public class IdsNotPreservedComparer extends SimpleGraphComparer {
+
+ private RunningLog log;
+
+ public ComparisonResult compare(Graph g1, Graph g2) {
+ this.log = new RunningLog();
+
+ ComparisonResult simpleCompareResult = super.compare(g1, g2);
+
+ if (! simpleCompareResult.comparisonSucceeded()) {
+ return simpleCompareResult;
+ }
+
+ log.append(simpleCompareResult.getLog());
+
+ if (! nodeDegreeFrequenciesEqual(g1, g2))
+ return new ComparisonResult(false, "The number of nodes" +
+ "with a certain number of edges is not the same in" +
+ "both graphs.", log);
+
+ /*
+ * TODO: we could really use a graph isomorphism comparison right
+ * here. nodeDegreeFrequencies will catch some errors, but lets
+ * a lot through.
+ */
+
+ if (! haveSameNodeAttributes(g1, g2))
+ return new ComparisonResult(false, "Node attributes are not " +
+ "the same in both graphs.", log);
+
+ if (! haveSameEdgeAttributes(g1, g2))
+ return new ComparisonResult(false, "Edge attributes are not " +
+ "the same in both graphs.", log);
+
+ //all tests passed
+ return new ComparisonResult(true, "All tests succeeded.", log);
+ }
+
+ /*
+ * Tests whether there are an equal numbers of nodes with the same
+ * number of edges in each graph, e.g. 5 nodes with 1 edge, 12 nodes
+ * with 2 edges etc.. .
+ *
+ * Possibly useful when graph IDs are modified by the conversion.
+ */
+ private boolean nodeDegreeFrequenciesEqual(Graph g1, Graph g2) {
+ Set e1 = getNodeDegreeFrequencies(g1);
+ Set e2 = getNodeDegreeFrequencies(g2);
+
+ boolean result = e1.equals(e2);
+ return result;
+ }
+
+ /*
+ * Helper method for nodeDegreeFrequenciesEqual
+ */
+ private Set getNodeDegreeFrequencies(Graph g) {
+ Map nodeDegreeFrequencies
+ = new HashMap();
+
+ /*
+ * TODO: (might want to shortcut all of this by counting from 0 to
+ * numberOfNodes)
+ */
+ Table nodeTable = g.getNodeTable();
+ for (IntIterator ii = nodeTable.rows(); ii.hasNext();) {
+ int nodeID = ii.nextInt();
+ Node node = g.getNode(nodeID);
+
+ int numEdges = g.getInDegree(node) + g.getOutDegree(node);
+
+ Integer currentFrequency =
+ (Integer) nodeDegreeFrequencies.get(new Integer(numEdges));
+ if (currentFrequency == null) {
+ /*
+ * A node with this number of edges has not been recorded yet,
+ * so we set the number of occurrences to one.
+ */
+ nodeDegreeFrequencies.put(new Integer(numEdges),
+ new Integer(1));
+ } else {
+ /*
+ * A node with this number of edges has been recorded, so
+ * we increment the number of occurrences by one.
+ */
+ nodeDegreeFrequencies.put(new Integer(numEdges),
+ currentFrequency);
+ }
+ }
+
+ //convert the result to a more usable format.
+ Set nodeFrequencyPairs
+ = nodeDegreeFrequencies.entrySet();
+
+ return nodeFrequencyPairs;
+ }
+
+
+ private boolean haveSameNodeAttributes(Graph g1, Graph g2) {
+ Table t1 = getStrippedNodeTable(g1);
+ Table t2 = getStrippedNodeTable(g2);
+ boolean result = areEqualWhenSorted(t1, t2);
+ return result;
+ }
+
+ /*
+ * Determines whether the two graphs have the same edge attributes.
+ * That is, for every edge in table A there is an edge in table B with
+ * the exactly the same attribute values, and vice versa. Has no regard
+ * for source and target IDs, or the order the edgesappear in the edge
+ * tables.
+ */
+ private boolean haveSameEdgeAttributes(Graph g1, Graph g2) {
+ //remove the IDs
+ Table t1 = getStrippedEdgeTable(g1.getEdgeTable());
+ Table t2 = getStrippedEdgeTable(g2.getEdgeTable());
+
+ boolean result = areEqualWhenSorted(t1, t2);
+ return result;
+ }
+
+ /*
+ * These methods do what .equals() should do for their respective objects:
+ * Actually compare the contents to see if they are .equals() to each
+ * other. The default methods instead appear to be doing a memory
+ * location comparison.
+ */
+
+ private boolean areEqual(Graph g1, Graph g2, boolean sort) {
+ Table nodeTable1 = g1.getNodeTable();
+ Table nodeTable2 = g2.getNodeTable();
+
+ if (sort) {
+ if (! areEqualWhenSorted(nodeTable1, nodeTable2))
+ return false;
+ } else {
+ if (! areEqual(nodeTable1, nodeTable2))
+ return false;
+ }
+
+ Table edgeTable1 = g1.getEdgeTable();
+ Table edgeTable2 = g2.getEdgeTable();
+
+ if (sort) {
+ if (! areEqualWhenSorted(edgeTable1, edgeTable2))
+ return false;
+ } else {
+ if (! areEqual(edgeTable1, edgeTable2))
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean areEqualWhenSorted(Table t1, Table t2) {
+ boolean result = areEqual(GraphUtil.getSorted(t1),
+ GraphUtil.getSorted(t2));
+ return result;
+ }
+
+ /*
+ * Cares about the order of nodes and edges as well.
+ */
+ private boolean areEqual(Table t1, Table t2) {
+ Iterator tuplesIterator1 = t1.tuples();
+ Iterator tuplesIterator2 = t2.tuples();
+
+ while (tuplesIterator1.hasNext()) {
+ Tuple tuple1 = (Tuple) tuplesIterator1.next();
+ Tuple tuple2 = (Tuple) tuplesIterator2.next();
+
+ if (! areEqual(tuple1, tuple2)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private boolean areEqual(Tuple tu1, Tuple tu2) {
+ if (tu1.getColumnCount() != tu2.getColumnCount()) {
+ log.append("Number of columns in tuples differ.");
+ log.append("First tuple: " + tu1);
+ log.append("Second tuple: " + tu2);
+ return false;
+ }
+
+ for (int ii = 0; ii < tu1.getColumnCount(); ii++) {
+ Object columnContents1 = tu1.get(ii);
+ Object columnContents2 = tu2.get(ii);
+
+ if (columnContents1 == null && columnContents2 == null) {
+ //nulls are equal to each other!
+ continue;
+ } else if (columnContents1 == null) {
+ //one is null and the other is not.
+ log.append("Bad pair of tuples!");
+ log.append(tu1 + " : " + tu2);
+ return false;
+ } else if (columnContents2 == null) {
+ //one is null and the other is not.
+ log.append("Bad pair of tuples!");
+ log.append(tu1 + " : " + tu2);
+ return false;
+ } else if (! tu1.get(ii).equals(tu2.get(ii))){
+ log.append("Bad pair of tuples!");
+ log.append(tu1 + " : " + tu2);
+ //neither are null, but they are still not equal.
+ return false;
+ }
+ }
+
+ //all column contents are equal.
+ return true;
+ }
+
+ /**
+ * Removes source and target columns from a copied version of the table.
+ *
+ * Helper method for haveSameEdgeAttributes
+ *
+ * @param t the original table
+ * @return a stripped copy of the original table
+ */
+ private Table getStrippedEdgeTable(Table t) {
+ Table tCopy = GraphUtil.copyTable(t);
+ tCopy.removeColumn(Graph.DEFAULT_SOURCE_KEY);
+ tCopy.removeColumn(Graph.DEFAULT_TARGET_KEY);
+ return tCopy;
+ }
+
+ private Table getStrippedNodeTable(Graph g) {
+ Table tCopy = GraphUtil.copyTable(g.getNodeTable());
+ String nodeKeyField = g.getNodeKeyField();
+ if (nodeKeyField != null) {
+ tCopy.removeColumn(nodeKeyField);
+ }
+ return tCopy;
+ }
+}
Added: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/IdsPreservedComparer.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/graphcomparison/IdsPreserve...
[truncated message content] |