use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class TestSolrQueryResponse method testSetHttpHeader.
@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());
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class TestSolrQueryResponse method testValues.
@Test
public void testValues() throws Exception {
final SolrQueryResponse response = new SolrQueryResponse();
assertEquals("values initially not empty", 0, response.getValues().size());
// initially empty, then add something
final NamedList<Object> newValue = new SimpleOrderedMap<>();
newValue.add("key1", "value1");
response.setAllValues(newValue);
assertEquals("values new value", newValue, response.getValues());
response.add("key2", "value2");
{
final Iterator<Map.Entry<String, Object>> it = response.getValues().iterator();
assertTrue(it.hasNext());
final Map.Entry<String, Object> entry1 = it.next();
assertEquals("key1", entry1.getKey());
assertEquals("value1", entry1.getValue());
assertTrue(it.hasNext());
final Map.Entry<String, Object> entry2 = it.next();
assertEquals("key2", entry2.getKey());
assertEquals("value2", entry2.getValue());
assertFalse(it.hasNext());
}
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class TestSolrQueryResponse method testRemoveHttpHeaders.
@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());
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class TestSolrQueryResponse method testRemoveHttpHeader.
@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());
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class TestSolrQueryResponse method testToLog.
@Test
public void testToLog() throws Exception {
final SolrQueryResponse response = new SolrQueryResponse();
assertEquals("toLog initially not empty", 0, response.getToLog().size());
assertEquals("logid_only", response.getToLogAsString("logid_only"));
// initially empty, then add something
response.addToLog("key1", "value1");
{
final Iterator<Map.Entry<String, Object>> it = response.getToLog().iterator();
assertTrue(it.hasNext());
final Map.Entry<String, Object> entry1 = it.next();
assertEquals("key1", entry1.getKey());
assertEquals("value1", entry1.getValue());
assertFalse(it.hasNext());
}
assertEquals("key1=value1", response.getToLogAsString(""));
assertEquals("abc123 key1=value1", response.getToLogAsString("abc123"));
// and then add something else
response.addToLog("key2", "value2");
{
final Iterator<Map.Entry<String, Object>> it = response.getToLog().iterator();
assertTrue(it.hasNext());
final Map.Entry<String, Object> entry1 = it.next();
assertEquals("key1", entry1.getKey());
assertEquals("value1", entry1.getValue());
assertTrue(it.hasNext());
final Map.Entry<String, Object> entry2 = it.next();
assertEquals("key2", entry2.getKey());
assertEquals("value2", entry2.getValue());
assertFalse(it.hasNext());
}
assertEquals("key1=value1 key2=value2", response.getToLogAsString(""));
assertEquals("xyz789 key1=value1 key2=value2", response.getToLogAsString("xyz789"));
}
Aggregations