lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [20/21] lucenenet git commit: Added tests for DefaultCodecFactory, DefaultDocValuesFormatFactory, and DefaultPostingsFormatFactory
Date Sun, 12 Mar 2017 16:38:19 GMT
Added tests for DefaultCodecFactory, DefaultDocValuesFormatFactory, and DefaultPostingsFormatFactory


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/c89d4dd1
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/c89d4dd1
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/c89d4dd1

Branch: refs/heads/api-work
Commit: c89d4dd1ba1d2450dab3f8ddda8b7c4fc543ff51
Parents: 0ce32f2
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Mar 12 22:42:39 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Mar 12 23:21:38 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Tests/Lucene.Net.Tests.csproj    |   3 +
 .../Support/Codecs/TestDefaultCodecFactory.cs   | 634 +++++++++++++++++++
 .../Codecs/TestDefaultDocValuesFormatFactory.cs | 311 +++++++++
 .../Codecs/TestDefaultPostingsFormatFactory.cs  | 319 ++++++++++
 4 files changed, 1267 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c89d4dd1/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
index b8f5fc2..9f08433 100644
--- a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
+++ b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
@@ -482,6 +482,9 @@
     <Compile Include="Support\C5\SupportClasses.cs" />
     <Compile Include="Support\C5\WeakViewList.cs" />
     <Compile Include="Support\C5\Wrappers.cs" />
+    <Compile Include="Support\Codecs\TestDefaultCodecFactory.cs" />
+    <Compile Include="Support\Codecs\TestDefaultDocValuesFormatFactory.cs" />
+    <Compile Include="Support\Codecs\TestDefaultPostingsFormatFactory.cs" />
     <Compile Include="Support\TestHashMap.cs" />
     <Compile Include="Support\TestLinkedHashMap.cs" />
     <Compile Include="Support\TestLongBuffer.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c89d4dd1/src/Lucene.Net.Tests/Support/Codecs/TestDefaultCodecFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Support/Codecs/TestDefaultCodecFactory.cs b/src/Lucene.Net.Tests/Support/Codecs/TestDefaultCodecFactory.cs
new file mode 100644
index 0000000..1d611bc
--- /dev/null
+++ b/src/Lucene.Net.Tests/Support/Codecs/TestDefaultCodecFactory.cs
@@ -0,0 +1,634 @@
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
+using System.Reflection;
+
+namespace Lucene.Net.Codecs
+{
+    /*
+     * 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.
+     */
+
+    public class TestDefaultCodecFactory : LuceneTestCase
+    {
+        [Test]
+        public void TestScanLucene()
+        {
+            var factory = new DefaultCodecFactory();
+
+            var codecs = factory.AvailableServices();
+
+            assertEquals(8, codecs.Count);
+
+            assertTrue(codecs.Contains("Lucene46"));
+            assertTrue(codecs.Contains("Lucene45"));
+            assertTrue(codecs.Contains("Lucene42"));
+            assertTrue(codecs.Contains("Lucene41"));
+            assertTrue(codecs.Contains("Lucene40"));
+            assertTrue(codecs.Contains("Lucene3x"));
+            assertTrue(codecs.Contains("SimpleText"));
+            assertTrue(codecs.Contains("Appending"));
+        }
+
+        private class ScanningCodecFactory : DefaultCodecFactory
+        {
+            public ScanningCodecFactory()
+            {
+                base.ScanForCodecs(this.GetType().GetTypeInfo().Assembly);
+            }
+        }
+
+        [Test]
+        public void TestScanCustom()
+        {
+            var factory = new ScanningCodecFactory();
+
+            var codecs = factory.AvailableServices();
+
+            assertEquals(10, codecs.Count);
+
+            assertTrue(codecs.Contains("Lucene46"));
+            assertTrue(codecs.Contains("Lucene45"));
+            assertTrue(codecs.Contains("Lucene42"));
+            assertTrue(codecs.Contains("Lucene41"));
+            assertTrue(codecs.Contains("Lucene40"));
+            assertTrue(codecs.Contains("Lucene3x"));
+            assertTrue(codecs.Contains("SimpleText"));
+            assertTrue(codecs.Contains("Appending"));
+            assertTrue(codecs.Contains("Public"));
+            assertTrue(codecs.Contains("NotIgnored"));
+
+            // Ensure our local Lucene40 named type overrides
+            // the default.
+            assertEquals(typeof(TestLucene40Codec), factory.GetCodec("Lucene40").GetType());
+        }
+
+        private class ExplicitCodecFactory : DefaultCodecFactory
+        {
+            public ExplicitCodecFactory()
+            {
+                base.PutCodecType(typeof(PrivateCodec));
+            }
+        }
+
+        [Test]
+        public void TestPutExplicit()
+        {
+            var factory = new ExplicitCodecFactory();
+
+            var codecs = factory.AvailableServices();
+
+            assertTrue(codecs.Contains("Private"));
+        }
+
+        private class InvalidNameCodecFactory : DefaultCodecFactory
+        {
+            public InvalidNameCodecFactory()
+            {
+                base.PutCodecType(typeof(InvalidNamedCodec));
+            }
+        }
+
+        [Test]
+        public void TestInvalidName()
+        {
+            Assert.Throws<ArgumentException>(() => new InvalidNameCodecFactory());
+        }
+
+        private class CustomNameCodecFactory : DefaultCodecFactory
+        {
+            public CustomNameCodecFactory()
+            {
+                base.PutCodecType(typeof(CustomNamedCodec));
+            }
+        }
+
+        [Test]
+        public void TestCustomName()
+        {
+            var factory = new CustomNameCodecFactory();
+
+            assertTrue(factory.AvailableServices().Contains("FooBar"));
+        }
+
+        [Test]
+        public void TestRetrieve()
+        {
+            var factory = new DefaultCodecFactory();
+
+            var codec = factory.GetCodec("Lucene45");
+
+            assertNotNull(codec);
+#pragma warning disable 612, 618
+            assertEquals(typeof(Lucene45.Lucene45Codec), codec.GetType());
+#pragma warning restore 612, 618
+        }
+
+        [Test]
+        public void TestRetrieveCustomNamed()
+        {
+            var factory = new CustomNameCodecFactory();
+
+            var codec = factory.GetCodec("FooBar");
+
+            assertNotNull(codec);
+            assertEquals(typeof(CustomNamedCodec), codec.GetType());
+        }
+
+        private class ReplaceCodecFactory : DefaultCodecFactory
+        {
+            public ReplaceCodecFactory()
+            {
+                base.PutCodecType(typeof(TestLucene40Codec));
+            }
+        }
+
+        [Test]
+        public void TestReplace()
+        {
+            var factory = new ReplaceCodecFactory();
+
+            var codec = factory.GetCodec("Lucene40");
+
+            assertNotNull(codec);
+            assertEquals(typeof(TestLucene40Codec), codec.GetType());
+        }
+
+        private class CustomInstanceFactory : DefaultCodecFactory
+        {
+            public override Codec GetCodec(string name)
+            {
+                if (name.Equals("ThisIsATest", StringComparison.Ordinal))
+                {
+                    return new NotIgnoredCodec();
+                }
+
+                return base.GetCodec(name);
+            }
+
+            // NOTE: Typically, this would be the only method you need to override
+            // for dependency injection support.
+            protected override Codec GetCodec(Type type)
+            {
+                if (type.Equals(typeof(Lucene46.Lucene46Codec)))
+                {
+                    return new CustomNamedCodec();
+                }
+
+                return base.GetCodec(type);
+            }
+        }
+
+        /// <summary>
+        /// This is a test to simulate what would happen if a dependency injection
+        /// container were used to supply the instance
+        /// </summary>
+        [Test]
+        public void TestCustomInstanceByName()
+        {
+            var factory = new CustomInstanceFactory();
+
+            var codec = factory.GetCodec("ThisIsATest");
+
+            assertNotNull(codec);
+            assertEquals(typeof(NotIgnoredCodec), codec.GetType());
+        }
+
+        /// <summary>
+        /// This is a test to simulate what would happen if a dependency injection
+        /// container were used to supply the instance
+        /// </summary>
+        [Test]
+        public void TestCustomInstanceByType()
+        {
+            var factory = new CustomInstanceFactory();
+
+            var codec = factory.GetCodec("Lucene46");
+
+            assertNotNull(codec);
+            assertEquals(typeof(CustomNamedCodec), codec.GetType());
+        }
+    }
+
+    #region Test Classes
+    public class PublicCodec : Codec
+    {
+        public override DocValuesFormat DocValuesFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override FieldInfosFormat FieldInfosFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override LiveDocsFormat LiveDocsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override NormsFormat NormsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override PostingsFormat PostingsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override SegmentInfoFormat SegmentInfoFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override StoredFieldsFormat StoredFieldsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override TermVectorsFormat TermVectorsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+    }
+
+    internal class PrivateCodec : Codec
+    {
+        public override DocValuesFormat DocValuesFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override FieldInfosFormat FieldInfosFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override LiveDocsFormat LiveDocsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override NormsFormat NormsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override PostingsFormat PostingsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override SegmentInfoFormat SegmentInfoFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override StoredFieldsFormat StoredFieldsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override TermVectorsFormat TermVectorsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+    }
+
+    public class NotIgnoredCodec : Codec
+    {
+        public override DocValuesFormat DocValuesFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override FieldInfosFormat FieldInfosFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override LiveDocsFormat LiveDocsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override NormsFormat NormsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override PostingsFormat PostingsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override SegmentInfoFormat SegmentInfoFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override StoredFieldsFormat StoredFieldsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override TermVectorsFormat TermVectorsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+    }
+
+    [IgnoreCodec]
+    [CodecName("FooBar")]
+    public class CustomNamedCodec : Codec
+    {
+        public override DocValuesFormat DocValuesFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override FieldInfosFormat FieldInfosFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override LiveDocsFormat LiveDocsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override NormsFormat NormsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override PostingsFormat PostingsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override SegmentInfoFormat SegmentInfoFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override StoredFieldsFormat StoredFieldsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override TermVectorsFormat TermVectorsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+    }
+
+    [IgnoreCodec]
+    [CodecName("My-Codec|With-Bad_Name")]
+    public class InvalidNamedCodec : Codec
+    {
+        public override DocValuesFormat DocValuesFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override FieldInfosFormat FieldInfosFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override LiveDocsFormat LiveDocsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override NormsFormat NormsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override PostingsFormat PostingsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override SegmentInfoFormat SegmentInfoFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override StoredFieldsFormat StoredFieldsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override TermVectorsFormat TermVectorsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+    }
+
+    [CodecName("Lucene40")]
+    public class TestLucene40Codec : Codec
+    {
+        public override DocValuesFormat DocValuesFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override FieldInfosFormat FieldInfosFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override LiveDocsFormat LiveDocsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override NormsFormat NormsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override PostingsFormat PostingsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override SegmentInfoFormat SegmentInfoFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override StoredFieldsFormat StoredFieldsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+
+        public override TermVectorsFormat TermVectorsFormat
+        {
+            get
+            {
+                throw new NotImplementedException();
+            }
+        }
+    }
+    #endregion Test Classes
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c89d4dd1/src/Lucene.Net.Tests/Support/Codecs/TestDefaultDocValuesFormatFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Support/Codecs/TestDefaultDocValuesFormatFactory.cs b/src/Lucene.Net.Tests/Support/Codecs/TestDefaultDocValuesFormatFactory.cs
new file mode 100644
index 0000000..53f4f87
--- /dev/null
+++ b/src/Lucene.Net.Tests/Support/Codecs/TestDefaultDocValuesFormatFactory.cs
@@ -0,0 +1,311 @@
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
+using System.Reflection;
+using Lucene.Net.Index;
+
+namespace Lucene.Net.Codecs
+{
+    /*
+     * 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.
+     */
+
+    public class TestDefaultDocValuesFormatFactory : LuceneTestCase
+    {
+        [Test]
+        public void TestScanLucene()
+        {
+            var factory = new DefaultDocValuesFormatFactory();
+
+            var DocValuesFormats = factory.AvailableServices();
+
+            assertEquals(8, DocValuesFormats.Count);
+
+            assertTrue(DocValuesFormats.Contains("Lucene46"));
+            assertTrue(DocValuesFormats.Contains("Lucene45"));
+            assertTrue(DocValuesFormats.Contains("Lucene42"));
+            assertTrue(DocValuesFormats.Contains("Lucene41"));
+            assertTrue(DocValuesFormats.Contains("Lucene40"));
+            assertTrue(DocValuesFormats.Contains("Lucene3x"));
+            assertTrue(DocValuesFormats.Contains("SimpleText"));
+            assertTrue(DocValuesFormats.Contains("Appending"));
+        }
+
+        private class ScanningDocValuesFormatFactory : DefaultDocValuesFormatFactory
+        {
+            public ScanningDocValuesFormatFactory()
+            {
+                base.ScanForDocValuesFormats(this.GetType().GetTypeInfo().Assembly);
+            }
+        }
+
+        [Test]
+        public void TestScanCustom()
+        {
+            var factory = new ScanningDocValuesFormatFactory();
+
+            var docValuesFormats = factory.AvailableServices();
+
+            assertEquals(10, docValuesFormats.Count);
+
+            assertTrue(docValuesFormats.Contains("Lucene46"));
+            assertTrue(docValuesFormats.Contains("Lucene45"));
+            assertTrue(docValuesFormats.Contains("Lucene42"));
+            assertTrue(docValuesFormats.Contains("Lucene41"));
+            assertTrue(docValuesFormats.Contains("Lucene40"));
+            assertTrue(docValuesFormats.Contains("Lucene3x"));
+            assertTrue(docValuesFormats.Contains("SimpleText"));
+            assertTrue(docValuesFormats.Contains("Appending"));
+            assertTrue(docValuesFormats.Contains("Public"));
+            assertTrue(docValuesFormats.Contains("NotIgnored"));
+
+            // Ensure our local Lucene40 named type overrides
+            // the default.
+            assertEquals(typeof(TestLucene40DocValuesFormat), factory.GetDocValuesFormat("Lucene40").GetType());
+        }
+
+        private class ExplicitDocValuesFormatFactory : DefaultDocValuesFormatFactory
+        {
+            public ExplicitDocValuesFormatFactory()
+            {
+                base.PutDocValuesFormatType(typeof(PrivateDocValuesFormat));
+            }
+        }
+
+        [Test]
+        public void TestPutExplicit()
+        {
+            var factory = new ExplicitDocValuesFormatFactory();
+
+            var docValuesFormats = factory.AvailableServices();
+
+            assertTrue(docValuesFormats.Contains("Private"));
+        }
+
+        private class InvalidNameDocValuesFormatFactory : DefaultDocValuesFormatFactory
+        {
+            public InvalidNameDocValuesFormatFactory()
+            {
+                base.PutDocValuesFormatType(typeof(InvalidNamedDocValuesFormat));
+            }
+        }
+
+        [Test]
+        public void TestInvalidName()
+        {
+            Assert.Throws<ArgumentException>(() => new InvalidNameDocValuesFormatFactory());
+        }
+
+        private class CustomNameDocValuesFormatFactory : DefaultDocValuesFormatFactory
+        {
+            public CustomNameDocValuesFormatFactory()
+            {
+                base.PutDocValuesFormatType(typeof(CustomNamedDocValuesFormat));
+            }
+        }
+
+        [Test]
+        public void TestCustomName()
+        {
+            var factory = new CustomNameDocValuesFormatFactory();
+
+            assertTrue(factory.AvailableServices().Contains("FooBar"));
+        }
+
+        [Test]
+        public void TestRetrieve()
+        {
+            var factory = new DefaultDocValuesFormatFactory();
+
+            var DocValuesFormat = factory.GetDocValuesFormat("Lucene45");
+
+            assertNotNull(DocValuesFormat);
+#pragma warning disable 612, 618
+            assertEquals(typeof(Lucene45.Lucene45DocValuesFormat), DocValuesFormat.GetType());
+#pragma warning restore 612, 618
+        }
+
+        [Test]
+        public void TestRetrieveCustomNamed()
+        {
+            var factory = new CustomNameDocValuesFormatFactory();
+
+            var DocValuesFormat = factory.GetDocValuesFormat("FooBar");
+
+            assertNotNull(DocValuesFormat);
+            assertEquals(typeof(CustomNamedDocValuesFormat), DocValuesFormat.GetType());
+        }
+
+        private class ReplaceDocValuesFormatFactory : DefaultDocValuesFormatFactory
+        {
+            public ReplaceDocValuesFormatFactory()
+            {
+                base.PutDocValuesFormatType(typeof(TestLucene40DocValuesFormat));
+            }
+        }
+
+        [Test]
+        public void TestReplace()
+        {
+            var factory = new ReplaceDocValuesFormatFactory();
+
+            var DocValuesFormat = factory.GetDocValuesFormat("Lucene40");
+
+            assertNotNull(DocValuesFormat);
+            assertEquals(typeof(TestLucene40DocValuesFormat), DocValuesFormat.GetType());
+        }
+
+        private class CustomInstanceFactory : DefaultDocValuesFormatFactory
+        {
+            public override DocValuesFormat GetDocValuesFormat(string name)
+            {
+                if (name.Equals("ThisIsATest", StringComparison.Ordinal))
+                {
+                    return new NotIgnoredDocValuesFormat();
+                }
+
+                return base.GetDocValuesFormat(name);
+            }
+
+            // NOTE: Typically, this would be the only method you need to override
+            // for dependency injection support.
+            protected override DocValuesFormat GetDocValuesFormat(Type type)
+            {
+                if (type.Equals(typeof(Lucene45.Lucene45DocValuesFormat)))
+                {
+                    return new CustomNamedDocValuesFormat();
+                }
+
+                return base.GetDocValuesFormat(type);
+            }
+        }
+
+        /// <summary>
+        /// This is a test to simulate what would happen if a dependency injection
+        /// container were used to supply the instance
+        /// </summary>
+        [Test]
+        public void TestCustomInstanceByName()
+        {
+            var factory = new CustomInstanceFactory();
+
+            var DocValuesFormat = factory.GetDocValuesFormat("ThisIsATest");
+
+            assertNotNull(DocValuesFormat);
+            assertEquals(typeof(NotIgnoredDocValuesFormat), DocValuesFormat.GetType());
+        }
+
+        /// <summary>
+        /// This is a test to simulate what would happen if a dependency injection
+        /// container were used to supply the instance
+        /// </summary>
+        [Test]
+        public void TestCustomInstanceByType()
+        {
+            var factory = new CustomInstanceFactory();
+
+            var DocValuesFormat = factory.GetDocValuesFormat("Lucene45");
+
+            assertNotNull(DocValuesFormat);
+            assertEquals(typeof(CustomNamedDocValuesFormat), DocValuesFormat.GetType());
+        }
+    }
+
+    #region Test Classes
+    public class PublicDocValuesFormat : DocValuesFormat
+    {
+        public override DocValuesConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override DocValuesProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    internal class PrivateDocValuesFormat : DocValuesFormat
+    {
+        public override DocValuesConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override DocValuesProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    public class NotIgnoredDocValuesFormat : DocValuesFormat
+    {
+        public override DocValuesConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override DocValuesProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    [IgnoreDocValuesFormat]
+    [DocValuesFormatName("FooBar")]
+    public class CustomNamedDocValuesFormat : DocValuesFormat
+    {
+        public override DocValuesConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override DocValuesProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    [IgnoreDocValuesFormat]
+    [DocValuesFormatName("My-DocValuesFormat|With-Bad_Name")]
+    public class InvalidNamedDocValuesFormat : DocValuesFormat
+    {
+        public override DocValuesConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override DocValuesProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    [DocValuesFormatName("Lucene40")]
+    public class TestLucene40DocValuesFormat : DocValuesFormat
+    {
+        public override DocValuesConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override DocValuesProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+    #endregion Test Classes
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c89d4dd1/src/Lucene.Net.Tests/Support/Codecs/TestDefaultPostingsFormatFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Support/Codecs/TestDefaultPostingsFormatFactory.cs b/src/Lucene.Net.Tests/Support/Codecs/TestDefaultPostingsFormatFactory.cs
new file mode 100644
index 0000000..4b51cc7
--- /dev/null
+++ b/src/Lucene.Net.Tests/Support/Codecs/TestDefaultPostingsFormatFactory.cs
@@ -0,0 +1,319 @@
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
+using System.Reflection;
+using Lucene.Net.Index;
+
+namespace Lucene.Net.Codecs
+{
+    /*
+     * 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.
+     */
+
+    public class TestDefaultPostingsFormatFactory : LuceneTestCase
+    {
+        [Test]
+        public void TestScanLucene()
+        {
+            var factory = new DefaultPostingsFormatFactory();
+
+            var postingsFormats = factory.AvailableServices();
+
+            assertEquals(11, postingsFormats.Count);
+
+            assertTrue(postingsFormats.Contains("Lucene41"));
+            assertTrue(postingsFormats.Contains("Lucene40"));
+            assertTrue(postingsFormats.Contains("SimpleText"));
+            assertTrue(postingsFormats.Contains("Pulsing41"));
+            assertTrue(postingsFormats.Contains("Direct"));
+            assertTrue(postingsFormats.Contains("FSTOrd41"));
+            assertTrue(postingsFormats.Contains("FSTOrdPulsing41"));
+            assertTrue(postingsFormats.Contains("FST41"));
+            assertTrue(postingsFormats.Contains("FSTPulsing41"));
+            assertTrue(postingsFormats.Contains("Memory"));
+            assertTrue(postingsFormats.Contains("BloomFilter"));
+        }
+
+        private class ScanningPostingsFormatFactory : DefaultPostingsFormatFactory
+        {
+            public ScanningPostingsFormatFactory()
+            {
+                base.ScanForPostingsFormats(this.GetType().GetTypeInfo().Assembly);
+            }
+        }
+
+        [Test]
+        public void TestScanCustom()
+        {
+            var factory = new ScanningPostingsFormatFactory();
+
+            var postingsFormats = factory.AvailableServices();
+
+            assertEquals(13, postingsFormats.Count);
+
+            assertTrue(postingsFormats.Contains("Lucene41"));
+            assertTrue(postingsFormats.Contains("Lucene40"));
+            assertTrue(postingsFormats.Contains("SimpleText"));
+            assertTrue(postingsFormats.Contains("Pulsing41"));
+            assertTrue(postingsFormats.Contains("Direct"));
+            assertTrue(postingsFormats.Contains("FSTOrd41"));
+            assertTrue(postingsFormats.Contains("FSTOrdPulsing41"));
+            assertTrue(postingsFormats.Contains("FST41"));
+            assertTrue(postingsFormats.Contains("FSTPulsing41"));
+            assertTrue(postingsFormats.Contains("Memory"));
+            assertTrue(postingsFormats.Contains("BloomFilter"));
+            assertTrue(postingsFormats.Contains("Public"));
+            assertTrue(postingsFormats.Contains("NotIgnored"));
+
+            // Ensure our local Lucene40 named type overrides
+            // the default.
+            assertEquals(typeof(TestLucene40PostingsFormat), factory.GetPostingsFormat("Lucene40").GetType());
+        }
+
+        private class ExplicitPostingsFormatFactory : DefaultPostingsFormatFactory
+        {
+            public ExplicitPostingsFormatFactory()
+            {
+                base.PutPostingsFormatType(typeof(PrivatePostingsFormat));
+            }
+        }
+
+        [Test]
+        public void TestPutExplicit()
+        {
+            var factory = new ExplicitPostingsFormatFactory();
+
+            var postingsFormats = factory.AvailableServices();
+
+            assertTrue(postingsFormats.Contains("Private"));
+        }
+
+        private class InvalidNamePostingsFormatFactory : DefaultPostingsFormatFactory
+        {
+            public InvalidNamePostingsFormatFactory()
+            {
+                base.PutPostingsFormatType(typeof(InvalidNamedPostingsFormat));
+            }
+        }
+
+        [Test]
+        public void TestInvalidName()
+        {
+            Assert.Throws<ArgumentException>(() => new InvalidNamePostingsFormatFactory());
+        }
+
+        private class CustomNamePostingsFormatFactory : DefaultPostingsFormatFactory
+        {
+            public CustomNamePostingsFormatFactory()
+            {
+                base.PutPostingsFormatType(typeof(CustomNamedPostingsFormat));
+            }
+        }
+
+        [Test]
+        public void TestCustomName()
+        {
+            var factory = new CustomNamePostingsFormatFactory();
+
+            assertTrue(factory.AvailableServices().Contains("FooBar"));
+        }
+
+        [Test]
+        public void TestRetrieve()
+        {
+            var factory = new DefaultPostingsFormatFactory();
+
+            var PostingsFormat = factory.GetPostingsFormat("Lucene41");
+
+            assertNotNull(PostingsFormat);
+#pragma warning disable 612, 618
+            assertEquals(typeof(Lucene41.Lucene41PostingsFormat), PostingsFormat.GetType());
+#pragma warning restore 612, 618
+        }
+
+        [Test]
+        public void TestRetrieveCustomNamed()
+        {
+            var factory = new CustomNamePostingsFormatFactory();
+
+            var PostingsFormat = factory.GetPostingsFormat("FooBar");
+
+            assertNotNull(PostingsFormat);
+            assertEquals(typeof(CustomNamedPostingsFormat), PostingsFormat.GetType());
+        }
+
+        private class ReplacePostingsFormatFactory : DefaultPostingsFormatFactory
+        {
+            public ReplacePostingsFormatFactory()
+            {
+                base.PutPostingsFormatType(typeof(TestLucene40PostingsFormat));
+            }
+        }
+
+        [Test]
+        public void TestReplace()
+        {
+            var factory = new ReplacePostingsFormatFactory();
+
+            var PostingsFormat = factory.GetPostingsFormat("Lucene40");
+
+            assertNotNull(PostingsFormat);
+            assertEquals(typeof(TestLucene40PostingsFormat), PostingsFormat.GetType());
+        }
+
+        private class CustomInstanceFactory : DefaultPostingsFormatFactory
+        {
+            public override PostingsFormat GetPostingsFormat(string name)
+            {
+                if (name.Equals("ThisIsATest", StringComparison.Ordinal))
+                {
+                    return new NotIgnoredPostingsFormat();
+                }
+
+                return base.GetPostingsFormat(name);
+            }
+
+            // NOTE: Typically, this would be the only method you need to override
+            // for dependency injection support.
+            protected override PostingsFormat GetPostingsFormat(Type type)
+            {
+#pragma warning disable 612, 618
+                if (type.Equals(typeof(Lucene40.Lucene40PostingsFormat)))
+#pragma warning restore 612, 618
+                {
+                    return new CustomNamedPostingsFormat();
+                }
+
+                return base.GetPostingsFormat(type);
+            }
+        }
+
+        /// <summary>
+        /// This is a test to simulate what would happen if a dependency injection
+        /// container were used to supply the instance
+        /// </summary>
+        [Test]
+        public void TestCustomInstanceByName()
+        {
+            var factory = new CustomInstanceFactory();
+
+            var PostingsFormat = factory.GetPostingsFormat("ThisIsATest");
+
+            assertNotNull(PostingsFormat);
+            assertEquals(typeof(NotIgnoredPostingsFormat), PostingsFormat.GetType());
+        }
+
+        /// <summary>
+        /// This is a test to simulate what would happen if a dependency injection
+        /// container were used to supply the instance
+        /// </summary>
+        [Test]
+        public void TestCustomInstanceByType()
+        {
+            var factory = new CustomInstanceFactory();
+
+            var PostingsFormat = factory.GetPostingsFormat("Lucene40");
+
+            assertNotNull(PostingsFormat);
+            assertEquals(typeof(CustomNamedPostingsFormat), PostingsFormat.GetType());
+        }
+    }
+
+    #region Test Classes
+    public class PublicPostingsFormat : PostingsFormat
+    {
+        public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override FieldsProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    internal class PrivatePostingsFormat : PostingsFormat
+    {
+        public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override FieldsProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    public class NotIgnoredPostingsFormat : PostingsFormat
+    {
+        public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override FieldsProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    [IgnorePostingsFormat]
+    [PostingsFormatName("FooBar")]
+    public class CustomNamedPostingsFormat : PostingsFormat
+    {
+        public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override FieldsProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    [IgnorePostingsFormat]
+    [PostingsFormatName("My-PostingsFormat|With-Bad_Name")]
+    public class InvalidNamedPostingsFormat : PostingsFormat
+    {
+        public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override FieldsProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    [PostingsFormatName("Lucene40")]
+    public class TestLucene40PostingsFormat : PostingsFormat
+    {
+        public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override FieldsProducer FieldsProducer(SegmentReadState state)
+        {
+            throw new NotImplementedException();
+        }
+    }
+    #endregion Test Classes
+}


Mime
View raw message