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