1 19 20 package com.hp.hpl.jena.ontology.daml.impl.test; 23 24 25 import java.util.*; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 import com.hp.hpl.jena.ontology.*; 33 import com.hp.hpl.jena.ontology.daml.DAMLModel; 34 import com.hp.hpl.jena.rdf.model.*; 35 36 import junit.framework.*; 37 38 39 48 public abstract class DAMLTestBase 49 extends TestSuite 50 { 51 54 public static final String BASE = "http://jena.hpl.hp.com/testing/ontology"; 55 public static final String NS = BASE + "#"; 56 57 58 61 64 65 68 public DAMLTestBase( String name ) { 69 super( name ); 70 TestCase[] tc = getTests(); 71 72 for (int i = 0; i < tc.length; i++) { 73 addTest( tc[i] ); 74 } 75 } 76 77 80 81 84 85 protected OntTestCase[] getTests() { 86 return null; 87 } 88 89 90 94 protected abstract class OntTestCase 95 extends TestCase 96 { 97 protected String m_langElement; 98 99 public OntTestCase( String langElement ) { 100 super( "DAML API test " + langElement ); 101 m_langElement = langElement; 102 } 103 104 public void setUp() { 105 OntDocumentManager.getInstance().reset( true ); 107 } 108 109 110 public void runTest() 111 throws Exception 112 { 113 boolean profileEx = false; 114 DAMLModel m = ModelFactory.createDAMLModel(); 115 116 try { 117 doTest( m ); 118 } 119 catch (ProfileException e) { 120 profileEx = true; 121 } 122 123 assertTrue( "language element " + m_langElement + " was expected in DAML model ", !profileEx ); 124 } 125 126 127 protected abstract void doTest( DAMLModel m ) throws Exception ; 128 129 130 protected void iteratorTest( Iterator i, Object [] expected ) { 131 Log logger = LogFactory.getLog( getClass() ); 132 List expList = new ArrayList(); 133 for (int j = 0; j < expected.length; j++) { 134 expList.add( expected[j] ); 135 } 136 137 while (i.hasNext()) { 138 Object next = i.next(); 139 140 if (!expList.contains( next )) { 142 logger.debug( getName() + " - Unexpected iterator result: " + next ); 143 } 144 145 assertTrue( "Value " + next + " was not expected as a result from this iterator ", expList.contains( next ) ); 146 assertTrue( "Value " + next + " was not removed from the list ", expList.remove( next ) ); 147 } 148 149 if (!(expList.size() == 0)) { 150 logger.debug( getName() + "Expected iterator results not found" ); 151 for (Iterator j = expList.iterator(); j.hasNext(); ) { 152 logger.debug( getName() + " - missing: " + j.next() ); 153 } 154 } 155 assertEquals( "There were expected elements from the iterator that were not found", 0, expList.size() ); 156 } 157 } 158 } 159 160 161 190 191 | Popular Tags |