📄 zkbvalidationtestcase.java
字号:
package test.org.mandarax.zkb;
/*
* Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.File;
import java.io.FileOutputStream;
import java.util.Comparator;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.mandarax.kernel.ClauseSet;
import org.mandarax.kernel.Query;
import org.mandarax.reference.AdvancedKnowledgeBase;
import org.mandarax.util.logging.LogCategories;
import org.mandarax.zkb.ObjectPersistencyService;
import org.mandarax.zkb.ZKBDriver;
import test.org.mandarax.testsupport.TestUtils;
/**
* Test case to validate ZKB documents.
* @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
* @version 3.4 <7 March 05>
* @since 2.3
*/
public class ZKBValidationTestCase extends junit.framework.TestCase implements LogCategories {
protected static SAXBuilder saxBuilder = new SAXBuilder(true);
protected static XMLOutputter outPutter = new XMLOutputter(" ",true);
protected ZKBDriver driver = null;
protected ObjectPersistencyService ops = null;
protected String name = null;
protected AdvancedKnowledgeBase kb = new AdvancedKnowledgeBase();
// the file name used to output / temp storage
protected String file = null;
/**
* Construct a ZKB test case.
* @param driver the zkb driver
* @param anOps the object persistency service
* @param comparator a comparator
* @param clauses clauses to be added to the kb
* @param queries queries to be added to the kb
* @param name the name of the test case
*/
public ZKBValidationTestCase(ZKBDriver aDriver,ObjectPersistencyService anOps,Comparator comparator,ClauseSet[] clauses,Query[] queries,String name) {
super ("test");
aDriver.setDtdRefPolicy(ZKBDriver.INTERNAL_DTD_REF);
driver = aDriver;
ops = anOps;
setName(name);
// build filename
StringBuffer buf = new StringBuffer();
buf.append("_test_zkb_valid_");
buf.append(getName());
buf.append("_4driver_");
buf.append(driver.getName());
buf.append(".xml");
file = TestUtils.getFileName(buf.toString());
// init kb
if (comparator!=null) kb.setComparator(comparator);
if (clauses!=null) {
for (int i=0;i<clauses.length;i++) kb.add(clauses[i]);
}
if (queries!=null) {
for (int i=0;i<queries.length;i++) kb.addQuery(queries[i]);
}
}
/**
* Construct a ZKB test case.
* @param driver the zkb driver
* @param anOps the object persistency service
* @param comparator a comparator
* @param clauseSet a clause set to be added to the kb
* @param query a query to be added to the kb
* @param name the name of the test case
*/
public ZKBValidationTestCase(ZKBDriver aDriver,ObjectPersistencyService anOps,Comparator comparator,ClauseSet clauseSet,Query query,String name) {
this(aDriver,anOps,comparator,clauseSet==null?new ClauseSet[]{}:new ClauseSet[]{clauseSet},query==null?new Query[]{}:new Query[]{query},name);
}
/**
* Construct a ZKB test case.
* @param driver the zkb driver
* @param anOps the object persistency service
* @param clauseSet a clause set to be added to the kb
* @param query a query to be added to the kb
* @param name the name of the test case
*/
public ZKBValidationTestCase(ZKBDriver aDriver,ObjectPersistencyService anOps,ClauseSet clauseSet,Query query,String name) {
this(aDriver,anOps,null,clauseSet,query,name);
}
/**
* Construct a ZKB test case.
* @param driver the zkb driver
* @param anOps the object persistency service
* @param clauseSet a clause set to be added to the kb
* @param name the name of the test case
*/
public ZKBValidationTestCase(ZKBDriver aDriver,ObjectPersistencyService anOps,ClauseSet clauseSet,String name) {
this(aDriver,anOps,null,clauseSet,null,name);
}
/**
* Run the test.
*/
public void test() throws Exception {
Document doc = driver.exportKnowledgeBase(kb,ops);
// write
FileOutputStream out = new FileOutputStream(file);
outPutter.output(doc,out);
out.close();
// read and validate !!
try {
saxBuilder.build(new File(file));
}
catch (JDOMException x) {
LOG_TEST.error("Error running test " + this,x);
assertTrue(false);
}
}
/**
* Convert the object to a string.
* @return a string
*/
public String toString() {
return "DTD Validation test case for ZKB - " + name;
}
/**
* Returns the name.
* @return String
*/
public String getName() {
return toString();
}
/**
* Sets the name.
* @param name The name to set
*/
public void setName(String name) {
this.name = name;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -