📄 testlistsyntaxcategories.java
字号:
}
public boolean test( Resource r ) {
return r instanceof AllDifferent;
}
},
// classes
new DoListTest( "OWL+import list classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 14,
null )
{
public Iterator doList( OntModel m ) {
return m.listClasses();
}
public boolean test( Resource r ) {
return r instanceof OntClass;
}
},
new DoListTest( "OWL+import list named classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 12,
new String[] {NS+"A", NS+"B", NS+"C", NS+"D", NS+"E", NS+"X0", NS+"X1", NS+"Y0", NS+"Y1", NS+"Z",
OWL.Thing.getURI(), OWL.Nothing.getURI()} )
{
public Iterator doList( OntModel m ) {
return m.listNamedClasses();
}
public boolean test( Resource r ) {
return r instanceof OntClass;
}
},
new DoListTest( "OWL+import list intersection classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
new String[] {NS+"A" } )
{
public Iterator doList( OntModel m ) {
return m.listIntersectionClasses();
}
public boolean test( Resource r ) {
return r instanceof OntClass;
}
},
new DoListTest( "OWL+import list union classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 2,
new String[] {NS+"B", OWL.Thing.getURI()} )
{
public Iterator doList( OntModel m ) {
return m.listUnionClasses();
}
public boolean test( Resource r ) {
return r instanceof OntClass;
}
},
new DoListTest( "OWL+import list complement classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 3,
null )
{
public Iterator doList( OntModel m ) {
return m.listComplementClasses();
}
public boolean test( Resource r ) {
return r instanceof OntClass;
}
},
new DoListTest( "OWL+import list enumerated classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
new String[] {NS+"D"} )
{
public Iterator doList( OntModel m ) {
return m.listEnumeratedClasses();
}
public boolean test( Resource r ) {
return r instanceof OntClass;
}
},
new DoListTest( "OWL+import list restrictions", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
null )
{
public Iterator doList( OntModel m ) {
return m.listRestrictions();
}
public boolean test( Resource r ) {
return r instanceof Restriction;
}
},
};
// Instance variables
//////////////////////////////////
// Constructors
//////////////////////////////////
public TestListSyntaxCategories( String name ) {
super( name );
}
// External signature methods
//////////////////////////////////
public static TestSuite suite() {
TestSuite s = new TestSuite( "TestListSyntaxCategories" );
for (int i = 0; i < testCases.length; i++) {
s.addTest( testCases[i] );
}
return s;
}
// Internal implementation methods
//////////////////////////////////
//==============================================================================
// Inner class definitions
//==============================================================================
protected static class DoListTest
extends TestCase
{
protected String m_fileName;
protected OntModelSpec m_spec;
protected int m_count;
protected String[] m_expected;
protected boolean m_exExpected; // exception expected during list operation
protected DoListTest( String name, String fileName, OntModelSpec spec, int count, String[] expected ) {
this( name, fileName, spec, count, expected, false );
}
protected DoListTest( String name, String fileName, OntModelSpec spec, int count, String[] expected, boolean exExpected ) {
super( name );
m_fileName = fileName;
m_spec = spec;
m_count = count;
m_expected = expected;
m_exExpected = exExpected;
}
public void setUp() {
// ensure the ont doc manager is in a consistent state
OntDocumentManager.getInstance().reset( true );
}
public void runTest() {
OntModel m = ModelFactory.createOntologyModel( m_spec, null );
m.getDocumentManager().setMetadataSearchPath( "file:etc/ont-policy-test.rdf", true );
if (m_fileName != null) {
m.read( m_fileName );
}
boolean exOccurred = false;
Iterator i = null;
try {
i = doList( m );
}
catch (OntologyException e) {
exOccurred = true;
}
assertEquals( "Ontology exception" + (m_exExpected ? " was " : " was not ") + "expected", m_exExpected, exOccurred );
if (!exOccurred) {
List expected = expected( m );
List actual = new ArrayList();
int extraneous = 0;
// now we walk the iterator
while (i.hasNext()) {
Resource res = (Resource) i.next();
assertTrue( "Should not fail node test on " + res, test( res ));
actual.add( res );
if (expected != null) {
if (expected.contains( res )) {
expected.remove( res );
}
else {
if (!res.isAnon()) {
// since we can't list expected anon resources, we ignore them in this check
extraneous++;
}
}
}
}
// debugging
if (m_count != actual.size()) {
Log logger = LogFactory.getLog( getClass() );
logger.debug( getName() + " - expected " + m_count + " results, actual = " + actual.size() );
for (Iterator j = actual.iterator(); j.hasNext(); ) {
logger.debug( getName() + " - saw actual: " + j.next() );
}
}
if (expected != null && !expected.isEmpty()) {
Log logger = LogFactory.getLog( getClass() );
for (Iterator j = expected.iterator(); j.hasNext(); ) {
logger.debug( getName() + " - expected but did not find: " + j.next() );
}
}
assertEquals( getName() + ": wrong number of results returned", m_count, actual.size() );
if (expected != null) {
assertTrue( "Did not find all expected resources in iterator", expected.isEmpty() );
assertEquals( "Found extraneous results, not in expected list", 0, extraneous );
}
}
}
/* get the iterator */
public Iterator doList( OntModel m ) {
// should be overriden in sub-classes
return null;
}
/* test the Java type of the result, and other tests */
public boolean test( Resource r ) {
return true;
}
protected List expected( OntModel m ) {
if (m_expected != null) {
List expected = new ArrayList();
for (int i = 0; i < m_expected.length; i++) {
expected.add( m.getResource( m_expected[i] ) );
}
return expected;
}
else {
return null;
}
}
}
}
/*
(c) Copyright 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -