From 134a4a400a150a2467fc030f8920e92f3b7dcb7c Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 24 Jul 2012 04:36:52 +0000 Subject: [PATCH] LUCENE-4044: fix some more tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2510@1364881 13f79535-47bb-0310-9956-ffa450edef68 --- .../TestCommonGramsFilterFactory.java | 7 +- .../TestCommonGramsQueryFilterFactory.java | 7 +- .../analysis/core/TestStopFilterFactory.java | 4 +- .../core/TestTypeTokenFilterFactory.java | 6 +- .../apache/lucene/analysis/core/stop-1.txt | 17 ++++ .../apache/lucene/analysis/core/stop-2.txt | 17 ++++ .../lucene/analysis/core/stop-snowball.txt | 10 +++ .../lucene/analysis/core/stoptypes-1.txt | 17 ++++ .../lucene/analysis/core/stoptypes-2.txt | 17 ++++ .../analysis/fr/TestElisionFilterFactory.java | 8 +- .../lucene/analysis/fr/frenchArticles.txt | 24 ++++++ ...estDelimitedPayloadTokenFilterFactory.java | 6 +- .../util/ResourceAsStreamResourceLoader.java | 84 +++++++++++++++++++ .../util/StringMockResourceLoader.java | 51 +++++++++++ .../TestWordDelimiterFilterFactory.java | 4 +- 15 files changed, 260 insertions(+), 19 deletions(-) create mode 100644 lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-1.txt create mode 100644 lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-2.txt create mode 100644 lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-snowball.txt create mode 100644 lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stoptypes-1.txt create mode 100644 lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stoptypes-2.txt create mode 100644 lucene/analysis/common/src/test/org/apache/lucene/analysis/fr/frenchArticles.txt create mode 100644 lucene/analysis/common/src/test/org/apache/lucene/analysis/util/ResourceAsStreamResourceLoader.java create mode 100644 lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java rename {lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous => solr/core/src/test/org/apache/solr/analysis}/TestWordDelimiterFilterFactory.java (97%) diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/commongrams/TestCommonGramsFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/commongrams/TestCommonGramsFilterFactory.java index f2b9204d7db..3739f0812a6 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/commongrams/TestCommonGramsFilterFactory.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/commongrams/TestCommonGramsFilterFactory.java @@ -21,9 +21,10 @@ import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.Tokenizer; +import org.apache.lucene.analysis.core.TestStopFilter; import org.apache.lucene.analysis.util.CharArraySet; +import org.apache.lucene.analysis.util.ResourceAsStreamResourceLoader; import org.apache.lucene.analysis.util.ResourceLoader; -import org.apache.solr.core.SolrResourceLoader; import java.io.StringReader; import java.util.Collections; @@ -38,7 +39,7 @@ import java.util.HashMap; public class TestCommonGramsFilterFactory extends BaseTokenStreamTestCase { public void testInform() throws Exception { - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new ResourceAsStreamResourceLoader(TestStopFilter.class); assertTrue("loader is null and it shouldn't be", loader != null); CommonGramsFilterFactory factory = new CommonGramsFilterFactory(); Map args = new HashMap(); @@ -88,7 +89,7 @@ public class TestCommonGramsFilterFactory extends BaseTokenStreamTestCase { * If no words are provided, then a set of english default stopwords is used. */ public void testDefaults() throws Exception { - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new ResourceAsStreamResourceLoader(TestStopFilter.class); assertTrue("loader is null and it shouldn't be", loader != null); CommonGramsFilterFactory factory = new CommonGramsFilterFactory(); factory.setLuceneMatchVersion(TEST_VERSION_CURRENT); diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/commongrams/TestCommonGramsQueryFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/commongrams/TestCommonGramsQueryFilterFactory.java index 80d5534f9e7..95de4d413c1 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/commongrams/TestCommonGramsQueryFilterFactory.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/commongrams/TestCommonGramsQueryFilterFactory.java @@ -21,9 +21,10 @@ import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.Tokenizer; +import org.apache.lucene.analysis.core.TestStopFilter; import org.apache.lucene.analysis.util.CharArraySet; +import org.apache.lucene.analysis.util.ResourceAsStreamResourceLoader; import org.apache.lucene.analysis.util.ResourceLoader; -import org.apache.solr.core.SolrResourceLoader; import java.io.StringReader; import java.util.Collections; @@ -38,7 +39,7 @@ import java.util.HashMap; public class TestCommonGramsQueryFilterFactory extends BaseTokenStreamTestCase { public void testInform() throws Exception { - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new ResourceAsStreamResourceLoader(TestStopFilter.class); assertTrue("loader is null and it shouldn't be", loader != null); CommonGramsQueryFilterFactory factory = new CommonGramsQueryFilterFactory(); Map args = new HashMap(); @@ -88,7 +89,7 @@ public class TestCommonGramsQueryFilterFactory extends BaseTokenStreamTestCase { * If no words are provided, then a set of english default stopwords is used. */ public void testDefaults() throws Exception { - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new ResourceAsStreamResourceLoader(TestStopFilter.class); assertTrue("loader is null and it shouldn't be", loader != null); CommonGramsQueryFilterFactory factory = new CommonGramsQueryFilterFactory(); factory.setLuceneMatchVersion(TEST_VERSION_CURRENT); diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestStopFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestStopFilterFactory.java index a06608208a6..dc977c4f441 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestStopFilterFactory.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestStopFilterFactory.java @@ -19,8 +19,8 @@ package org.apache.lucene.analysis.core; import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.util.CharArraySet; +import org.apache.lucene.analysis.util.ResourceAsStreamResourceLoader; import org.apache.lucene.analysis.util.ResourceLoader; -import org.apache.solr.core.SolrResourceLoader; import java.util.Map; import java.util.HashMap; @@ -32,7 +32,7 @@ import java.util.HashMap; public class TestStopFilterFactory extends BaseTokenStreamTestCase { public void testInform() throws Exception { - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new ResourceAsStreamResourceLoader(getClass()); assertTrue("loader is null and it shouldn't be", loader != null); StopFilterFactory factory = new StopFilterFactory(); Map args = new HashMap(); diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestTypeTokenFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestTypeTokenFilterFactory.java index 2ed5bc78972..bf4416ffffd 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestTypeTokenFilterFactory.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestTypeTokenFilterFactory.java @@ -20,8 +20,8 @@ package org.apache.lucene.analysis.core; import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.NumericTokenStream; import org.apache.lucene.analysis.util.InitializationException; +import org.apache.lucene.analysis.util.ResourceAsStreamResourceLoader; import org.apache.lucene.analysis.util.ResourceLoader; -import org.apache.solr.core.SolrResourceLoader; import org.junit.Test; import java.util.HashMap; @@ -35,7 +35,7 @@ public class TestTypeTokenFilterFactory extends BaseTokenStreamTestCase { @Test public void testInform() throws Exception { - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new ResourceAsStreamResourceLoader(getClass()); TypeTokenFilterFactory factory = new TypeTokenFilterFactory(); Map args = new HashMap(); args.put("types", "stoptypes-1.txt"); @@ -95,7 +95,7 @@ public class TestTypeTokenFilterFactory extends BaseTokenStreamTestCase { args.put("enablePositionIncrements", "false"); typeTokenFilterFactory.setLuceneMatchVersion(TEST_VERSION_CURRENT); typeTokenFilterFactory.init(args); - typeTokenFilterFactory.inform(new SolrResourceLoader(null, null)); + typeTokenFilterFactory.inform(new ResourceAsStreamResourceLoader(getClass())); fail("not supplying 'types' parameter should cause an InitializationException"); } catch (InitializationException e) { // everything ok diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-1.txt b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-1.txt new file mode 100644 index 00000000000..8dfe80902d2 --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-1.txt @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +foo +bar \ No newline at end of file diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-2.txt b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-2.txt new file mode 100644 index 00000000000..646b7ff4ddb --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-2.txt @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +junk +more \ No newline at end of file diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-snowball.txt b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-snowball.txt new file mode 100644 index 00000000000..1c0c6f51142 --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stop-snowball.txt @@ -0,0 +1,10 @@ + | This is a file in snowball format, empty lines are ignored, '|' is a comment + | Additionally, multiple words can be on the same line, allowing stopwords to be + | arranged in tables (useful in some languages where they might inflect) + + | fictitious table below + +|third person singular +|Subject Object Possessive Reflexive +he him his himself| masculine +she her hers herself| feminine diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stoptypes-1.txt b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stoptypes-1.txt new file mode 100644 index 00000000000..456348ea9dc --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stoptypes-1.txt @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stoptypes-2.txt b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stoptypes-2.txt new file mode 100644 index 00000000000..d8a3810c26c --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/stoptypes-2.txt @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/fr/TestElisionFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/fr/TestElisionFilterFactory.java index 5770f3266bf..2c48d8e5eda 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/fr/TestElisionFilterFactory.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/fr/TestElisionFilterFactory.java @@ -27,8 +27,8 @@ import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.Tokenizer; +import org.apache.lucene.analysis.util.ResourceAsStreamResourceLoader; import org.apache.lucene.analysis.util.ResourceLoader; -import org.apache.solr.core.SolrResourceLoader; /** * Simple tests to ensure the French elision filter factory is working. @@ -42,7 +42,7 @@ public class TestElisionFilterFactory extends BaseTokenStreamTestCase { Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false); ElisionFilterFactory factory = new ElisionFilterFactory(); factory.setLuceneMatchVersion(TEST_VERSION_CURRENT); - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new ResourceAsStreamResourceLoader(getClass()); Map args = new HashMap(); args.put("articles", "frenchArticles.txt"); factory.init(args); @@ -61,7 +61,7 @@ public class TestElisionFilterFactory extends BaseTokenStreamTestCase { factory.setLuceneMatchVersion(TEST_VERSION_CURRENT); Map args = Collections.emptyMap(); factory.init(args); - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new ResourceAsStreamResourceLoader(getClass()); factory.inform(loader); TokenStream stream = factory.create(tokenizer); assertTokenStreamContents(stream, new String[] { "avion" }); @@ -75,7 +75,7 @@ public class TestElisionFilterFactory extends BaseTokenStreamTestCase { Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false); ElisionFilterFactory factory = new ElisionFilterFactory(); factory.setLuceneMatchVersion(TEST_VERSION_CURRENT); - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new ResourceAsStreamResourceLoader(getClass()); Map args = new HashMap(); args.put("articles", "frenchArticles.txt"); args.put("ignoreCase", "true"); diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/fr/frenchArticles.txt b/lucene/analysis/common/src/test/org/apache/lucene/analysis/fr/frenchArticles.txt new file mode 100644 index 00000000000..914161185f7 --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/fr/frenchArticles.txt @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# A set of articles for testing the French Elision filter. +# Requiring a text file is a bit weird here... +l +m +t +qu +n +s +j diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/TestDelimitedPayloadTokenFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/TestDelimitedPayloadTokenFilterFactory.java index 8f497abf49e..9e87d0372c5 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/TestDelimitedPayloadTokenFilterFactory.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/TestDelimitedPayloadTokenFilterFactory.java @@ -29,7 +29,7 @@ import org.apache.lucene.analysis.payloads.FloatEncoder; import org.apache.lucene.analysis.payloads.PayloadHelper; import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; import org.apache.lucene.analysis.util.ResourceLoader; -import org.apache.solr.core.SolrResourceLoader; +import org.apache.lucene.analysis.util.StringMockResourceLoader; public class TestDelimitedPayloadTokenFilterFactory extends BaseTokenStreamTestCase { @@ -38,7 +38,7 @@ public class TestDelimitedPayloadTokenFilterFactory extends BaseTokenStreamTestC args.put(DelimitedPayloadTokenFilterFactory.ENCODER_ATTR, "float"); DelimitedPayloadTokenFilterFactory factory = new DelimitedPayloadTokenFilterFactory(); factory.init(args); - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new StringMockResourceLoader("solr/collection1"); factory.inform(loader); TokenStream input = new MockTokenizer(new StringReader("the|0.1 quick|0.1 red|0.1"), MockTokenizer.WHITESPACE, false); @@ -61,7 +61,7 @@ public class TestDelimitedPayloadTokenFilterFactory extends BaseTokenStreamTestC args.put(DelimitedPayloadTokenFilterFactory.DELIMITER_ATTR, "*"); DelimitedPayloadTokenFilterFactory factory = new DelimitedPayloadTokenFilterFactory(); factory.init(args); - ResourceLoader loader = new SolrResourceLoader("solr/collection1"); + ResourceLoader loader = new StringMockResourceLoader("solr/collection1"); factory.inform(loader); TokenStream input = new MockTokenizer(new StringReader("the*0.1 quick*0.1 red*0.1"), MockTokenizer.WHITESPACE, false); diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/ResourceAsStreamResourceLoader.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/ResourceAsStreamResourceLoader.java new file mode 100644 index 00000000000..3d06aa46997 --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/ResourceAsStreamResourceLoader.java @@ -0,0 +1,84 @@ +package org.apache.lucene.analysis.util; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.CodingErrorAction; +import java.util.ArrayList; +import java.util.List; + +import org.apache.lucene.util.IOUtils; + +public class ResourceAsStreamResourceLoader implements ResourceLoader { + Class clazz; + + public ResourceAsStreamResourceLoader(Class clazz) { + this.clazz = clazz; + } + + @Override + public InputStream openResource(String resource) throws IOException { + return clazz.getResourceAsStream(resource); + } + + @Override + public List getLines(String resource) throws IOException { + BufferedReader input = null; + ArrayList lines; + try { + input = new BufferedReader(new InputStreamReader(openResource(resource), + IOUtils.CHARSET_UTF_8.newDecoder() + .onMalformedInput(CodingErrorAction.REPORT) + .onUnmappableCharacter(CodingErrorAction.REPORT))); + + lines = new ArrayList(); + for (String word=null; (word=input.readLine())!=null;) { + // skip initial bom marker + if (lines.isEmpty() && word.length() > 0 && word.charAt(0) == '\uFEFF') + word = word.substring(1); + // skip comments + if (word.startsWith("#")) continue; + word=word.trim(); + // skip blank lines + if (word.length()==0) continue; + lines.add(word); + } + } catch (CharacterCodingException ex) { + throw new RuntimeException("Error loading resource (wrong encoding?): " + resource, ex); + } finally { + if (input != null) + input.close(); + } + return lines; + } + + // TODO: do this subpackages thing... wtf is that? + @Override + public T newInstance(String cname, Class expectedType, String... subpackages) { + try { + Class clazz = Class.forName(cname).asSubclass(expectedType); + return clazz.newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java new file mode 100644 index 00000000000..2a73121c5c2 --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java @@ -0,0 +1,51 @@ +package org.apache.lucene.analysis.util; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; + +/** Fake resource loader for tests: works if you want to fake reading a single file */ +public class StringMockResourceLoader implements ResourceLoader { + String text; + + public StringMockResourceLoader(String text) { + this.text = text; + } + + public List getLines(String resource) throws IOException { + return Arrays.asList(text.split("\n")); + } + + // TODO: do this subpackages thing... wtf is that? + public T newInstance(String cname, Class expectedType, String... subpackages) { + try { + Class clazz = Class.forName(cname).asSubclass(expectedType); + return clazz.newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public InputStream openResource(String resource) throws IOException { + return new ByteArrayInputStream(text.getBytes("UTF-8")); + } +} diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestWordDelimiterFilterFactory.java b/solr/core/src/test/org/apache/solr/analysis/TestWordDelimiterFilterFactory.java similarity index 97% rename from lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestWordDelimiterFilterFactory.java rename to solr/core/src/test/org/apache/solr/analysis/TestWordDelimiterFilterFactory.java index b93bc006852..b77104cd474 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestWordDelimiterFilterFactory.java +++ b/solr/core/src/test/org/apache/solr/analysis/TestWordDelimiterFilterFactory.java @@ -1,4 +1,4 @@ -package org.apache.lucene.analysis.miscellaneous; +package org.apache.solr.analysis; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -25,6 +25,7 @@ import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.analysis.TokenStream; import org.apache.solr.SolrTestCaseJ4; +import org.apache.lucene.analysis.miscellaneous.WordDelimiterFilterFactory; import org.apache.lucene.analysis.util.ResourceLoader; import org.apache.solr.core.SolrResourceLoader; import org.junit.BeforeClass; @@ -33,6 +34,7 @@ import org.junit.Test; /** * New WordDelimiterFilter tests... most of the tests are in ConvertedLegacyTest */ +// TODO: add a low-level test for this factory public class TestWordDelimiterFilterFactory extends SolrTestCaseJ4 { @BeforeClass