NIHVIVO-3542 Clean up the unit test for IndividualRequestAnalyzer - move the stub class into its own file.
This commit is contained in:
parent
bf61f9a168
commit
fff0167211
2 changed files with 92 additions and 84 deletions
|
@ -9,16 +9,14 @@ import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertNotNull;
|
import static junit.framework.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import stubs.edu.cornell.mannlib.vitro.webapp.beans.IndividualStub;
|
import stubs.edu.cornell.mannlib.vitro.webapp.beans.IndividualStub;
|
||||||
|
import stubs.edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalysisContextStub;
|
||||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||||
|
|
||||||
|
@ -64,7 +62,7 @@ public class IndividualRequestAnalyzerTest extends AbstractTestClass {
|
||||||
+ ID_INDIVIDUAL_FOREIGN;
|
+ ID_INDIVIDUAL_FOREIGN;
|
||||||
|
|
||||||
private IndividualRequestAnalyzer analyzer;
|
private IndividualRequestAnalyzer analyzer;
|
||||||
private MyAnalysisContext analysisContext;
|
private IndividualRequestAnalysisContextStub analysisContext;
|
||||||
private HttpServletRequestStub req;
|
private HttpServletRequestStub req;
|
||||||
private VitroRequest vreq;
|
private VitroRequest vreq;
|
||||||
private IndividualRequestInfo requestInfo;
|
private IndividualRequestInfo requestInfo;
|
||||||
|
@ -76,7 +74,7 @@ public class IndividualRequestAnalyzerTest extends AbstractTestClass {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
req = new HttpServletRequestStub();
|
req = new HttpServletRequestStub();
|
||||||
analysisContext = new MyAnalysisContext(DEFAULT_NAMESPACE);
|
analysisContext = new IndividualRequestAnalysisContextStub(DEFAULT_NAMESPACE);
|
||||||
|
|
||||||
testIndividual = new IndividualStub(URI_INDIVIDUAL_TEST);
|
testIndividual = new IndividualStub(URI_INDIVIDUAL_TEST);
|
||||||
analysisContext.addIndividual(testIndividual);
|
analysisContext.addIndividual(testIndividual);
|
||||||
|
@ -398,83 +396,4 @@ public class IndividualRequestAnalyzerTest extends AbstractTestClass {
|
||||||
requestInfo.getRdfFormat());
|
requestInfo.getRdfFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Supporting classes
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
private static class MyAnalysisContext implements
|
|
||||||
IndividualRequestAnalysisContext {
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Stub infrastructure
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
private final String defaultNamespace;
|
|
||||||
private final Map<String, Individual> individualsByUri = new HashMap<String, Individual>();
|
|
||||||
private final Map<String, Individual> profilePages = new HashMap<String, Individual>();
|
|
||||||
private final Map<String, String> namespacesByPrefix = new HashMap<String, String>();
|
|
||||||
private final Map<String, String> aliasUrlsByIndividual = new HashMap<String, String>();
|
|
||||||
|
|
||||||
public MyAnalysisContext(String defaultNamespace) {
|
|
||||||
this.defaultNamespace = defaultNamespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addIndividual(Individual individual) {
|
|
||||||
individualsByUri.put(individual.getURI(), individual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addProfilePage(String netId, Individual individual) {
|
|
||||||
profilePages.put(netId, individual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNamespacePrefix(String prefix, String namespace) {
|
|
||||||
namespacesByPrefix.put(prefix, namespace);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAliasUrl(String individualUri, String aliasUrl) {
|
|
||||||
aliasUrlsByIndividual.put(individualUri, aliasUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Stub methods
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDefaultNamespace() {
|
|
||||||
return defaultNamespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNamespaceForPrefix(String prefix) {
|
|
||||||
if (prefix == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String namespace = namespacesByPrefix.get(prefix);
|
|
||||||
return (namespace == null) ? "" : namespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Individual getIndividualByURI(String individualUri) {
|
|
||||||
if (individualUri == null) {
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
return individualsByUri.get(individualUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Individual getIndividualByNetId(String netId) {
|
|
||||||
if (netId == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return profilePages.get(netId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAliasUrlForBytestreamIndividual(Individual individual) {
|
|
||||||
if (individual == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return aliasUrlsByIndividual.get(individual.getURI());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package stubs.edu.cornell.mannlib.vitro.webapp.controller.individual;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalysisContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple implementation of the Analysis Context for the Individual Request.
|
||||||
|
*/
|
||||||
|
public class IndividualRequestAnalysisContextStub implements
|
||||||
|
IndividualRequestAnalysisContext {
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Stub infrastructure
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
private final String defaultNamespace;
|
||||||
|
private final Map<String, Individual> individualsByUri = new HashMap<String, Individual>();
|
||||||
|
private final Map<String, Individual> profilePages = new HashMap<String, Individual>();
|
||||||
|
private final Map<String, String> namespacesByPrefix = new HashMap<String, String>();
|
||||||
|
private final Map<String, String> aliasUrlsByIndividual = new HashMap<String, String>();
|
||||||
|
|
||||||
|
public IndividualRequestAnalysisContextStub(String defaultNamespace) {
|
||||||
|
this.defaultNamespace = defaultNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addIndividual(Individual individual) {
|
||||||
|
individualsByUri.put(individual.getURI(), individual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addProfilePage(String netId, Individual individual) {
|
||||||
|
profilePages.put(netId, individual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNamespacePrefix(String prefix, String namespace) {
|
||||||
|
namespacesByPrefix.put(prefix, namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAliasUrl(String individualUri, String aliasUrl) {
|
||||||
|
aliasUrlsByIndividual.put(individualUri, aliasUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Stub methods
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultNamespace() {
|
||||||
|
return defaultNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNamespaceForPrefix(String prefix) {
|
||||||
|
if (prefix == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String namespace = namespacesByPrefix.get(prefix);
|
||||||
|
return (namespace == null) ? "" : namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Individual getIndividualByURI(String individualUri) {
|
||||||
|
if (individualUri == null) {
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
return individualsByUri.get(individualUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Individual getIndividualByNetId(String netId) {
|
||||||
|
if (netId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return profilePages.get(netId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAliasUrlForBytestreamIndividual(Individual individual) {
|
||||||
|
if (individual == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return aliasUrlsByIndividual.get(individual.getURI());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue