VIVO-742 Create the interfaces for Application and SearchEngine

Also some stubs for unit tests.
This commit is contained in:
Jim Blake 2014-04-22 10:32:27 -04:00
parent b20445b233
commit 6329343465
16 changed files with 886 additions and 0 deletions

View file

@ -0,0 +1,61 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package stubs.edu.cornell.mannlib.vitro.webapp.modules;
import java.lang.reflect.Field;
import javax.servlet.ServletContext;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
/**
* TODO
*/
public class ApplicationStub implements Application {
/**
* Create an ApplicationStub and set it as the instance in ApplicationUtils.
*/
public static void setup(ServletContext ctx, SearchEngine searchEngine) {
ApplicationStub instance = new ApplicationStub(ctx, searchEngine);
try {
Field instanceField = ApplicationUtils.class
.getDeclaredField("instance");
instanceField.setAccessible(true);
instanceField.set(null, instance);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
private final ServletContext ctx;
private final SearchEngine searchEngine;
public ApplicationStub(ServletContext ctx, SearchEngine searchEngine) {
this.ctx = ctx;
this.searchEngine = searchEngine;
}
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
@Override
public ServletContext getServletContext() {
return ctx;
}
@Override
public SearchEngine getSearchEngine() {
return searchEngine;
}
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
}

View file

@ -0,0 +1,136 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse;
/**
* TODO
*/
public class SearchEngineStub implements SearchEngine {
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
Map<String, SearchResponseStub> queryResponses = new HashMap<>();
public void setQueryResponse(String queryText, SearchResponseStub response) {
queryResponses.put(queryText, response);
}
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
@Override
public SearchQuery createQuery() {
return new SearchQueryStub();
}
@Override
public SearchQuery createQuery(String queryText) {
return new SearchQueryStub(queryText);
}
@Override
public SearchResponse query(SearchQuery query) throws SearchEngineException {
SearchResponseStub response = queryResponses.get(query.getQuery());
if (response == null) {
return SearchResponseStub.EMPTY_RESPONSE;
} else {
return response;
}
}
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public void startup(Application application, ComponentStartupStatus ss) {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchEngineStub.startup() not implemented.");
}
@Override
public void shutdown(Application application) {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchEngineStub.shutdown() not implemented.");
}
@Override
public void ping() throws SearchEngineException {
// TODO Auto-generated method stub
throw new RuntimeException("SearchEngineStub.ping() not implemented.");
}
@Override
public SearchInputDocument createInputDocument() {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchEngineStub.createInputDocument() not implemented.");
}
@Override
public void add(SearchInputDocument... docs) throws SearchEngineException {
// TODO Auto-generated method stub
throw new RuntimeException("SearchEngineStub.add() not implemented.");
}
@Override
public void add(Collection<SearchInputDocument> docs)
throws SearchEngineException {
// TODO Auto-generated method stub
throw new RuntimeException("SearchEngineStub.add() not implemented.");
}
@Override
public void commit() throws SearchEngineException {
// TODO Auto-generated method stub
throw new RuntimeException("SearchEngineStub.commit() not implemented.");
}
@Override
public void commit(boolean wait) throws SearchEngineException {
// TODO Auto-generated method stub
throw new RuntimeException("SearchEngineStub.commit() not implemented.");
}
@Override
public void deleteById(String... ids) throws SearchEngineException {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchEngineStub.deleteById() not implemented.");
}
@Override
public void deleteById(Collection<String> ids) throws SearchEngineException {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchEngineStub.deleteById() not implemented.");
}
@Override
public void deleteByQuery(String query) throws SearchEngineException {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchEngineStub.deleteByQuery() not implemented.");
}
}

View file

@ -0,0 +1,38 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine;
import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchQuery;
/**
* TODO
*/
public class SearchQueryStub extends BaseSearchQuery {
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
/**
* @param queryText
*/
public SearchQueryStub() {
super();
}
/**
* @param queryText
*/
public SearchQueryStub(String queryText) {
super();
setQuery(queryText);
}
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
}

View file

@ -0,0 +1,60 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine;
import java.util.List;
import java.util.Map;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList;
/**
* TODO
*/
public class SearchResponseStub implements SearchResponse {
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
public static final SearchResponseStub EMPTY_RESPONSE = null;
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public SearchResultDocumentList getResults() {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchResponseStub.getResults() not implemented.");
}
@Override
public Map<String, Map<String, List<String>>> getHighlighting() {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchResponseStub.getHighlighting() not implemented.");
}
@Override
public SearchFacetField getFacetField(String name) {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchResponseStub.getFacetField() not implemented.");
}
@Override
public List<SearchFacetField> getFacetFields() {
// TODO Auto-generated method stub
throw new RuntimeException(
"SearchResponseStub.getFacetFields() not implemented.");
}
}