Revision 45126
Added by Claudio Atzori over 7 years ago
ISStoreServiceTest.java | ||
---|---|---|
12 | 12 |
|
13 | 13 |
import java.util.ArrayList; |
14 | 14 |
import java.util.Arrays; |
15 |
import java.util.Iterator; |
|
15 | 16 |
import java.util.List; |
16 | 17 |
|
17 | 18 |
import javax.xml.namespace.QName; |
18 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
19 | 19 |
|
20 | 20 |
import org.apache.cxf.endpoint.Endpoint; |
21 | 21 |
import org.apache.cxf.endpoint.ServerImpl; |
... | ... | |
28 | 28 |
import org.junit.runner.RunWith; |
29 | 29 |
import org.mockito.Mock; |
30 | 30 |
import org.mockito.invocation.InvocationOnMock; |
31 |
import org.mockito.runners.MockitoJUnit44Runner;
|
|
31 |
import org.mockito.junit.MockitoJUnitRunner;
|
|
32 | 32 |
import org.mockito.stubbing.Answer; |
33 | 33 |
import org.xmldb.api.base.XMLDBException; |
34 | 34 |
|
... | ... | |
41 | 41 |
import eu.dnetlib.enabling.resultset.ResultSetServiceImpl; |
42 | 42 |
import eu.dnetlib.soap.cxf.JaxwsEndpointReferenceBuilder; |
43 | 43 |
import eu.dnetlib.soap.cxf.StandaloneCxfEndpointReferenceBuilder; |
44 |
import eu.dnetlib.xml.database.XMLDBResultSet; |
|
45 | 44 |
import eu.dnetlib.xml.database.XMLDatabase; |
46 | 45 |
|
47 | 46 |
/** |
... | ... | |
50 | 49 |
* @author marko |
51 | 50 |
* |
52 | 51 |
*/ |
53 |
@RunWith(MockitoJUnit44Runner.class)
|
|
52 |
@RunWith(MockitoJUnitRunner.class) |
|
54 | 53 |
public class ISStoreServiceTest { // NOPMD by marko on 11/24/08 4:54 PM |
55 | 54 |
|
56 | 55 |
/** |
... | ... | |
340 | 339 |
* the declaration of this exception is just a syntactic necessity |
341 | 340 |
*/ |
342 | 341 |
private void prepareXMLDBResultSet() throws XMLDBException { |
343 |
final XMLDBResultSet rset = mock(XMLDBResultSet.class); |
|
344 |
when(xdb.xquery(SOME_QUERY)).thenReturn(rset); |
|
345 |
when(rset.getSize()).thenReturn(2L); |
|
346 |
when(rset.get(0)).thenReturn(ONE); |
|
347 |
when(rset.get(1)).thenReturn(TWO); |
|
342 |
List<String> myList = Arrays.asList(ONE,TWO); |
|
343 |
when(xdb.xquery(SOME_QUERY)).thenReturn(myList.iterator()); |
|
348 | 344 |
} |
349 | 345 |
|
350 | 346 |
/** |
... | ... | |
384 | 380 |
assertEquals("second value", TWO, res.get(1)); |
385 | 381 |
} |
386 | 382 |
|
387 |
/** |
|
388 |
* test search xml method. |
|
389 |
* |
|
390 |
* @throws ISStoreException |
|
391 |
* shouldn't happen |
|
392 |
* @throws XMLDBException |
|
393 |
* shouldn't happen |
|
394 |
*/ |
|
395 |
@Test |
|
396 |
public void testSearchXML() throws ISStoreException, XMLDBException { |
|
397 |
setUpResultSet(); |
|
398 |
prepareXMLDBResultSet(); |
|
399 |
|
|
400 |
final W3CEndpointReference epr = store.searchXML(SOME_QUERY); |
|
401 |
assertNotNull("should return epr", epr); |
|
402 |
|
|
403 |
assertNotNull("local resultset", resultSetImpl); |
|
404 |
|
|
405 |
assertEquals("local resultset size", 2, resultSetImpl.getNumberOfResults()); |
|
406 |
assertEquals("local resultset id", SOME_RS_ID, resultSetImpl.getIdentifier()); |
|
407 |
|
|
408 |
assertEquals("first value", ONE, resultSetImpl.getResults(1, 1).get(0)); |
|
409 |
assertEquals("second value", TWO, resultSetImpl.getResults(2, 2).get(0)); |
|
410 |
|
|
411 |
System.out.println(epr.toString()); |
|
412 |
assertTrue( |
|
413 |
"rs epr", |
|
414 |
epr.toString() |
|
415 |
.contains( |
|
416 |
"<EndpointReference xmlns=\"http://www.w3.org/2005/08/addressing\"><Address>http://localhost/something</Address><ReferenceParameters>" |
|
417 |
+ "<ResourceIdentifier:ResourceIdentifier xmlns=\"http://www.driver.org\" " |
|
418 |
+ "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" " |
|
419 |
+ "xmlns:ResourceIdentifier=\"http://www.driver.org\">someRsId</ResourceIdentifier:ResourceIdentifier></ReferenceParameters>" |
|
420 |
+ "<Metadata><wsam:ServiceName EndpointName=\"TestServiceEndpoint\" xmlns:ns2=\"http://my.test\" " |
|
421 |
+ "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" xmlns:wsaw=\"http://www.w3.org/2006/05/addressing/wsdl\" xmlns:wsam=\"http://www.w3.org/2007/05/addressing/metadata\"" |
|
422 |
+ ">ns2:TestService</wsam:ServiceName></Metadata>" + "</EndpointReference>")); |
|
423 |
} |
|
424 |
|
|
425 | 383 |
} |
Also available in: Unified diff
migrated to dnet45, using updated mockito version in tests