Skip to content

Apache Lucene open-source search software

SOLR-4650: make BadCopyFieldTest extend AbstractBadConfigTestBase, which handles exceptions properly and deletes the core init'd to test config

Steven Rowe11068128d167
diff --git a/solr/core/src/test/org/apache/solr/schema/BadCopyFieldTest.java b/solr/core/src/test/org/apache/solr/schema/BadCopyFieldTest.java
index 01711434f5c..aca3f5ecd46 100644
--- a/solr/core/src/test/org/apache/solr/schema/BadCopyFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/BadCopyFieldTest.java
@@ -17,69 +17,42 @@
package org.apache.solr.schema;
-import org.apache.solr.SolrTestCaseJ4;
-import org.junit.Test;
+import org.apache.solr.core.AbstractBadConfigTestBase;
/**
* SOLR-4650: copyField source with no asterisk should trigger an error if it doesn't match an explicit or dynamic field
*/
-public class BadCopyFieldTest extends SolrTestCaseJ4 {
-
- @Test
- public void testNonGlobCopyFieldSourceMatchingNothingShouldFail() {
- try {
- initCore("solrconfig.xml","bad-schema-non-glob-copyfield-source-matching-nothing-should-fail-test.xml");
- } catch (Exception e) {
- assertEquals
- ("copyField source :'matches_nothing' is not a glob and doesn't match any explicit field or dynamicField.",
- e.getMessage());
- }
+public class BadCopyFieldTest extends AbstractBadConfigTestBase {
+
+ private void doTest(final String schema, final String errString) throws Exception {
+ assertConfigs("solrconfig-basic.xml", schema, errString);
+ }
+
+ public void testNonGlobCopyFieldSourceMatchingNothingShouldFail() throws Exception {
+ doTest("bad-schema-non-glob-copyfield-source-matching-nothing-should-fail-test.xml",
+ "copyField source :'matches_nothing' is not a glob and doesn't match any explicit field or dynamicField.");
}
- @Test
- public void testMultipleAsteriskCopyFieldSourceShouldFail() {
- try {
- initCore("solrconfig.xml","bad-schema-multiple-asterisk-copyfield-source-should-fail-test.xml");
- } catch (Exception e) {
- assertEquals
- ("copyField source :'*too_many_asterisks*' is an invalid glob: either it contains more than one asterisk,"
- +" or the asterisk occurs neither at the start nor at the end.",
- e.getMessage());
- }
+ private static final String INVALID_GLOB_MESSAGE = " is an invalid glob: either it contains more than one asterisk,"
+ + " or the asterisk occurs neither at the start nor at the end.";
+
+ public void testMultipleAsteriskCopyFieldSourceShouldFail() throws Exception {
+ doTest("bad-schema-multiple-asterisk-copyfield-source-should-fail-test.xml",
+ "copyField source :'*too_many_asterisks*'" + INVALID_GLOB_MESSAGE);
}
- @Test
- public void testMisplacedAsteriskCopyFieldSourceShouldFail() {
- try {
- initCore("solrconfig.xml","bad-schema-misplaced-asterisk-copyfield-source-should-fail-test.xml");
- } catch (Exception e) {
- assertEquals
- ("copyField source :'misplaced_*_asterisk' is an invalid glob: either it contains more than one asterisk,"
- +" or the asterisk occurs neither at the start nor at the end.",
- e.getMessage());
- }
+ public void testMisplacedAsteriskCopyFieldSourceShouldFail() throws Exception {
+ doTest("bad-schema-misplaced-asterisk-copyfield-source-should-fail-test.xml",
+ "copyField source :'misplaced_*_asterisk'" + INVALID_GLOB_MESSAGE);
}
- public void testMultipleAsteriskCopyFieldDestShouldFail() {
- try {
- initCore("solrconfig.xml","bad-schema-multiple-asterisk-copyfield-dest-should-fail-test.xml");
- } catch (Exception e) {
- assertEquals
- ("copyField dest :'*too_many_asterisks*' is an invalid glob: either it contains more than one asterisk,"
- +" or the asterisk occurs neither at the start nor at the end.",
- e.getMessage());
- }
+ public void testMultipleAsteriskCopyFieldDestShouldFail() throws Exception {
+ doTest("bad-schema-multiple-asterisk-copyfield-dest-should-fail-test.xml",
+ "copyField dest :'*too_many_asterisks*'" + INVALID_GLOB_MESSAGE);
}
- @Test
- public void testMisplacedAsteriskCopyFieldDestShouldFail() {
- try {
- initCore("solrconfig.xml","bad-schema-misplaced-asterisk-copyfield-dest-should-fail-test.xml");
- } catch (Exception e) {
- assertEquals
- ("copyField dest :'misplaced_*_asterisk' is an invalid glob: either it contains more than one asterisk,"
- +" or the asterisk occurs neither at the start nor at the end.",
- e.getMessage());
- }
+ public void testMisplacedAsteriskCopyFieldDestShouldFail() throws Exception {
+ doTest("bad-schema-misplaced-asterisk-copyfield-dest-should-fail-test.xml",
+ "copyField dest :'misplaced_*_asterisk'" + INVALID_GLOB_MESSAGE);
}
}