Skip to content

Commit

Permalink
unit tests for JcrRdfTools
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jun 25, 2013
1 parent 9f0074a commit 1cd0ee7
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 59 deletions.
5 changes: 5 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/RdfLexicon.java
Expand Up @@ -20,6 +20,11 @@ public final class RdfLexicon {
public static final Property HAS_COMPUTED_CHECKSUM = ResourceFactory.createProperty("info:fedora/fedora-system:def/internal#computedChecksum");
public static final Property HAS_COMPUTED_SIZE = ResourceFactory.createProperty("info:fedora/fedora-system:def/internal#computedSize");

public static final Property HAS_FIXITY_CHECK_COUNT = ResourceFactory.createProperty("info:fedora/fedora-system:def/internal#numFixityChecks");
public static final Property HAS_FIXITY_ERROR_COUNT = ResourceFactory.createProperty("info:fedora/fedora-system:def/internal#numFixityErrors");
public static final Property HAS_FIXITY_REPAIRED_COUNT = ResourceFactory.createProperty("info:fedora/fedora-system:def/internal#numFixityRepaired");


// SEARCH
public static final Property SEARCH_HAS_TOTAL_RESULTS = ResourceFactory.createProperty("http://a9.com/-/spec/opensearch/1.1/totalResults");
public static final Property SEARCH_ITEMS_PER_PAGE = ResourceFactory.createProperty("http://a9.com/-/spec/opensearch/1.1/itemsPerPage");
Expand Down
Expand Up @@ -341,6 +341,10 @@ public void setRepository(final Repository repository) {
repo = repository;
}

public Repository getRepository() {
return repo;
}

/**
* @todo Add Documentation.
*/
Expand Down
Expand Up @@ -196,12 +196,16 @@ public ValueFactory apply(final Node n) {
@Override
public com.hp.hpl.jena.rdf.model.Property
apply(final Property property) {
final Namespaced nsProperty = (Namespaced)property;
try {
final String uri = nsProperty.getNamespaceURI();
return ResourceFactory
.createProperty(getRDFNamespaceForJcrNamespace(uri),
nsProperty.getLocalName());
if (property instanceof Namespaced) {
final Namespaced nsProperty = (Namespaced)property;
final String uri = nsProperty.getNamespaceURI();
return ResourceFactory
.createProperty(getRDFNamespaceForJcrNamespace(uri),
nsProperty.getLocalName());
} else {
return ResourceFactory.createProperty(property.getName());
}
} catch (RepositoryException e) {
throw new IllegalStateException(e);
}
Expand Down
41 changes: 26 additions & 15 deletions fcrepo-kernel/src/main/java/org/fcrepo/utils/JcrRdfTools.java
Expand Up @@ -74,6 +74,7 @@ public abstract class JcrRdfTools {

private static final Logger LOGGER = getLogger(JcrRdfTools.class);

private static GetClusterConfiguration getClusterConfiguration = new GetClusterConfiguration();
/**
* A map of JCR namespaces to Fedora's RDF namespaces
*/
Expand All @@ -86,6 +87,7 @@ public abstract class JcrRdfTools {
*/
public static BiMap<String, String> rdfNamespacesToJcrNamespaces =
jcrNamespacesToRDFNamespaces.inverse();
private static LowLevelStorageService llstore = new LowLevelStorageService();

/**
* Convert a Fedora RDF Namespace into its JCR equivalent
Expand Down Expand Up @@ -251,7 +253,7 @@ public static Model getJcrPropertiesModel(final GraphSubjects factory,

final Model model = createDefaultJcrModel(node.getSession());

if (node.getPrimaryNodeType().getName().equals("mode:root")) {
if (node.getPrimaryNodeType().getName().equals(FedoraJcrTypes.ROOT)) {
/* a rdf description of the root node */
LOGGER.debug("Creating RDF response for repository description");
addRepositoryMetricsToModel(factory, node, model);
Expand Down Expand Up @@ -314,8 +316,7 @@ private static void addRepositoryMetricsToModel(final GraphSubjects factory,
/* add the configuration information */

/* Get the cluster configuration for the RDF response */
final Map<String, String> config =
new GetClusterConfiguration().apply(repository);
final Map<String, String> config = getClusterConfiguration.apply(repository);

assert (config != null);

Expand All @@ -327,17 +328,17 @@ private static void addRepositoryMetricsToModel(final GraphSubjects factory,

/* and add the repository metrics to the RDF model */
model.add(
subject,
model.createProperty("info:fedora/fedora-system:def/internal#numFixityChecks"),
ResourceFactory
.createTypedLiteral(counters
.get("org.fcrepo.services." +
"LowLevelStorageService." +
"fixity-check-counter")
.getCount()));
subject,
RdfLexicon.HAS_FIXITY_CHECK_COUNT,
ResourceFactory
.createTypedLiteral(counters
.get("org.fcrepo.services." +
"LowLevelStorageService." +
"fixity-check-counter")
.getCount()));
model.add(
subject,
model.createProperty("info:fedora/fedora-system:def/internal#numFixityErrors"),
RdfLexicon.HAS_FIXITY_ERROR_COUNT,
ResourceFactory
.createTypedLiteral(counters
.get("org.fcrepo.services." +
Expand All @@ -346,7 +347,7 @@ private static void addRepositoryMetricsToModel(final GraphSubjects factory,
.getCount()));
model.add(
subject,
model.createProperty("info:fedora/fedora-system:def/internal#numFixityRepaired"),
RdfLexicon.HAS_FIXITY_REPAIRED_COUNT,
ResourceFactory
.createTypedLiteral(counters
.get("org.fcrepo.services." +
Expand All @@ -371,8 +372,10 @@ private static void addJcrContentLocationInformationToModel(final GraphSubjects
factory.getGraphSubject(contentNode);

// TODO: get this from somewhere else.
final LowLevelStorageService llstore = new LowLevelStorageService();
llstore.setRepository(node.getSession().getRepository());

if (llstore.getRepository() != null){
llstore.setRepository(node.getSession().getRepository());
}

final Set<LowLevelCacheEntry> cacheEntries =
llstore.getLowLevelCacheEntries(contentNode);
Expand Down Expand Up @@ -788,4 +791,12 @@ public static Model getFixityResultsModel(final GraphSubjects factory,
}
return model;
}

public static void setGetClusterConfiguration(final GetClusterConfiguration getClusterConfiguration) {
JcrRdfTools.getClusterConfiguration = getClusterConfiguration;
}

public static void setLlstore(final LowLevelStorageService lowLevelStorageService) {
JcrRdfTools.llstore = lowLevelStorageService;
}
}
Expand Up @@ -58,7 +58,7 @@ public class FedoraTypesUtilsTest {
// unfortunately, we need to be able to cast to two interfaces to perform
// some tests this testing interface allows mocks to do that
static interface PropertyMock extends Property, Namespaced {
};
}

/**
* @todo Add Documentation.
Expand Down

0 comments on commit 1cd0ee7

Please sign in to comment.