From: Lars H. <lh...@us...> - 2005-07-08 16:27:32
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9420/src/org/tmapiutils/impexp/cxtm/tests Modified Files: CXTMTestCase.java CXTMTestSuite.java Log Message: Tabs -> Whitespaces Index: CXTMTestSuite.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/tests/CXTMTestSuite.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CXTMTestSuite.java 5 Mar 2005 17:30:09 -0000 1.2 --- CXTMTestSuite.java 8 Jul 2005 16:27:22 -0000 1.3 *************** *** 1,78 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * Licensed 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.tmapiutils.impexp.cxtm.tests; ! ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.util.Iterator; ! import java.util.Properties; ! ! import org.tmapiutils.impexp.cxtm.Canonicalize; ! import org.tmapiutils.impexp.cxtm.Driver; ! ! import junit.framework.Test; ! import junit.framework.TestSuite; ! ! /** ! * A JUnit TestSuite that is configured to run a series of ! * CXTMTestCase instances. The test suite is configured by ! * a Java properties file, the location of which is specified ! * by the value of the System property com.techquila.cxtm.test.files. ! */ ! public class CXTMTestSuite { ! ! public static Test suite() throws Exception { ! String driverClass = System.getProperty("org.tmapiutils.impexp.cxtm.Driver", "org.tmapiutils.impexp.cxtm.drivers.TM4JDriver"); ! Driver driver = (Driver) Class.forName(driverClass).newInstance(); ! driver.initialise(System.getProperties()); ! Canonicalize c = new Canonicalize(driver); ! String testFiles = System.getProperty("com.techquila.cxtm.test.files"); ! if (testFiles == null) { ! throw new RuntimeException("No test file list specified. Please set the system property com.techquila.cxtm.test.files to the location of the CXTM test file list."); ! } ! File f = new File(testFiles); ! TestSuite suite = new TestSuite("CXTMP Test Suite: " + f.getAbsolutePath()); ! if (!f.exists()) { ! throw new RuntimeException("Cannot locate test files list " + testFiles); ! } ! Properties testFileProps = new Properties(); ! try { ! testFileProps.load(new FileInputStream(f)); ! } catch (IOException ex) { ! throw new RuntimeException("The file " + f.getAbsolutePath() + " is not a valid properties file."); ! } ! ! String prefix = testFileProps.getProperty("uriprefix"); ! Boolean linefeeds = Boolean.valueOf(testFileProps.getProperty("insert.linefeeds")); ! c.setInsertLinefeeds(linefeeds.booleanValue()); ! ! Iterator it = testFileProps.keySet().iterator(); ! while (it.hasNext()) { ! String inFileName = (String) it.next(); ! if (inFileName.equals("uriprefix")) continue; ! if (inFileName.equals("insert.linefeeds")) continue; ! if (!inFileName.startsWith(";")) { ! String cxtmFileName = testFileProps.getProperty(inFileName); ! File inFile = new File(f.getParent(), inFileName); ! File outFile = new File(f.getParent(), cxtmFileName); ! suite.addTest(new CXTMTestCase(inFileName, c, inFile.getAbsolutePath(), prefix + inFileName, outFile.getAbsolutePath())); ! } ! } ! ! return suite; ! } ! } --- 1,78 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * Licensed 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.tmapiutils.impexp.cxtm.tests; ! ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.util.Iterator; ! import java.util.Properties; ! ! import org.tmapiutils.impexp.cxtm.Canonicalize; ! import org.tmapiutils.impexp.cxtm.Driver; ! ! import junit.framework.Test; ! import junit.framework.TestSuite; ! ! /** ! * A JUnit TestSuite that is configured to run a series of ! * CXTMTestCase instances. The test suite is configured by ! * a Java properties file, the location of which is specified ! * by the value of the System property com.techquila.cxtm.test.files. ! */ ! public class CXTMTestSuite { ! ! public static Test suite() throws Exception { ! String driverClass = System.getProperty("org.tmapiutils.impexp.cxtm.Driver", "org.tmapiutils.impexp.cxtm.drivers.TM4JDriver"); ! Driver driver = (Driver) Class.forName(driverClass).newInstance(); ! driver.initialise(System.getProperties()); ! Canonicalize c = new Canonicalize(driver); ! String testFiles = System.getProperty("com.techquila.cxtm.test.files"); ! if (testFiles == null) { ! throw new RuntimeException("No test file list specified. Please set the system property com.techquila.cxtm.test.files to the location of the CXTM test file list."); ! } ! File f = new File(testFiles); ! TestSuite suite = new TestSuite("CXTMP Test Suite: " + f.getAbsolutePath()); ! if (!f.exists()) { ! throw new RuntimeException("Cannot locate test files list " + testFiles); ! } ! Properties testFileProps = new Properties(); ! try { ! testFileProps.load(new FileInputStream(f)); ! } catch (IOException ex) { ! throw new RuntimeException("The file " + f.getAbsolutePath() + " is not a valid properties file."); ! } ! ! String prefix = testFileProps.getProperty("uriprefix"); ! Boolean linefeeds = Boolean.valueOf(testFileProps.getProperty("insert.linefeeds")); ! c.setInsertLinefeeds(linefeeds.booleanValue()); ! ! Iterator it = testFileProps.keySet().iterator(); ! while (it.hasNext()) { ! String inFileName = (String) it.next(); ! if (inFileName.equals("uriprefix")) continue; ! if (inFileName.equals("insert.linefeeds")) continue; ! if (!inFileName.startsWith(";")) { ! String cxtmFileName = testFileProps.getProperty(inFileName); ! File inFile = new File(f.getParent(), inFileName); ! File outFile = new File(f.getParent(), cxtmFileName); ! suite.addTest(new CXTMTestCase(inFileName, c, inFile.getAbsolutePath(), prefix + inFileName, outFile.getAbsolutePath())); ! } ! } ! ! return suite; ! } ! } Index: CXTMTestCase.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/tests/CXTMTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CXTMTestCase.java 5 Mar 2005 17:09:38 -0000 1.1 --- CXTMTestCase.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,80 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * Licensed 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.tmapiutils.impexp.cxtm.tests; ! ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.InputStream; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.impexp.cxtm.Canonicalize; ! ! /** ! * A JUnit TestCase that loads an input topic map file, ! * generates the canonical form of the data model created ! * by the topic map processor and compares that against ! * an expected canonical form. If the generated canonical ! * form matches the expected form the test passes, otherwise ! * the test fails. ! */ ! public class CXTMTestCase extends TestCase { ! ! private String m_baseURI; ! ! private String m_cxtmFileName; ! ! private String m_xtmFileName; ! ! private Canonicalize m_canonicalizer; ! ! /** ! * Constructor for CXTMTestCase. ! */ ! public CXTMTestCase(String name, Canonicalize canonicalizer, String xtmFileName, String baseURI, String cxtmFileName) { ! super(name); ! m_canonicalizer = canonicalizer; ! m_xtmFileName = xtmFileName; ! m_cxtmFileName = cxtmFileName; ! m_baseURI = baseURI; ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(CXTMTestCase.class); ! } ! ! public void runTest() throws Exception { ! File xtmFile = new File(m_xtmFileName); ! ByteArrayOutputStream expected = new ByteArrayOutputStream(); ! InputStream tmp = new FileInputStream(new File(m_cxtmFileName)); ! int b; ! while ((b = tmp.read()) != -1) { ! expected.write(b); ! } ! StringBuffer actual = new StringBuffer(); ! int mismatchAt = m_canonicalizer.canonicalize( ! new FileInputStream(xtmFile), ! m_baseURI, ! expected.toByteArray(), ! actual); ! assertTrue("Unexpected canonical form. Source file: " + m_xtmFileName + ".\n" + ! "\nExpected canonical form: " + expected.toString("UTF-8") + ! "\nProcessed canonical form: " + actual.toString(), ! mismatchAt < 0); ! } ! ! } --- 1,80 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * Licensed 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.tmapiutils.impexp.cxtm.tests; ! ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.InputStream; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.impexp.cxtm.Canonicalize; ! ! /** ! * A JUnit TestCase that loads an input topic map file, ! * generates the canonical form of the data model created ! * by the topic map processor and compares that against ! * an expected canonical form. If the generated canonical ! * form matches the expected form the test passes, otherwise ! * the test fails. ! */ ! public class CXTMTestCase extends TestCase { ! ! private String m_baseURI; ! ! private String m_cxtmFileName; ! ! private String m_xtmFileName; ! ! private Canonicalize m_canonicalizer; ! ! /** ! * Constructor for CXTMTestCase. ! */ ! public CXTMTestCase(String name, Canonicalize canonicalizer, String xtmFileName, String baseURI, String cxtmFileName) { ! super(name); ! m_canonicalizer = canonicalizer; ! m_xtmFileName = xtmFileName; ! m_cxtmFileName = cxtmFileName; ! m_baseURI = baseURI; ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(CXTMTestCase.class); ! } ! ! public void runTest() throws Exception { ! File xtmFile = new File(m_xtmFileName); ! ByteArrayOutputStream expected = new ByteArrayOutputStream(); ! InputStream tmp = new FileInputStream(new File(m_cxtmFileName)); ! int b; ! while ((b = tmp.read()) != -1) { ! expected.write(b); ! } ! StringBuffer actual = new StringBuffer(); ! int mismatchAt = m_canonicalizer.canonicalize( ! new FileInputStream(xtmFile), ! m_baseURI, ! expected.toByteArray(), ! actual); ! assertTrue("Unexpected canonical form. Source file: " + m_xtmFileName + ".\n" + ! "\nExpected canonical form: " + expected.toString("UTF-8") + ! "\nProcessed canonical form: " + actual.toString(), ! mismatchAt < 0); ! } ! ! } |