Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding VisibleForTesting annotation, replacing magic numbers with var…
…iables for likely webapp/REST API path components
  • Loading branch information
escowles committed Jul 29, 2014
1 parent 2558c0e commit 25bd357
Showing 1 changed file with 11 additions and 5 deletions.
Expand Up @@ -15,6 +15,7 @@
*/
package org.fcrepo.indexer;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Supplier;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.NodeIterator;
Expand Down Expand Up @@ -69,6 +70,7 @@ public class IndexerGroup implements MessageListener {

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

@VisibleForTesting
protected final Set<Indexer<Object>> indexers;

private Set<String> reindexed;
Expand Down Expand Up @@ -123,6 +125,9 @@ public class IndexerGroup implements MessageListener {
public static final Resource INDEXABLE_MIXIN =
createResource(INDEXER_NAMESPACE + "indexable");

private static final String REST_PREFIX = "/rest/";
private static final String FCREPO_PREFIX = "/fcrepo/";

/**
* Indicates that a resource is a datastream.
**/
Expand Down Expand Up @@ -151,7 +156,7 @@ public IndexerGroup(final Set<Indexer<Object>> indexers,
}

/**
* Constructor with provided default HttpClient instance.
* Constructor with provided default HttpClient instance added for testing.
**/
public IndexerGroup(final Set<Indexer<Object>> indexers, final DefaultHttpClient httpClient) {
LOGGER.debug("Creating IndexerGroup: {}", this);
Expand All @@ -162,6 +167,7 @@ public IndexerGroup(final Set<Indexer<Object>> indexers, final DefaultHttpClient
this.defaultClient = httpClient;
}

@VisibleForTesting
protected DefaultHttpClient httpClient(final String repositoryURL) {
// try to find existing client
if ( clients.size() > 0 ) {
Expand All @@ -179,10 +185,10 @@ protected DefaultHttpClient httpClient(final String repositoryURL) {

// if no existing client matched, create a new one
final String baseURL;
if ( repositoryURL.indexOf("/rest/") > 0 ) {
baseURL = repositoryURL.substring(0, repositoryURL.indexOf("/rest/") + 6);
} else if ( repositoryURL.indexOf("/",8) > 0 ) {
baseURL = repositoryURL.substring(0, repositoryURL.indexOf("/",8) + 1);
if ( repositoryURL.indexOf(REST_PREFIX) > 0 ) {
baseURL = repositoryURL.substring(0, repositoryURL.indexOf(REST_PREFIX) + REST_PREFIX.length());
} else if ( repositoryURL.indexOf("/",FCREPO_PREFIX.length()) > 0 ) {
baseURL = repositoryURL.substring(0, repositoryURL.indexOf("/",FCREPO_PREFIX.length()) + 1);
} else {
baseURL = repositoryURL;
}
Expand Down

0 comments on commit 25bd357

Please sign in to comment.