Skip to content

Commit

Permalink
Integration test confirming nodetype inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
yulgit1 authored and Andrew Woods committed Feb 21, 2014
1 parent 3800da9 commit 14eb8b3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Expand Up @@ -93,6 +93,9 @@ public final class RdfLexicon {
public static final String RDF_NAMESPACE =
"http://www.w3.org/1999/02/22-rdf-syntax-ns#";

public static final String INDEXING_NAMESPACE =
"http://fedora.info/definitions/v4/indexing#";

public static final String DC_NAMESPACE =
"http://purl.org/dc/elements/1.1/";

Expand Down
Expand Up @@ -30,6 +30,7 @@
import static org.fcrepo.kernel.RdfLexicon.HAS_CONTENT_LOCATION;
import static org.fcrepo.kernel.RdfLexicon.HAS_PRIMARY_IDENTIFIER;
import static org.fcrepo.kernel.RdfLexicon.HAS_SIZE;
import static org.fcrepo.kernel.RdfLexicon.RDF_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.RELATIONS_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.REPOSITORY_NAMESPACE;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.getVersionHistory;
Expand All @@ -40,13 +41,20 @@
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.List;

import javax.inject.Inject;
import javax.jcr.NamespaceRegistry;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.NodeTypeDefinition;
import javax.jcr.nodetype.NodeTypeIterator;
import javax.jcr.nodetype.NodeTypeTemplate;
import javax.jcr.PropertyType;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeTypeManager;

import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.exception.InvalidChecksumException;
Expand All @@ -69,6 +77,7 @@
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.sparql.core.DatasetGraph;
import com.hp.hpl.jena.sparql.core.Quad;
import com.hp.hpl.jena.sparql.util.Symbol;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.vocabulary.RDF;
Expand Down Expand Up @@ -224,6 +233,46 @@ public void testObjectGraphWithCustomProperty() throws RepositoryException {

}

@Test
public void testRdfTypeInheritance() throws RepositoryException {
logger.info("in testRdfTypeInheritance...");
NodeTypeManager mgr = session.getWorkspace().getNodeTypeManager();
NamespaceRegistry nsReg = session.getWorkspace().getNamespaceRegistry();

//create supertype mixin
NodeTypeTemplate type = mgr.createNodeTypeTemplate();
type.setName("test:aSupertype");
type.setMixin(true);
NodeTypeDefinition[] nodeTypes = new NodeTypeDefinition[]{type};
mgr.registerNodeTypes(nodeTypes, true);

//create a type inheriting above supertype
NodeTypeTemplate type2 = mgr.createNodeTypeTemplate();
type2.setName("test:testInher");
type2.setMixin(true);
type2.setDeclaredSuperTypeNames(new String[]{"test:aSupertype"});
NodeTypeDefinition[] nodeTypes2 = new NodeTypeDefinition[]{type2};
mgr.registerNodeTypes(nodeTypes2, true);

//create object with inheriting type
FedoraResource object = objectService.createObject(session, "/testNTTnheritanceObject");
final javax.jcr.Node node = object.getNode();
node.addMixin("test:testInher");

session.save();
session.logout();
session = repo.login();

object = objectService.createObject(session, "/testNTTnheritanceObject");

//test that supertype has been inherited as rdf:type
final Node s = createGraphSubjectNode("/testNTTnheritanceObject");
final Node p = createProperty(RDF_NAMESPACE + "type").asNode();
final Node o = createProperty("info:fedora/test/aSupertype").asNode();
assertTrue("supertype test:aSupertype not found inherited in test:testInher!",object.getPropertiesDataset(subjects).asDatasetGraph()
.contains(ANY, s, p, o));
}

@Test
public void testDatastreamGraph() throws RepositoryException, InvalidChecksumException {

Expand Down

0 comments on commit 14eb8b3

Please sign in to comment.