diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index de6e3107144..d4b79efc8a5 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -290,6 +290,9 @@ Other Changes * SOLR-8305: replace LatLonType.getValueSource's QParser use (Christine Poerschke) +* SOLR-8388: factor out response/TestSolrQueryResponse.java from servlet/ResponseHeaderTest.java + (Christine Poerschke) + ================== 5.4.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release diff --git a/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java b/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java new file mode 100644 index 00000000000..98b39475b44 --- /dev/null +++ b/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java @@ -0,0 +1,159 @@ +package org.apache.solr.response; + +/* + * 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. + */ + +import org.apache.lucene.util.LuceneTestCase; +import org.apache.solr.response.SolrQueryResponse; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map.Entry; + + +public class TestSolrQueryResponse extends LuceneTestCase { + + @Test + public void testAddHttpHeader() { + SolrQueryResponse response = new SolrQueryResponse(); + Iterator> it = response.httpHeaders(); + assertFalse(it.hasNext()); + + response.addHttpHeader("key1", "value1"); + it = response.httpHeaders(); + assertTrue(it.hasNext()); + Entry entry = it.next(); + assertEquals("key1", entry.getKey()); + assertEquals("value1", entry.getValue()); + assertFalse(it.hasNext()); + + response.addHttpHeader("key1", "value2"); + it = response.httpHeaders(); + assertTrue(it.hasNext()); + entry = it.next(); + assertEquals("key1", entry.getKey()); + assertEquals("value1", entry.getValue()); + assertTrue(it.hasNext()); + entry = it.next(); + assertEquals("key1", entry.getKey()); + assertEquals("value2", entry.getValue()); + assertFalse(it.hasNext()); + + response.addHttpHeader("key2", "value2"); + it = response.httpHeaders(); + assertTrue(it.hasNext()); + entry = it.next(); + assertEquals("key1", entry.getKey()); + assertEquals("value1", entry.getValue()); + assertTrue(it.hasNext()); + entry = it.next(); + assertEquals("key1", entry.getKey()); + assertEquals("value2", entry.getValue()); + assertTrue(it.hasNext()); + entry = it.next(); + assertEquals("key2", entry.getKey()); + assertEquals("value2", entry.getValue()); + assertFalse(it.hasNext()); + } + + @Test + public void testSetHttpHeader() { + SolrQueryResponse response = new SolrQueryResponse(); + Iterator> it = response.httpHeaders(); + assertFalse(it.hasNext()); + + response.setHttpHeader("key1", "value1"); + it = response.httpHeaders(); + assertTrue(it.hasNext()); + Entry entry = it.next(); + assertEquals("key1", entry.getKey()); + assertEquals("value1", entry.getValue()); + assertFalse(it.hasNext()); + + response.setHttpHeader("key1", "value2"); + it = response.httpHeaders(); + assertTrue(it.hasNext()); + entry = it.next(); + assertEquals("key1", entry.getKey()); + assertEquals("value2", entry.getValue()); + assertFalse(it.hasNext()); + + response.addHttpHeader("key1", "value3"); + response.setHttpHeader("key1", "value4"); + it = response.httpHeaders(); + assertTrue(it.hasNext()); + entry = it.next(); + assertEquals("key1", entry.getKey()); + assertEquals("value4", entry.getValue()); + assertFalse(it.hasNext()); + + response.setHttpHeader("key2", "value5"); + it = response.httpHeaders(); + assertTrue(it.hasNext()); + entry = it.next(); + assertEquals("key1", entry.getKey()); + assertEquals("value4", entry.getValue()); + assertTrue(it.hasNext()); + entry = it.next(); + assertEquals("key2", entry.getKey()); + assertEquals("value5", entry.getValue()); + assertFalse(it.hasNext()); + } + + @Test + public void testRemoveHttpHeader() { + SolrQueryResponse response = new SolrQueryResponse(); + Iterator> it = response.httpHeaders(); + assertFalse(it.hasNext()); + response.addHttpHeader("key1", "value1"); + assertTrue(response.httpHeaders().hasNext()); + assertEquals("value1", response.removeHttpHeader("key1")); + assertFalse(response.httpHeaders().hasNext()); + + response.addHttpHeader("key1", "value2"); + response.addHttpHeader("key1", "value3"); + response.addHttpHeader("key2", "value4"); + assertTrue(response.httpHeaders().hasNext()); + assertEquals("value2", response.removeHttpHeader("key1")); + assertEquals("value3", response.httpHeaders().next().getValue()); + assertEquals("value3", response.removeHttpHeader("key1")); + assertNull(response.removeHttpHeader("key1")); + assertEquals("key2", response.httpHeaders().next().getKey()); + + } + + @Test + public void testRemoveHttpHeaders() { + SolrQueryResponse response = new SolrQueryResponse(); + Iterator> it = response.httpHeaders(); + assertFalse(it.hasNext()); + response.addHttpHeader("key1", "value1"); + assertTrue(response.httpHeaders().hasNext()); + assertEquals(Arrays.asList("value1"), response.removeHttpHeaders("key1")); + assertFalse(response.httpHeaders().hasNext()); + + response.addHttpHeader("key1", "value2"); + response.addHttpHeader("key1", "value3"); + response.addHttpHeader("key2", "value4"); + assertTrue(response.httpHeaders().hasNext()); + assertEquals(Arrays.asList(new String[]{"value2", "value3"}), response.removeHttpHeaders("key1")); + assertNull(response.removeHttpHeaders("key1")); + assertEquals("key2", response.httpHeaders().next().getKey()); + } + +} diff --git a/solr/core/src/test/org/apache/solr/servlet/ResponseHeaderTest.java b/solr/core/src/test/org/apache/solr/servlet/ResponseHeaderTest.java index c45f37897e3..61392c35f29 100644 --- a/solr/core/src/test/org/apache/solr/servlet/ResponseHeaderTest.java +++ b/solr/core/src/test/org/apache/solr/servlet/ResponseHeaderTest.java @@ -78,134 +78,6 @@ public class ResponseHeaderTest extends SolrJettyTestBase { assertTrue("Expected header not found", containsWarningHeader); } - @Test - public void testAddHttpHeader() { - SolrQueryResponse response = new SolrQueryResponse(); - Iterator> it = response.httpHeaders(); - assertFalse(it.hasNext()); - - response.addHttpHeader("key1", "value1"); - it = response.httpHeaders(); - assertTrue(it.hasNext()); - Entry entry = it.next(); - assertEquals("key1", entry.getKey()); - assertEquals("value1", entry.getValue()); - assertFalse(it.hasNext()); - - response.addHttpHeader("key1", "value2"); - it = response.httpHeaders(); - assertTrue(it.hasNext()); - entry = it.next(); - assertEquals("key1", entry.getKey()); - assertEquals("value1", entry.getValue()); - assertTrue(it.hasNext()); - entry = it.next(); - assertEquals("key1", entry.getKey()); - assertEquals("value2", entry.getValue()); - assertFalse(it.hasNext()); - - response.addHttpHeader("key2", "value2"); - it = response.httpHeaders(); - assertTrue(it.hasNext()); - entry = it.next(); - assertEquals("key1", entry.getKey()); - assertEquals("value1", entry.getValue()); - assertTrue(it.hasNext()); - entry = it.next(); - assertEquals("key1", entry.getKey()); - assertEquals("value2", entry.getValue()); - assertTrue(it.hasNext()); - entry = it.next(); - assertEquals("key2", entry.getKey()); - assertEquals("value2", entry.getValue()); - assertFalse(it.hasNext()); - } - - @Test - public void testSetHttpHeader() { - SolrQueryResponse response = new SolrQueryResponse(); - Iterator> it = response.httpHeaders(); - assertFalse(it.hasNext()); - - response.setHttpHeader("key1", "value1"); - it = response.httpHeaders(); - assertTrue(it.hasNext()); - Entry entry = it.next(); - assertEquals("key1", entry.getKey()); - assertEquals("value1", entry.getValue()); - assertFalse(it.hasNext()); - - response.setHttpHeader("key1", "value2"); - it = response.httpHeaders(); - assertTrue(it.hasNext()); - entry = it.next(); - assertEquals("key1", entry.getKey()); - assertEquals("value2", entry.getValue()); - assertFalse(it.hasNext()); - - response.addHttpHeader("key1", "value3"); - response.setHttpHeader("key1", "value4"); - it = response.httpHeaders(); - assertTrue(it.hasNext()); - entry = it.next(); - assertEquals("key1", entry.getKey()); - assertEquals("value4", entry.getValue()); - assertFalse(it.hasNext()); - - response.setHttpHeader("key2", "value5"); - it = response.httpHeaders(); - assertTrue(it.hasNext()); - entry = it.next(); - assertEquals("key1", entry.getKey()); - assertEquals("value4", entry.getValue()); - assertTrue(it.hasNext()); - entry = it.next(); - assertEquals("key2", entry.getKey()); - assertEquals("value5", entry.getValue()); - assertFalse(it.hasNext()); - } - - @Test - public void testRemoveHttpHeader() { - SolrQueryResponse response = new SolrQueryResponse(); - Iterator> it = response.httpHeaders(); - assertFalse(it.hasNext()); - response.addHttpHeader("key1", "value1"); - assertTrue(response.httpHeaders().hasNext()); - assertEquals("value1", response.removeHttpHeader("key1")); - assertFalse(response.httpHeaders().hasNext()); - - response.addHttpHeader("key1", "value2"); - response.addHttpHeader("key1", "value3"); - response.addHttpHeader("key2", "value4"); - assertTrue(response.httpHeaders().hasNext()); - assertEquals("value2", response.removeHttpHeader("key1")); - assertEquals("value3", response.httpHeaders().next().getValue()); - assertEquals("value3", response.removeHttpHeader("key1")); - assertNull(response.removeHttpHeader("key1")); - assertEquals("key2", response.httpHeaders().next().getKey()); - - } - - @Test - public void testRemoveHttpHeaders() { - SolrQueryResponse response = new SolrQueryResponse(); - Iterator> it = response.httpHeaders(); - assertFalse(it.hasNext()); - response.addHttpHeader("key1", "value1"); - assertTrue(response.httpHeaders().hasNext()); - assertEquals(Arrays.asList("value1"), response.removeHttpHeaders("key1")); - assertFalse(response.httpHeaders().hasNext()); - - response.addHttpHeader("key1", "value2"); - response.addHttpHeader("key1", "value3"); - response.addHttpHeader("key2", "value4"); - assertTrue(response.httpHeaders().hasNext()); - assertEquals(Arrays.asList(new String[]{"value2", "value3"}), response.removeHttpHeaders("key1")); - assertNull(response.removeHttpHeaders("key1")); - assertEquals("key2", response.httpHeaders().next().getKey()); - } - public static class ComponentThatAddsHeader extends SearchComponent { @Override