Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DA10C200B74 for ; Thu, 1 Sep 2016 16:39:29 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D7410160AA8; Thu, 1 Sep 2016 14:39:29 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F4024160ACE for ; Thu, 1 Sep 2016 16:39:26 +0200 (CEST) Received: (qmail 71790 invoked by uid 500); 1 Sep 2016 14:39:25 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 70995 invoked by uid 99); 1 Sep 2016 14:39:24 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Sep 2016 14:39:24 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7FA4CDF9F1; Thu, 1 Sep 2016 14:39:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: synhershko@apache.org To: commits@lucenenet.apache.org Date: Thu, 01 Sep 2016 14:40:08 -0000 Message-Id: <6a886437cea44d6e8e71ca4c624a34d1@git.apache.org> In-Reply-To: <8ca16dfa9b744f62a1ee6e6469fe3783@git.apache.org> References: <8ca16dfa9b744f62a1ee6e6469fe3783@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [47/52] [abbrv] lucenenet git commit: Ported Analysis.Core.TestAllAnalyzersHaveFactories. archived-at: Thu, 01 Sep 2016 14:39:30 -0000 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 Authored: Fri Aug 26 13:10:26 2016 +0700 Committer: Shad Storhaug 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 @@ -using System; +using 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. */ + /// + /// Tests that any newly added Tokenizers/TokenFilters/CharFilters have a + /// corresponding factory (and that the SPI configuration is correct) + /// + 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; - - /// - /// Tests that any newly added Tokenizers/TokenFilters/CharFilters have a - /// corresponding factory (and that the SPI configuration is correct) - /// - public class TestAllAnalyzersHaveFactories : LuceneTestCase - { - - // these are test-only components (e.g. test-framework) - private static readonly ISet testComponents = Collections.newSetFromMap(new IdentityHashMap()); - static TestAllAnalyzersHaveFactories() - { - Collections.addAll(testComponents, typeof(MockTokenizer), typeof(MockCharFilter), typeof(MockFixedLengthPayloadFilter), typeof(MockGraphTokenFilter), typeof(MockHoleInjectingTokenFilter), typeof(MockRandomLookaheadTokenFilter), typeof(MockTokenFilter), typeof(MockVariableLengthPayloadFilter), typeof(ValidatingTokenFilter), typeof(CrankyTokenFilter)); - Collections.addAll(crazyComponents, typeof(CachingTokenFilter), typeof(TeeSinkTokenFilter)); - Collections.addAll(deprecatedDuplicatedComponents, typeof(DutchStemFilter), typeof(FrenchStemFilter), typeof(IndicTokenizer)); - Collections.addAll(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 testComponents = new HashSet(); + 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 crazyComponents = Collections.newSetFromMap(new IdentityHashMap()); + // these are 'crazy' components like cachingtokenfilter. does it make sense to add factories for these? + private static readonly ISet crazyComponents = new HashSet(); - // these are deprecated components that are just exact dups of other functionality: they dont need factories - // (they never had them) - private static readonly ISet deprecatedDuplicatedComponents = Collections.newSetFromMap(new IdentityHashMap()); + // these are deprecated components that are just exact dups of other functionality: they dont need factories + // (they never had them) + private static readonly ISet deprecatedDuplicatedComponents = new HashSet(); - // these are oddly-named (either the actual analyzer, or its factory) - // they do actually have factories. - // TODO: clean this up! - private static readonly ISet oddlyNamedComponents = Collections.newSetFromMap(new IdentityHashMap()); + // these are oddly-named (either the actual analyzer, or its factory) + // they do actually have factories. + // TODO: clean this up! + private static readonly ISet oddlyNamedComponents = new HashSet(); - 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 analysisClasses = new List(); - ((List)analysisClasses).AddRange(TestRandomChains.getClassesForPackage("org.apache.lucene.analysis")); - ((List)analysisClasses).AddRange(TestRandomChains.getClassesForPackage("org.apache.lucene.collation")); + [Test] + public virtual void Test() + { + IList analysisClasses = new List( + typeof(StandardAnalyzer).Assembly.GetTypes() + .Where(c => !c.IsAbstract && c.IsPublic && !c.IsInterface && c.IsClass && (c.GetCustomAttribute() == 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 args = new Dictionary(); - 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 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 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 args = new Dictionary(); + 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 @@ +