src.com.hp.hpl.jena.rdf.arp.states.test.TestData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jena Show documentation
Show all versions of jena Show documentation
Jena is a Java framework for building Semantic Web applications. It provides a programmatic environment for RDF, RDFS and OWL, SPARQL and includes a rule-based inference engine.
/*
* (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
* [See end of file]
*/
package com.hp.hpl.jena.rdf.arp.states.test;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import org.xml.sax.Attributes;
import org.xml.sax.SAXParseException;
import com.hp.hpl.jena.rdf.arp.ARPErrorNumbers;
import com.hp.hpl.jena.rdf.arp.impl.AbsXMLContext;
import com.hp.hpl.jena.rdf.arp.impl.AttributeLexer;
import com.hp.hpl.jena.rdf.arp.impl.Names;
import com.hp.hpl.jena.rdf.arp.impl.URIReference;
import com.hp.hpl.jena.rdf.arp.impl.XMLBaselessContext;
import com.hp.hpl.jena.rdf.arp.impl.XMLContext;
import com.hp.hpl.jena.rdf.arp.impl.XMLHandler;
import com.hp.hpl.jena.rdf.arp.states.AbsXMLLiteral;
import com.hp.hpl.jena.rdf.arp.states.DAMLCollection;
import com.hp.hpl.jena.rdf.arp.states.FrameI;
import com.hp.hpl.jena.rdf.arp.states.HasSubjectFrameI;
import com.hp.hpl.jena.rdf.arp.states.InnerXMLLiteral;
import com.hp.hpl.jena.rdf.arp.states.LookingForRDF;
import com.hp.hpl.jena.rdf.arp.states.OuterXMLLiteral;
import com.hp.hpl.jena.rdf.arp.states.RDFCollection;
import com.hp.hpl.jena.rdf.arp.states.WantEmpty;
import com.hp.hpl.jena.rdf.arp.states.WantLiteralValueOrDescription;
import com.hp.hpl.jena.rdf.arp.states.WantPropertyElement;
import com.hp.hpl.jena.rdf.arp.states.WantTopLevelDescription;
import com.hp.hpl.jena.rdf.arp.states.WantTypedLiteral;
import com.hp.hpl.jena.rdf.arp.states.WantsObjectFrameI;
/**
* For each state s, for each element-attribute event e1, - test s, e1 - if s,
* e1 is not an error + test s, e1; Description; test s,e1, eg:prop; test s, e1,
* end; for each element-attribute event e2 + test s, e1, e2 if s, e1, e2 is not
* an error
*
* @author Jeremy J. Carroll
*
*/
public class TestData implements ARPErrorNumbers{
// TODO: not for 2.3. get rid of short names all together, not good idea.
private static final URIReference foo = URIReference.createNoChecks("http://foo/");
private static final URIReference bar = URIReference.createNoChecks("http://bar/");
static TestHandler xmlHandler = new TestHandler();
// static {
// try {
// xmlHandler.initParse("http://example.org/", "");
// } catch (SAXParseException e) {
// e.printStackTrace();
// }
//
// }
static String dataFile = "testing/arp/state.txt";
static AbsXMLContext xmlContext;
static {
try {
xmlContext= new XMLBaselessContext(xmlHandler,
ERR_RESOLVING_AGAINST_RELATIVE_BASE).withBase(xmlHandler,"http://example.org/base/");
} catch (SAXParseException e) {
throw new RuntimeException(e);
}
}
static TestFrame testFrame = new TestFrame(xmlHandler, xmlContext);
static char white[] = { 32, 32, 32, 32, 32 };
static char black[] = { 97, 98, 99, 100, 101 };
private static final AttrEvent xmlSpace = new AttrEvent(QName.xml("space"));
static Event allEvents[] = {
new ElementEvent(QName.rdf("li")),
new ElementEvent(QName.rdf("Description")),
new ElementEvent("F",QName.rdf("RDF")),
new ElementEvent(QName.eg("Goo")),
new AttrEvent(QName.xml("base")),
new AttrEvent("g", QName.xml("lang"), "en"),
new AttrEvent(QName.eg("foo")),
xmlSpace,
new AttrEvent("B", QName.rdf("bagID"), "en"),
new AttrEvent(QName.rdf("about")),
new AttrEvent("h", QName.rdf("aboutEach"), "en"),
new AttrEvent("H", QName.rdf("aboutEachPrefix"), "en"),
new AttrEvent(QName.rdf("ID")), new AttrEvent(QName.rdf("nodeID")),
new AttrEvent(QName.rdf("resource")),
new AttrEvent(QName.rdf("type")),
new AttrEvent(QName.rdf("datatype")),
new AttrEvent("C", QName.rdf("parseType"), "Collection"),
new AttrEvent("L", QName.rdf("parseType"), "Literal"),
new AttrEvent("R", QName.rdf("parseType"), "Resource"),
new InternalEvent("e", "") {
FrameI apply(FrameI from, Attributes att) throws SAXParseException {
from.endElement();
return from.getParent();
}
}, new InternalEvent("O", "object") {
FrameI apply(FrameI from, Attributes att) {
((WantsObjectFrameI) from).theObject(foo);
return from;
}
}, new InternalEvent("W", "white") {
FrameI apply(FrameI from, Attributes att) throws SAXParseException {
from.characters(white, 0, 5);
return from;
}
}, new InternalEvent("Q", "'abcde'") {
FrameI apply(FrameI from, Attributes att) throws SAXParseException {
from.characters(black, 0, 5);
return from;
}
},
new InternalEvent("P", "pred-object") {
FrameI apply(FrameI from, Attributes att) {
((HasSubjectFrameI) from).aPredAndObj(foo,bar);
return from;
}
}, };
static Map short2Event = new HashMap();
static {
for (int i=0;i",
" ",
" ",
"'abcde'",
"'abcde' ",
"'abcde' ",
"",
"pred-object",
"object",
};
boolean inCharacterize = false;
void characterize(Class f){
inCharacterize = true;
int sz = eventList.size;
StringBuffer rslt = new StringBuffer();
String skip = null;
eventList.test(f);
rslt.append(eventListName(f,null));
rslt.append(" $ " + testInfo(f) + " {");
if ( eventList.testResult.getClass() != LookingForRDF.class)
for (int i=0;i= (AbsXMLLiteral.class.isAssignableFrom(f) ? 3 :
eventList.testResult instanceof LookingForRDF ? 2
: 8))
return;
for (int i = 0; i < allEvents.length; i++) {
if (allEvents[i].isAttribute()) {
Event e = eventList.last();
if (!(e.isElement() || (e.isAttribute() && e.hashCode() < allEvents[i]
.hashCode())))
continue;
} else if (true) {
continue;
}
eventList.add(allEvents[i]);
expand(f);
eventList.pop();
}
}
private Random dice = new Random(23);
private boolean randomPurgeXMLAttrs() {
int weight = 0;
eventList.rewind();
while (eventList.hasNext()) {
Event e = eventList.next();
if ( e==xmlSpace)
weight += 2;
else if ( e.isAttribute() && ((AttrEvent)e).q.uri.equals(Names.xmlns) )
weight ++;
}
while (weight-- >0)
if (dice.nextBoolean())
return true;
return false;
}
private boolean shorterTestFails(Class f) {
if (eventList.size <= 2)
return false;
for (int i=1;i