1
|
package eu.dnetlib.enabling.is.store; // NOPMD
|
2
|
|
3
|
import static org.junit.Assert.assertFalse;
|
4
|
import static org.junit.Assert.assertNotNull;
|
5
|
import static org.junit.Assert.assertTrue;
|
6
|
import static org.mockito.Matchers.anyString;
|
7
|
import static org.mockito.Mockito.mock;
|
8
|
import static org.mockito.Mockito.when;
|
9
|
|
10
|
import java.util.Iterator;
|
11
|
import java.util.List;
|
12
|
|
13
|
import org.junit.Before;
|
14
|
import org.junit.Test;
|
15
|
import org.junit.runner.RunWith;
|
16
|
import org.mockito.Mock;
|
17
|
import org.mockito.junit.MockitoJUnitRunner;
|
18
|
import org.xmldb.api.base.XMLDBException;
|
19
|
|
20
|
import eu.dnetlib.enabling.is.store.rmi.ISStoreException;
|
21
|
import eu.dnetlib.xml.database.XMLDatabase;
|
22
|
|
23
|
/**
|
24
|
* test the ISStore service.
|
25
|
*
|
26
|
* @author marko
|
27
|
*
|
28
|
*/
|
29
|
@RunWith(MockitoJUnitRunner.class)
|
30
|
public class ISStoreServiceImplTest {
|
31
|
|
32
|
/**
|
33
|
* instance under test.
|
34
|
*/
|
35
|
private transient ISStoreServiceImpl storeService;
|
36
|
|
37
|
/**
|
38
|
* xml database mock.
|
39
|
*/
|
40
|
@Mock
|
41
|
private transient XMLDatabase xmlDatabase;
|
42
|
|
43
|
/**
|
44
|
* setup class under test.
|
45
|
*/
|
46
|
@Before
|
47
|
public void setUp() {
|
48
|
storeService = new ISStoreServiceImpl();
|
49
|
storeService.setXmlDatabase(xmlDatabase);
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* test that quick search profile returns null instead of an empty list.
|
54
|
*
|
55
|
* @throws XMLDBException shouldn't happen
|
56
|
* @throws ISStoreException shouldn't happen
|
57
|
*/
|
58
|
@Test
|
59
|
public void testQuickSearchXML() throws XMLDBException, ISStoreException {
|
60
|
final Iterator<String> rset = mock(Iterator.class);
|
61
|
when(rset.hasNext()).thenReturn(true, false);
|
62
|
when(xmlDatabase.xquery(anyString())).thenReturn(rset);
|
63
|
|
64
|
final List<String> res = storeService.quickSearchXML("someQuery");
|
65
|
|
66
|
assertNotNull("empty result not null", res);
|
67
|
assertFalse("empty result is empty", res.isEmpty());
|
68
|
}
|
69
|
|
70
|
}
|