📄 testresource.java
字号:
/*****************************************************************************
* Source code information
* -----------------------
* Original author Ian Dickinson, HP Labs Bristol
* Author email Ian.Dickinson@hp.com
* Package Jena 2
* Web http://sourceforge.net/projects/jena/
* Created 23-May-2003
* Filename $RCSfile: TestResource.java,v $
* Revision $Revision: 1.18 $
* Release status $State: Exp $
*
* Last modified on $Date: 2007/01/21 16:26:30 $
* by $Author: ian_dickinson $
*
* (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
* (see footer for full conditions)
*****************************************************************************/
// Package
///////////////
package com.hp.hpl.jena.ontology.impl.test;
// Imports
///////////////
import junit.framework.TestSuite;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.RDF;
/**
* <p>
* Unit test cases for ontology resources
* </p>
*
* @author Ian Dickinson, HP Labs
* (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
* @version CVS $Id: TestResource.java,v 1.18 2007/01/21 16:26:30 ian_dickinson Exp $
*/
public class TestResource
extends OntTestBase
{
// Constants
//////////////////////////////////
// Static variables
//////////////////////////////////
// Instance variables
//////////////////////////////////
// Constructors
//////////////////////////////////
static public TestSuite suite() {
return new TestResource( "TestResource" );
}
public TestResource( String name ) {
super( name );
}
// External signature methods
//////////////////////////////////
// Internal implementation methods
//////////////////////////////////
public OntTestCase[] getTests() {
return new OntTestCase[] {
new OntTestCase( "OntResource.sameAs", true, false, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );
OntResource b = (OntResource) m.getResource( NS + "b" ).as( OntResource.class );
OntResource c = (OntResource) m.getResource( NS + "c" ).as( OntResource.class );
a.addSameAs( b );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SAME_AS() ) );
assertEquals( "a should be sameAs b", b, a.getSameAs() );
a.addSameAs( c );
assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.SAME_AS() ) );
iteratorTest( a.listSameAs(), new Object[] {b, c} );
assertTrue( "a should be the same as b", a.isSameAs( b ) );
assertTrue( "a should be the same as c", a.isSameAs( c ) );
a.setSameAs( b );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SAME_AS() ) );
assertEquals( "a should be sameAs b", b, a.getSameAs() );
a.removeSameAs( c );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SAME_AS() ) );
a.removeSameAs( b );
assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.SAME_AS() ) );
}
},
new OntTestCase( "OntResource.differentFrom", true, true, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );
OntResource b = (OntResource) m.getResource( NS + "b" ).as( OntResource.class );
OntResource c = (OntResource) m.getResource( NS + "c" ).as( OntResource.class );
a.addDifferentFrom( b );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DIFFERENT_FROM() ) );
assertEquals( "a should be differentFrom b", b, a.getDifferentFrom() );
a.addDifferentFrom( c );
assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.DIFFERENT_FROM() ) );
iteratorTest( a.listDifferentFrom(), new Object[] {b, c} );
assertTrue( "a should be diff from b", a.isDifferentFrom( b ) );
assertTrue( "a should be diff from c", a.isDifferentFrom( c ) );
a.setDifferentFrom( b );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DIFFERENT_FROM() ) );
assertEquals( "a should be differentFrom b", b, a.getDifferentFrom() );
a.removeDifferentFrom( c );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DIFFERENT_FROM() ) );
a.removeDifferentFrom( b );
assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.DIFFERENT_FROM() ) );
}
},
new OntTestCase( "OntResource.seeAlso", true, true, true, true ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );
OntResource b = (OntResource) m.getResource( NS + "b" ).as( OntResource.class );
OntResource c = (OntResource) m.getResource( NS + "c" ).as( OntResource.class );
a.addSeeAlso( b );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SEE_ALSO() ) );
assertEquals( "a should be seeAlso b", b, a.getSeeAlso() );
a.addSeeAlso( c );
assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.SEE_ALSO() ) );
iteratorTest( a.listSeeAlso(), new Object[] {b, c} );
assertTrue( "a should have seeAlso b", a.hasSeeAlso( b ) );
assertTrue( "a should have seeAlso c", a.hasSeeAlso( c ) );
a.setSeeAlso( b );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SEE_ALSO() ) );
assertEquals( "a should be seeAlso b", b, a.getSeeAlso() );
a.removeSeeAlso( c );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SEE_ALSO() ) );
a.removeSeeAlso( b );
assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.SEE_ALSO() ) );
}
},
new OntTestCase( "OntResource.isDefinedBy", true, true, true, true ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );
OntResource b = (OntResource) m.getResource( NS + "b" ).as( OntResource.class );
OntResource c = (OntResource) m.getResource( NS + "c" ).as( OntResource.class );
a.addIsDefinedBy( b );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.IS_DEFINED_BY() ) );
assertEquals( "a should be isDefinedBy b", b, a.getIsDefinedBy() );
a.addIsDefinedBy( c );
assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.IS_DEFINED_BY() ) );
iteratorTest( a.listIsDefinedBy(), new Object[] {b, c} );
assertTrue( "a should be defined by b", a.isDefinedBy( b ) );
assertTrue( "a should be defined by c", a.isDefinedBy( c ) );
a.setIsDefinedBy( b );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.IS_DEFINED_BY() ) );
assertEquals( "a should be isDefinedBy b", b, a.getIsDefinedBy() );
a.removeDefinedBy( c );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.IS_DEFINED_BY() ) );
a.removeDefinedBy( b );
assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.IS_DEFINED_BY() ) );
}
},
new OntTestCase( "OntResource.versionInfo", true, true, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );
a.addVersionInfo( "some info" );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.VERSION_INFO() ) );
assertEquals( "a has wrong version info", "some info", a.getVersionInfo() );
a.addVersionInfo( "more info" );
assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.VERSION_INFO() ) );
iteratorTest( a.listVersionInfo(), new Object[] {"some info", "more info"} );
assertTrue( "a should have some info", a.hasVersionInfo( "some info" ) );
assertTrue( "a should have more info", a.hasVersionInfo( "more info" ) );
a.setVersionInfo( "new info" );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.VERSION_INFO() ) );
assertEquals( "a has wrong version info", "new info", a.getVersionInfo() );
a.removeVersionInfo( "old info" );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.VERSION_INFO() ) );
a.removeVersionInfo( "new info" );
assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.VERSION_INFO() ) );
}
},
new OntTestCase( "OntResource.label.nolang", true, true, true, true ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );
a.addLabel( "some info", null );
assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.LABEL() ) );
assertEquals( "a has wrong label", "some info", a.getLabel( null ) );
a.addLabel( "more info", null );
assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.LABEL() ) );
iteratorTest( a.listLabels( null ), new Object[] {m.createLiteral( "some info" ), m.createLiteral( "more info" )} );
assertTrue( "a should have label some info", a.hasLabel( "some info", null ) );
assertTrue( "a should have label more info", a.hasLabel( "more info", null ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -