SOLR-8388: factor out response/TestSolrQueryResponse.java from servlet/ResponseHeaderTest.java

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1719116 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christine Poerschke 2015-12-10 17:21:53 +00:00
parent 99550b5c8a
commit a86b9bb80e
3 changed files with 162 additions and 128 deletions

View File

@ -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

View File

@ -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<Entry<String, String>> it = response.httpHeaders();
assertFalse(it.hasNext());
response.addHttpHeader("key1", "value1");
it = response.httpHeaders();
assertTrue(it.hasNext());
Entry<String, String> 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<Entry<String, String>> it = response.httpHeaders();
assertFalse(it.hasNext());
response.setHttpHeader("key1", "value1");
it = response.httpHeaders();
assertTrue(it.hasNext());
Entry<String, String> 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<Entry<String, String>> 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<Entry<String, String>> 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());
}
}

View File

@ -78,134 +78,6 @@ public class ResponseHeaderTest extends SolrJettyTestBase {
assertTrue("Expected header not found", containsWarningHeader);
}
@Test
public void testAddHttpHeader() {
SolrQueryResponse response = new SolrQueryResponse();
Iterator<Entry<String, String>> it = response.httpHeaders();
assertFalse(it.hasNext());
response.addHttpHeader("key1", "value1");
it = response.httpHeaders();
assertTrue(it.hasNext());
Entry<String, String> 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<Entry<String, String>> it = response.httpHeaders();
assertFalse(it.hasNext());
response.setHttpHeader("key1", "value1");
it = response.httpHeaders();
assertTrue(it.hasNext());
Entry<String, String> 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<Entry<String, String>> 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<Entry<String, String>> 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