You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2016/09/01 14:40:08 UTC
[47/52] [abbrv] lucenenet git commit: Ported
Analysis.Core.TestAllAnalyzersHaveFactories.
Ported Analysis.Core.TestAllAnalyzersHaveFactories.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/9ed5b8f3
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/9ed5b8f3
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/9ed5b8f3
Branch: refs/heads/master
Commit: 9ed5b8f3b44b0e2ede521608d7edaf4a9b81f92c
Parents: 0a5198e
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Fri Aug 26 13:10:26 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Sat Aug 27 02:20:02 2016 +0700
----------------------------------------------------------------------
.../Core/TestAllAnalyzersHaveFactories.cs | 315 +++++++++----------
.../Lucene.Net.Tests.Analysis.Common.csproj | 1 +
2 files changed, 153 insertions(+), 163 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9ed5b8f3/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestAllAnalyzersHaveFactories.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestAllAnalyzersHaveFactories.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestAllAnalyzersHaveFactories.cs
index 0c6a4ca..5bf0429 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestAllAnalyzersHaveFactories.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestAllAnalyzersHaveFactories.cs
@@ -1,10 +1,23 @@
-\ufeffusing System;
+\ufeffusing Lucene.Net.Analysis.Fr;
+using Lucene.Net.Analysis.In;
+using Lucene.Net.Analysis.Miscellaneous;
+using Lucene.Net.Analysis.Nl;
+using Lucene.Net.Analysis.Path;
+using Lucene.Net.Analysis.Sinks;
+using Lucene.Net.Analysis.Snowball;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Analysis.Util;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
-namespace org.apache.lucene.analysis.core
+namespace Lucene.Net.Analysis.Core
{
-
- /*
+ /*
* 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.
@@ -21,173 +34,149 @@ namespace org.apache.lucene.analysis.core
* limitations under the License.
*/
+ /// <summary>
+ /// Tests that any newly added Tokenizers/TokenFilters/CharFilters have a
+ /// corresponding factory (and that the SPI configuration is correct)
+ /// </summary>
+ public class TestAllAnalyzersHaveFactories : LuceneTestCase
+ {
- using PatternKeywordMarkerFilter = org.apache.lucene.analysis.miscellaneous.PatternKeywordMarkerFilter;
- using SetKeywordMarkerFilter = org.apache.lucene.analysis.miscellaneous.SetKeywordMarkerFilter;
- using FrenchStemFilter = org.apache.lucene.analysis.fr.FrenchStemFilter;
- using IndicTokenizer = org.apache.lucene.analysis.@in.IndicTokenizer;
- using DutchStemFilter = org.apache.lucene.analysis.nl.DutchStemFilter;
- using ReversePathHierarchyTokenizer = org.apache.lucene.analysis.path.ReversePathHierarchyTokenizer;
- using TeeSinkTokenFilter = org.apache.lucene.analysis.sinks.TeeSinkTokenFilter;
- using SnowballFilter = org.apache.lucene.analysis.snowball.SnowballFilter;
- using CharFilterFactory = org.apache.lucene.analysis.util.CharFilterFactory;
- using ResourceLoader = org.apache.lucene.analysis.util.ResourceLoader;
- using ResourceLoaderAware = org.apache.lucene.analysis.util.ResourceLoaderAware;
- using StringMockResourceLoader = org.apache.lucene.analysis.util.StringMockResourceLoader;
- using TokenFilterFactory = org.apache.lucene.analysis.util.TokenFilterFactory;
- using TokenizerFactory = org.apache.lucene.analysis.util.TokenizerFactory;
- using LuceneTestCase = org.apache.lucene.util.LuceneTestCase;
-
- /// <summary>
- /// Tests that any newly added Tokenizers/TokenFilters/CharFilters have a
- /// corresponding factory (and that the SPI configuration is correct)
- /// </summary>
- public class TestAllAnalyzersHaveFactories : LuceneTestCase
- {
-
- // these are test-only components (e.g. test-framework)
- private static readonly ISet<Type> testComponents = Collections.newSetFromMap(new IdentityHashMap<Type, bool?>());
- static TestAllAnalyzersHaveFactories()
- {
- Collections.addAll<Type>(testComponents, typeof(MockTokenizer), typeof(MockCharFilter), typeof(MockFixedLengthPayloadFilter), typeof(MockGraphTokenFilter), typeof(MockHoleInjectingTokenFilter), typeof(MockRandomLookaheadTokenFilter), typeof(MockTokenFilter), typeof(MockVariableLengthPayloadFilter), typeof(ValidatingTokenFilter), typeof(CrankyTokenFilter));
- Collections.addAll<Type>(crazyComponents, typeof(CachingTokenFilter), typeof(TeeSinkTokenFilter));
- Collections.addAll<Type>(deprecatedDuplicatedComponents, typeof(DutchStemFilter), typeof(FrenchStemFilter), typeof(IndicTokenizer));
- Collections.addAll<Type>(oddlyNamedComponents, typeof(ReversePathHierarchyTokenizer), typeof(SnowballFilter), typeof(PatternKeywordMarkerFilter), typeof(SetKeywordMarkerFilter)); // this is called SnowballPorterFilterFactory - this is supported via an option to PathHierarchyTokenizer's factory
- }
+ // these are test-only components (e.g. test-framework)
+ private static readonly ISet<Type> testComponents = new HashSet<Type>();
+ static TestAllAnalyzersHaveFactories()
+ {
+ testComponents.addAll(new Type[] { typeof(MockTokenizer), typeof(MockCharFilter), typeof(MockFixedLengthPayloadFilter), typeof(MockGraphTokenFilter), typeof(MockHoleInjectingTokenFilter), typeof(MockRandomLookaheadTokenFilter), typeof(MockTokenFilter), typeof(MockVariableLengthPayloadFilter), typeof(ValidatingTokenFilter) });
+ crazyComponents.addAll(new Type[] { typeof(CachingTokenFilter), typeof(TeeSinkTokenFilter),
+ // LUCENENET: Added this specialized BufferedCharFilter which doesn't need a factory
+ typeof(BufferedCharFilter)
+ });
+ deprecatedDuplicatedComponents.addAll(new Type[] { typeof(DutchStemFilter), typeof(FrenchStemFilter), typeof(IndicTokenizer) });
+ oddlyNamedComponents.addAll(new Type[] { typeof(ReversePathHierarchyTokenizer), typeof(SnowballFilter), typeof(PatternKeywordMarkerFilter), typeof(SetKeywordMarkerFilter) }); // this is called SnowballPorterFilterFactory - this is supported via an option to PathHierarchyTokenizer's factory
+ }
- // these are 'crazy' components like cachingtokenfilter. does it make sense to add factories for these?
- private static readonly ISet<Type> crazyComponents = Collections.newSetFromMap(new IdentityHashMap<Type, bool?>());
+ // these are 'crazy' components like cachingtokenfilter. does it make sense to add factories for these?
+ private static readonly ISet<Type> crazyComponents = new HashSet<Type>();
- // these are deprecated components that are just exact dups of other functionality: they dont need factories
- // (they never had them)
- private static readonly ISet<Type> deprecatedDuplicatedComponents = Collections.newSetFromMap(new IdentityHashMap<Type, bool?>());
+ // these are deprecated components that are just exact dups of other functionality: they dont need factories
+ // (they never had them)
+ private static readonly ISet<Type> deprecatedDuplicatedComponents = new HashSet<Type>();
- // these are oddly-named (either the actual analyzer, or its factory)
- // they do actually have factories.
- // TODO: clean this up!
- private static readonly ISet<Type> oddlyNamedComponents = Collections.newSetFromMap(new IdentityHashMap<Type, bool?>());
+ // these are oddly-named (either the actual analyzer, or its factory)
+ // they do actually have factories.
+ // TODO: clean this up!
+ private static readonly ISet<Type> oddlyNamedComponents = new HashSet<Type>();
- private static readonly ResourceLoader loader = new StringMockResourceLoader("");
+ private static readonly IResourceLoader loader = new StringMockResourceLoader("");
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public void test() throws Exception
- public virtual void test()
- {
- IList<Type> analysisClasses = new List<Type>();
- ((List<Type>)analysisClasses).AddRange(TestRandomChains.getClassesForPackage("org.apache.lucene.analysis"));
- ((List<Type>)analysisClasses).AddRange(TestRandomChains.getClassesForPackage("org.apache.lucene.collation"));
+ [Test]
+ public virtual void Test()
+ {
+ IList<Type> analysisClasses = new List<Type>(
+ typeof(StandardAnalyzer).Assembly.GetTypes()
+ .Where(c => !c.IsAbstract && c.IsPublic && !c.IsInterface && c.IsClass && (c.GetCustomAttribute<ObsoleteAttribute>() == null)
+ && !testComponents.Contains(c) && !crazyComponents.Contains(c) && !oddlyNamedComponents.Contains(c) && !deprecatedDuplicatedComponents.Contains(c)
+ && (c.IsSubclassOf(typeof(Tokenizer)) || c.IsSubclassOf(typeof(TokenFilter)) || c.IsSubclassOf(typeof(CharFilter)))
+ ));
- foreach (Class c in analysisClasses)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int modifiers = c.getModifiers();
- int modifiers = c.Modifiers;
- if (Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers) || c.Synthetic || c.AnonymousClass || c.MemberClass || c.Interface || testComponents.Contains(c) || crazyComponents.Contains(c) || oddlyNamedComponents.Contains(c) || deprecatedDuplicatedComponents.Contains(c) || c.isAnnotationPresent(typeof(Deprecated)) || !(c.IsSubclassOf(typeof(Tokenizer)) || c.IsSubclassOf(typeof(TokenFilter)) || c.IsSubclassOf(typeof(CharFilter))))
- { // deprecated ones are typically back compat hacks
- // don't waste time with abstract classes
- continue;
- }
- IDictionary<string, string> args = new Dictionary<string, string>();
- args["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString();
+ foreach (Type c in analysisClasses)
+ {
- if (c.IsSubclassOf(typeof(Tokenizer)))
- {
- string clazzName = c.SimpleName;
- assertTrue(clazzName.EndsWith("Tokenizer", StringComparison.Ordinal));
- string simpleName = clazzName.Substring(0, clazzName.Length - 9);
- assertNotNull(TokenizerFactory.lookupClass(simpleName));
- TokenizerFactory instance = null;
- try
- {
- instance = TokenizerFactory.forName(simpleName, args);
- assertNotNull(instance);
- if (instance is ResourceLoaderAware)
- {
- ((ResourceLoaderAware) instance).inform(loader);
- }
- assertSame(c, instance.create(new StringReader("")).GetType());
- }
- catch (System.ArgumentException e)
- {
- if (e.InnerException is NoSuchMethodException)
- {
- // there is no corresponding ctor available
- throw e;
- }
- // TODO: For now pass because some factories have not yet a default config that always works
- }
- }
- else if (c.IsSubclassOf(typeof(TokenFilter)))
- {
- string clazzName = c.SimpleName;
- assertTrue(clazzName.EndsWith("Filter", StringComparison.Ordinal));
- string simpleName = clazzName.Substring(0, clazzName.Length - (clazzName.EndsWith("TokenFilter", StringComparison.Ordinal) ? 11 : 6));
- assertNotNull(TokenFilterFactory.lookupClass(simpleName));
- TokenFilterFactory instance = null;
- try
- {
- instance = TokenFilterFactory.forName(simpleName, args);
- assertNotNull(instance);
- if (instance is ResourceLoaderAware)
- {
- ((ResourceLoaderAware) instance).inform(loader);
- }
-//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
-//ORIGINAL LINE: Class<? extends org.apache.lucene.analysis.TokenStream> createdClazz = instance.create(new KeywordTokenizer(new java.io.StringReader(""))).getClass();
- Type<?> createdClazz = instance.create(new KeywordTokenizer(new StringReader(""))).GetType();
- // only check instance if factory have wrapped at all!
- if (typeof(KeywordTokenizer) != createdClazz)
- {
- assertSame(c, createdClazz);
- }
- }
- catch (System.ArgumentException e)
- {
- if (e.InnerException is NoSuchMethodException)
- {
- // there is no corresponding ctor available
- throw e;
- }
- // TODO: For now pass because some factories have not yet a default config that always works
- }
- }
- else if (c.IsSubclassOf(typeof(CharFilter)))
- {
- string clazzName = c.SimpleName;
- assertTrue(clazzName.EndsWith("CharFilter", StringComparison.Ordinal));
- string simpleName = clazzName.Substring(0, clazzName.Length - 10);
- assertNotNull(CharFilterFactory.lookupClass(simpleName));
- CharFilterFactory instance = null;
- try
- {
- instance = CharFilterFactory.forName(simpleName, args);
- assertNotNull(instance);
- if (instance is ResourceLoaderAware)
- {
- ((ResourceLoaderAware) instance).inform(loader);
- }
-//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
-//ORIGINAL LINE: Class<? extends java.io.Reader> createdClazz = instance.create(new java.io.StringReader("")).getClass();
- Type<?> createdClazz = instance.create(new StringReader("")).GetType();
- // only check instance if factory have wrapped at all!
- if (typeof(StringReader) != createdClazz)
- {
- assertSame(c, createdClazz);
- }
- }
- catch (System.ArgumentException e)
- {
- if (e.InnerException is NoSuchMethodException)
- {
- // there is no corresponding ctor available
- throw e;
- }
- // TODO: For now pass because some factories have not yet a default config that always works
- }
- }
- }
- }
- }
+ IDictionary<string, string> args = new Dictionary<string, string>();
+ args["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString();
+ if (c.IsSubclassOf(typeof(Tokenizer)))
+ {
+ string clazzName = c.Name;
+ assertTrue(clazzName.EndsWith("Tokenizer", StringComparison.Ordinal));
+ string simpleName = clazzName.Substring(0, clazzName.Length - 9);
+ assertNotNull(TokenizerFactory.LookupClass(simpleName));
+ TokenizerFactory instance = null;
+ try
+ {
+ instance = TokenizerFactory.ForName(simpleName, args);
+ assertNotNull(instance);
+ if (instance is IResourceLoaderAware)
+ {
+ ((IResourceLoaderAware)instance).Inform(loader);
+ }
+ assertSame(c, instance.Create(new StringReader("")).GetType());
+ }
+ catch (System.ArgumentException e)
+ {
+ if (e.InnerException is MissingMethodException)
+ {
+ // there is no corresponding ctor available
+ throw e;
+ }
+ // TODO: For now pass because some factories have not yet a default config that always works
+ }
+ }
+ else if (c.IsSubclassOf(typeof(TokenFilter)))
+ {
+ string clazzName = c.Name;
+ assertTrue(clazzName.EndsWith("Filter", StringComparison.Ordinal));
+ string simpleName = clazzName.Substring(0, clazzName.Length - (clazzName.EndsWith("TokenFilter", StringComparison.Ordinal) ? 11 : 6));
+ assertNotNull(TokenFilterFactory.LookupClass(simpleName));
+ TokenFilterFactory instance = null;
+ try
+ {
+ instance = TokenFilterFactory.ForName(simpleName, args);
+ assertNotNull(instance);
+ if (instance is IResourceLoaderAware)
+ {
+ ((IResourceLoaderAware)instance).Inform(loader);
+ }
+ Type createdClazz = instance.Create(new KeywordTokenizer(new StringReader(""))).GetType();
+ // only check instance if factory have wrapped at all!
+ if (typeof(KeywordTokenizer) != createdClazz)
+ {
+ assertSame(c, createdClazz);
+ }
+ }
+ catch (System.ArgumentException e)
+ {
+ if (e.InnerException is MissingMethodException)
+ {
+ // there is no corresponding ctor available
+ throw e;
+ }
+ // TODO: For now pass because some factories have not yet a default config that always works
+ }
+ }
+ else if (c.IsSubclassOf(typeof(CharFilter)))
+ {
+ string clazzName = c.Name;
+ assertTrue(clazzName.EndsWith("CharFilter", StringComparison.Ordinal));
+ string simpleName = clazzName.Substring(0, clazzName.Length - 10);
+ assertNotNull(CharFilterFactory.LookupClass(simpleName));
+ CharFilterFactory instance = null;
+ try
+ {
+ instance = CharFilterFactory.ForName(simpleName, args);
+ assertNotNull(instance);
+ if (instance is IResourceLoaderAware)
+ {
+ ((IResourceLoaderAware)instance).Inform(loader);
+ }
+ Type createdClazz = instance.Create(new StringReader("")).GetType();
+ // only check instance if factory have wrapped at all!
+ if (typeof(StringReader) != createdClazz)
+ {
+ assertSame(c, createdClazz);
+ }
+ }
+ catch (System.ArgumentException e)
+ {
+ if (e.InnerException is MissingMethodException)
+ {
+ // there is no corresponding ctor available
+ throw e;
+ }
+ // TODO: For now pass because some factories have not yet a default config that always works
+ }
+ }
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9ed5b8f3/src/Lucene.Net.Tests.Analysis.Common/Lucene.Net.Tests.Analysis.Common.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Lucene.Net.Tests.Analysis.Common.csproj b/src/Lucene.Net.Tests.Analysis.Common/Lucene.Net.Tests.Analysis.Common.csproj
index cb94f28..6d6c668 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Lucene.Net.Tests.Analysis.Common.csproj
+++ b/src/Lucene.Net.Tests.Analysis.Common/Lucene.Net.Tests.Analysis.Common.csproj
@@ -87,6 +87,7 @@
<Compile Include="Analysis\Compound\TestCompoundWordTokenFilter.cs" />
<Compile Include="Analysis\Compound\TestDictionaryCompoundWordTokenFilterFactory.cs" />
<Compile Include="Analysis\Compound\TestHyphenationCompoundWordTokenFilterFactory.cs" />
+ <Compile Include="Analysis\Core\TestAllAnalyzersHaveFactories.cs" />
<Compile Include="Analysis\Core\TestAnalyzers.cs" />
<Compile Include="Analysis\Core\TestBugInSomething.cs" />
<Compile Include="Analysis\Core\TestClassicAnalyzer.cs" />