Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Merged with trunk

Steven Rowe88fe5d121f65
diff --cc solr/core/src/test/org/apache/solr/core/PluginInfoTest.java
index 00000000000,c543fab0465..a42c2efd60d
mode 000000,100644..100644
--- a/solr/core/src/test/org/apache/solr/core/PluginInfoTest.java
+++ b/solr/core/src/test/org/apache/solr/core/PluginInfoTest.java
@@@ -1,0 -1,176 +1,166 @@@
-/**
++package org.apache.solr.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.
+ * 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.
+ */
+
-package org.apache.solr.core;
-
+ import java.util.List;
+
+ import org.apache.solr.util.AbstractSolrTestCase;
-
-import org.apache.solr.common.util.DOMUtilTest;
++import org.apache.solr.util.DOMUtilTestBase;
+ import org.junit.Test;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+ import org.w3c.dom.Node;
+
+ /**
+ * TestCase for PluginInfo.
- * Extends DOMUtilTest because PluginInfo heavily depends on DOMUtil
++ * Extends DOMUtilTestBase because PluginInfo heavily depends on DOMUtil
+ * and the convinient {@link #getNode(String, String)} method.
+ */
-public class PluginInfoTest extends DOMUtilTest {
++public class PluginInfoTest extends DOMUtilTestBase {
+
+ private final static String configWithNoChildren = "" +
+ "<plugin name=\"aplug\">" +
+ "<str name=\"stringer\">aString</str>" +
+ "<int name=\"inter\">1</int>" +
+ "<bool name=\"booler\">true</bool>" +
+ "<float name=\"floater\">1.1f</float>" +
+ "<double name=\"doubler\">2.2d</double>" +
+ "<long name=\"longer\">2</long>" +
+ "<lst name=\"lister\">" +
+ "</lst>" +
+ "<arr name=\"arrer\">" +
+ "<str name=\"stringer\">aString</str>" +
+ "</arr>" +
+ "</plugin>";
+ private final static String configWith2Children = "" +
+ "<plugin name=\"aplug\">" +
+ "<int name=\"inter\">1</int>" +
+ "<child name=\"child1\"><int name=\"index\">0</int></child>" +
+ "<child name=\"child2\"><int name=\"index\">1</int></child>" +
+ "<float name=\"floater\">1.1f</float>" +
+ "<double name=\"doubler\">2.2d</double>" +
+ "<long name=\"longer\">2</long>" +
+ "<lst name=\"lister\">" +
+ "</lst>" +
+ "<arr name=\"arrer\">" +
+ "<str name=\"stringer\">aString</str>" +
+ "</arr>" +
+ "</plugin>";
+
+ // This is in fact a DOMUtil test, but it is here for completeness
+ @Test
+ public void testNameRequired() throws Exception {
+ Node nodeWithNoName = getNode("<plugin></plugin>", "plugin");
+ AbstractSolrTestCase.ignoreException("missing mandatory attribute");
+ try {
+ PluginInfo pi = new PluginInfo(nodeWithNoName, "Node with No name", true, false);
+ fail("Exception should have been thrown");
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().contains("missing mandatory attribute"));
+ } finally {
+ AbstractSolrTestCase.resetExceptionIgnores();
+ }
+ Node nodeWithAName = getNode("<plugin name=\"myName\" />", "plugin");
+ PluginInfo pi2 = new PluginInfo(nodeWithAName, "Node with a Name", true, false);
+ assertTrue(pi2.name.equals("myName"));
+ }
+
+ @Test
+ public void testClassRequired() throws Exception {
+ Node nodeWithNoClass = getNode("<plugin></plugin>", "plugin");
+ AbstractSolrTestCase.ignoreException("missing mandatory attribute");
+ try {
+ @SuppressWarnings("unused")
+ PluginInfo pi = new PluginInfo(nodeWithNoClass, "Node with No Class", false, true);
+ fail("Exception should have been thrown");
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().contains("missing mandatory attribute"));
+ } finally {
+ AbstractSolrTestCase.resetExceptionIgnores();
+ }
+ Node nodeWithAClass = getNode("<plugin class=\"myName\" />", "plugin");
+ PluginInfo pi2 = new PluginInfo(nodeWithAClass, "Node with a Class", false, true);
+ assertTrue(pi2.className.equals("myName"));
+ }
+ @Test
+ public void testIsEnabled() throws Exception {
+ Node node = getNode("<plugin enable=\"true\" />", "plugin");
+ PluginInfo pi = new PluginInfo(node, "enabled", false, false);
+ assertTrue(pi.isEnabled());
+ node = getNode("<plugin enable=\"false\" />", "plugin");
+ pi = new PluginInfo(node, "not enabled", false, false);
+ assertFalse(pi.isEnabled());
+
+ }
+ @Test
+ public void testIsDefault() throws Exception {
+ Node node = getNode("<plugin default=\"true\" />", "plugin");
+ PluginInfo pi = new PluginInfo(node, "default", false, false);
+ assertTrue(pi.isDefault());
+ node = getNode("<plugin default=\"false\" />", "plugin");
+ pi = new PluginInfo(node, "not default", false, false);
+ assertFalse(pi.isDefault());
+
+ }
+ @Test
+ public void testNoChildren() throws Exception{
+ Node node = getNode(configWithNoChildren, "/plugin");
+ PluginInfo pi = new PluginInfo(node, "from static", false, false);
+ assertTrue(pi.children.isEmpty());
+ }
+
+ @Test
+ public void testHasChildren() throws Exception {
+ Node node = getNode(configWith2Children, "plugin");
+ PluginInfo pi = new PluginInfo(node, "node with 2 Children", false, false);
+ assertTrue( pi.children.size() == 2 );
+ }
+
+ @Test
+ public void testChild() throws Exception {
+ Node node = getNode(configWith2Children, "plugin");
+ PluginInfo pi = new PluginInfo(node, "with children", false, false);
+ PluginInfo childInfo = pi.getChild("child");
+ assertNotNull(childInfo);
+ PluginInfo notExistent = pi.getChild("doesnotExist");
+ assertNull(notExistent);
+ assertTrue( childInfo instanceof PluginInfo );
+ assertTrue((Integer) childInfo.initArgs.get("index") == 0);
+ Node node2 = getNode(configWithNoChildren, "plugin");
+ PluginInfo pi2 = new PluginInfo(node2, "with No Children", false, false);
+ PluginInfo noChild = pi2.getChild("long");
+ assertNull(noChild);
+
+
+ }
+ @Test
+ public void testChildren() throws Exception {
+ Node node = getNode(configWith2Children, "plugin");
+ PluginInfo pi = new PluginInfo(node, "with children", false, false);
+ List<PluginInfo> children = pi.getChildren("child");
+ assertTrue(children.size() == 2);
+ for ( PluginInfo childInfo : children ) {
+ assertNotNull(childInfo);
+ assertTrue( childInfo instanceof PluginInfo );
+ }
+ }
+ @Test
+ public void testInitArgsCount() throws Exception {
+ Node node = getNode(configWithNoChildren, "plugin");
+ PluginInfo pi = new PluginInfo(node, "from static", true, false);
+ assertTrue( pi.initArgs.size() == node.getChildNodes().getLength() );
+ }
- @Test
- @Override
- public void testAddToNamedListPrimitiveTypes() throws Exception {
- // do nothing here
- }
-
+ }
diff --cc solr/solrj/src/test/org/apache/solr/common/util/DOMUtilTest.java
index 069c2f933e1,069c2f933e1..85bbfe994e5
--- a/solr/solrj/src/test/org/apache/solr/common/util/DOMUtilTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/util/DOMUtilTest.java
@@@ -17,30 -17,30 +17,9 @@@
package org.apache.solr.common.util;
--import java.io.StringReader;
++import org.apache.solr.util.DOMUtilTestBase;
--import javax.xml.parsers.DocumentBuilder;
--import javax.xml.parsers.DocumentBuilderFactory;
--import javax.xml.xpath.XPath;
--import javax.xml.xpath.XPathConstants;
--import javax.xml.xpath.XPathFactory;
--
--import org.w3c.dom.Document;
--import org.w3c.dom.Node;
--import org.xml.sax.InputSource;
--
--import org.apache.lucene.util.LuceneTestCase;
--
--public class DOMUtilTest extends LuceneTestCase {
--
-- private DocumentBuilder builder;
-- private static final XPathFactory xpathFactory = XPathFactory.newInstance();
--
-- @Override
-- public void setUp() throws Exception {
-- super.setUp();
-- builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
-- }
++public class DOMUtilTest extends DOMUtilTestBase {
public void testAddToNamedListPrimitiveTypes() throws Exception {
NamedList<Object> namedList = new SimpleOrderedMap<Object>();
@@@ -75,17 -75,17 +54,4 @@@
assertEquals( value, v );
namedList.remove( key );
}
--
-- public Node getNode( String xml, String path ) throws Exception {
-- return getNode( getDocument(xml), path );
-- }
--
-- public Node getNode( Document doc, String path ) throws Exception {
-- XPath xpath = xpathFactory.newXPath();
-- return (Node)xpath.evaluate(path, doc, XPathConstants.NODE);
-- }
--
-- public Document getDocument( String xml ) throws Exception {
-- return builder.parse(new InputSource(new StringReader(xml)));
-- }
}
diff --cc solr/test-framework/src/java/org/apache/solr/util/DOMUtilTestBase.java
index 00000000000,00000000000..2701a72cb55
new file mode 100644
--- /dev/null
+++ b/solr/test-framework/src/java/org/apache/solr/util/DOMUtilTestBase.java
@@@ -1,0 -1,0 +1,56 @@@
++/**
++ * 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.
++ */
++
++package org.apache.solr.util;
++
++
++import java.io.StringReader;
++import javax.xml.parsers.DocumentBuilder;
++import javax.xml.parsers.DocumentBuilderFactory;
++import javax.xml.xpath.XPath;
++import javax.xml.xpath.XPathConstants;
++import javax.xml.xpath.XPathFactory;
++
++import org.apache.lucene.util.LuceneTestCase;
++import org.w3c.dom.Document;
++import org.w3c.dom.Node;
++import org.xml.sax.InputSource;
++
++public class DOMUtilTestBase extends LuceneTestCase {
++
++ private DocumentBuilder builder;
++ private static final XPathFactory xpathFactory = XPathFactory.newInstance();
++
++ @Override
++ public void setUp() throws Exception {
++ super.setUp();
++ builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
++ }
++
++ public Node getNode( String xml, String path ) throws Exception {
++ return getNode( getDocument(xml), path );
++ }
++
++ public Node getNode( Document doc, String path ) throws Exception {
++ XPath xpath = xpathFactory.newXPath();
++ return (Node)xpath.evaluate(path, doc, XPathConstants.NODE);
++ }
++
++ public Document getDocument( String xml ) throws Exception {
++ return builder.parse(new InputSource(new StringReader(xml)));
++ }
++}