-
Notifications
You must be signed in to change notification settings - Fork 809
SOLR-15788: Remove the use of legacyExampleCollection1SolrHome() in test setup #4147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
019c088
834b060
79f1c66
11c9590
a22fea3
ce16d91
a9a9028
7e44e51
0905898
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| */ | ||
| package org.apache.solr.handler.admin; | ||
|
|
||
| import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.Set; | ||
|
|
@@ -32,12 +34,14 @@ | |
| import org.apache.solr.common.params.ModifiableSolrParams; | ||
| import org.apache.solr.common.params.SolrParams; | ||
| import org.apache.solr.common.util.ContentStreamBase; | ||
| import org.apache.solr.common.util.EnvUtils; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.apache.solr.core.SolrCore; | ||
| import org.apache.solr.request.SolrQueryRequest; | ||
| import org.apache.solr.request.SolrQueryRequestBase; | ||
| import org.apache.solr.request.SolrRequestHandler; | ||
| import org.apache.solr.response.SolrQueryResponse; | ||
| import org.apache.solr.util.ExternalPaths; | ||
| import org.apache.solr.util.SolrJettyTestRule; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
|
|
@@ -48,8 +52,13 @@ public class ShowFileRequestHandlerTest extends SolrTestCaseJ4 { | |
|
|
||
| @BeforeClass | ||
| public static void beforeTest() throws Exception { | ||
| initCore("solrconfig.xml", "schema.xml"); | ||
| solrTestRule.startSolr(legacyExampleCollection1SolrHome()); | ||
| EnvUtils.setProperty( | ||
| ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString()); | ||
| solrTestRule.startSolr(createTempDir()); | ||
| solrTestRule | ||
| .newCollection("collection1") | ||
| .withConfigSet(ExternalPaths.DEFAULT_CONFIGSET) | ||
| .create(); | ||
| } | ||
|
|
||
| private GenericSolrRequest createShowFileRequest(SolrParams params) { | ||
|
|
@@ -66,19 +75,17 @@ public void test404ViaHttp() { | |
| } | ||
|
|
||
| public void test404Locally() { | ||
| // we need to test that executing the handler directly does not | ||
| // throw an exception, just sets the exception on the response. | ||
|
|
||
| // bypass TestHarness since it will throw any exception found in the | ||
| // response. | ||
| SolrCore core = h.getCore(); | ||
| SolrQueryResponse rsp = new SolrQueryResponse(); | ||
| core.execute(core.getRequestHandler("/admin/file"), req("file", "does-not-exist-404.txt"), rsp); | ||
| assertNotNull("no exception in response", rsp.getException()); | ||
| assertTrue( | ||
| "wrong type of exception: " + rsp.getException().getClass(), | ||
| rsp.getException() instanceof SolrException); | ||
| assertEquals(404, ((SolrException) rsp.getException()).code()); | ||
| try (SolrCore core = solrTestRule.getCoreContainer().getCore("collection1")) { | ||
| SolrQueryResponse rsp = new SolrQueryResponse(); | ||
| SolrQueryRequest req = | ||
| new SolrQueryRequestBase(core, params("file", "does-not-exist-404.txt")); | ||
| core.execute(core.getRequestHandler("/admin/file"), req, rsp); | ||
| assertNotNull("no exception in response", rsp.getException()); | ||
| assertTrue( | ||
| "wrong type of exception: " + rsp.getException().getClass(), | ||
| rsp.getException() instanceof SolrException); | ||
| assertEquals(404, ((SolrException) rsp.getException()).code()); | ||
| } | ||
| } | ||
|
|
||
| public void testDirList() throws SolrServerException, IOException { | ||
|
|
@@ -119,26 +126,17 @@ public Set<String> getContentTypes() { | |
| } | ||
|
|
||
| public void testContentTypeHtmlBecomesTextPlain() { | ||
| SolrRequestHandler handler = h.getCore().getRequestHandler("/admin/file"); | ||
| SolrQueryRequest req = | ||
| new SolrQueryRequestBase( | ||
| h.getCore(), params("file", "schema.xml", "contentType", "text/html")); | ||
| SolrQueryResponse rsp = new SolrQueryResponse(); | ||
| handler.handleRequest(req, rsp); | ||
| ContentStreamBase.FileStream content = | ||
| (ContentStreamBase.FileStream) rsp.getValues().get("content"); | ||
| assertEquals("text/plain", content.getContentType()); | ||
| } | ||
|
|
||
| public void testContentTypeHtmlDefault() { | ||
| SolrRequestHandler handler = h.getCore().getRequestHandler("/admin/file"); | ||
| SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params("file", "example.html")); | ||
| SolrQueryResponse rsp = new SolrQueryResponse(); | ||
| handler.handleRequest(req, rsp); | ||
| ContentStreamBase.FileStream content = | ||
| (ContentStreamBase.FileStream) rsp.getValues().get("content"); | ||
| // System attempts to guess content type, but will only return XML, JSON, CSV, never HTML | ||
| assertEquals("application/xml", content.getContentType()); | ||
| try (SolrCore core = solrTestRule.getCoreContainer().getCore("collection1")) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whyis this called "collection1"? that's ugly. SHouldn't it be called "core1"?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quite a while ago, we standardized on "collection1" no matter what Solr's mode is. I like it. |
||
| SolrRequestHandler handler = core.getRequestHandler("/admin/file"); | ||
| SolrQueryRequest req = | ||
| new SolrQueryRequestBase( | ||
| core, params("file", "managed-schema.xml", "contentType", "text/html")); | ||
| SolrQueryResponse rsp = new SolrQueryResponse(); | ||
| handler.handleRequest(req, rsp); | ||
| ContentStreamBase.FileStream content = | ||
| (ContentStreamBase.FileStream) rsp.getValues().get("content"); | ||
| assertEquals("text/plain", content.getContentType()); | ||
| } | ||
| } | ||
|
|
||
| public void testIllegalContentType() throws SolrServerException, IOException { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method demonstrates what we have to start doing to get rid of
h.getCore...