Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit 225f52f

Browse files
franciscospaethchristophstrobl
authored andcommitted
DATASOLR-83 - Add support for Realtime GET.
Introduced some tests for SolrRealtimeGetRequest.
1 parent f1bb4b8 commit 225f52f

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

src/main/java/org/springframework/data/solr/SolrRealtimeGetRequest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public SolrRealtimeGetRequest(Serializable... ids) {
4848
public SolrRealtimeGetRequest(Collection<? extends Serializable> ids) {
4949
super(METHOD.GET, "/get");
5050

51-
Assert.notEmpty(ids, "At least one 'id' id required for real time get request.");
51+
Assert.notEmpty(ids, "At least one 'id' is required for real time get request.");
52+
Assert.noNullElements(ids.toArray(), "Real time get request can't be made for 'null' id.");
53+
5254
toStringIds(ids);
5355
}
5456

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.solr;
17+
18+
import static org.mockito.Mockito.*;
19+
20+
import java.io.IOException;
21+
22+
import org.apache.solr.client.solrj.SolrServer;
23+
import org.apache.solr.client.solrj.SolrServerException;
24+
import org.apache.solr.client.solrj.response.QueryResponse;
25+
import org.apache.solr.common.util.NamedList;
26+
import org.junit.Assert;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
import org.mockito.Mock;
30+
import org.mockito.runners.MockitoJUnitRunner;
31+
32+
/**
33+
* @author Francisco Spaeth
34+
*/
35+
@RunWith(MockitoJUnitRunner.class)
36+
public class SolrRealtimeGetRequestUnitTests {
37+
38+
private @Mock SolrServer solrServerMock;
39+
40+
@Test(expected = IllegalArgumentException.class)
41+
public void shouldThrowExeptionWhenNoIdsGiven() {
42+
new SolrRealtimeGetRequest();
43+
}
44+
45+
@Test(expected = IllegalArgumentException.class)
46+
public void shouldThrowExeptionWhenIdsContainsNullValue() {
47+
new SolrRealtimeGetRequest(1, 2, null);
48+
}
49+
50+
/**
51+
* @see DATASOLR-83
52+
*/
53+
@Test
54+
public void testCreationOfRealtimeGet() throws SolrServerException, IOException {
55+
56+
// given
57+
NamedList<Object> value = new NamedList<Object>();
58+
SolrRealtimeGetRequest request = new SolrRealtimeGetRequest(1L, 2F, 3, "4");
59+
when(solrServerMock.request(request)).thenReturn(value);
60+
61+
// when
62+
QueryResponse result = request.process(solrServerMock);
63+
64+
// then
65+
Assert.assertEquals(value, result.getResponse());
66+
Assert.assertArrayEquals(new String[] { "1", "2.0", "3", "4" }, request.getParams().getParams("ids"));
67+
verify(solrServerMock).request(request);
68+
}
69+
70+
}

0 commit comments

Comments
 (0)