PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/solr/src/test/org/apache/solr/common/params/ModifiableSolrParamsTest.java

https://github.com/simplegeo/lucene-solr
Java | 128 lines | 85 code | 27 blank | 16 comment | 1 complexity | 7162135ad357ecaaf4c8f43539693185 MD5 | raw file
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  3. * agreements. See the NOTICE file distributed with this work for additional information regarding
  4. * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
  5. * "License"); you may not use this file except in compliance with the License. You may obtain a
  6. * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
  7. * law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
  8. * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  9. * for the specific language governing permissions and limitations under the License.
  10. */
  11. package org.apache.solr.common.params;
  12. import org.apache.lucene.util.LuceneTestCase;
  13. /**
  14. * Unit Test Case for {@link org.apache.solr.common.params.ModifiableSolrParams
  15. * ModifiableSolrParams}
  16. *
  17. * @author kkumar
  18. */
  19. public class ModifiableSolrParamsTest extends LuceneTestCase
  20. {
  21. @Override
  22. public void setUp() throws Exception
  23. {
  24. super.setUp();
  25. modifiable = new ModifiableSolrParams();
  26. }
  27. @Override
  28. public void tearDown() throws Exception
  29. {
  30. modifiable.clear();
  31. super.tearDown();
  32. }
  33. public void testAdd()
  34. {
  35. String key = "key";
  36. String[] values = new String[1];
  37. values[0] = null;
  38. modifiable.add(key, values);
  39. String[] result = modifiable.getParams(key);
  40. assertEquals("params", values, result);
  41. }
  42. public void testAddNormal()
  43. {
  44. String key = "key";
  45. String[] helloWorld = new String[] { "Hello", "World" };
  46. String[] universe = new String[] { "Universe" };
  47. String[] helloWorldUniverse = new String[] { "Hello", "World", "Universe" };
  48. modifiable.add(key, helloWorld);
  49. assertEquals("checking Hello World: ", helloWorld, modifiable.getParams(key));
  50. modifiable.add(key, universe);
  51. String[] result = modifiable.getParams(key);
  52. compareArrays("checking Hello World Universe ", helloWorldUniverse, result);
  53. }
  54. public void testAddNull()
  55. {
  56. String key = "key";
  57. String[] helloWorld = new String[] { "Hello", "World" };
  58. String[] universe = new String[] { null };
  59. String[] helloWorldUniverse = new String[] { "Hello", "World", null };
  60. modifiable.add(key, helloWorld);
  61. assertEquals("checking Hello World: ", helloWorld, modifiable.getParams(key));
  62. modifiable.add(key, universe);
  63. String[] result = modifiable.getParams(key);
  64. compareArrays("checking Hello World Universe ", helloWorldUniverse, result);
  65. }
  66. public void testOldZeroLength()
  67. {
  68. String key = "key";
  69. String[] helloWorld = new String[] {};
  70. String[] universe = new String[] { "Universe" };
  71. String[] helloWorldUniverse = new String[] { "Universe" };
  72. modifiable.add(key, helloWorld);
  73. assertEquals("checking Hello World: ", helloWorld, modifiable.getParams(key));
  74. modifiable.add(key, universe);
  75. String[] result = modifiable.getParams(key);
  76. compareArrays("checking Hello World Universe ", helloWorldUniverse, result);
  77. }
  78. public void testAddPseudoNull()
  79. {
  80. String key = "key";
  81. String[] helloWorld = new String[] { "Hello", "World" };
  82. String[] universe = new String[] { "Universe", null };
  83. String[] helloWorldUniverse = new String[] { "Hello", "World", "Universe", null };
  84. modifiable.add(key, helloWorld);
  85. assertEquals("checking Hello World: ", helloWorld, modifiable.getParams(key));
  86. modifiable.add(key, universe);
  87. String[] result = modifiable.getParams(key);
  88. compareArrays("checking Hello World Universe ", helloWorldUniverse, result);
  89. }
  90. private void compareArrays(String prefix,
  91. String[] expected,
  92. String[] actual)
  93. {
  94. assertEquals(prefix + "length: ", expected.length, actual.length);
  95. for (int i = 0; i < expected.length; ++i)
  96. {
  97. assertEquals(prefix + " index " + i, expected[i], actual[i]);
  98. }
  99. }
  100. private ModifiableSolrParams modifiable;
  101. }