Revision 50659
Added by Claudio Atzori almost 7 years ago
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-enabling-services/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "cnr-enabling-services"} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/tools/JaxwsServiceResolverImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.junit.Assert.assertNotNull; |
|
5 |
import static org.mockito.Mockito.mock; // NOPMD |
|
6 |
import static org.mockito.Mockito.when; |
|
7 |
|
|
8 |
import javax.xml.transform.stream.StreamResult; |
|
9 |
import javax.xml.ws.Endpoint; |
|
10 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
11 |
|
|
12 |
import org.apache.commons.logging.Log; |
|
13 |
import org.apache.commons.logging.LogFactory; |
|
14 |
import org.apache.cxf.BusFactory; |
|
15 |
import org.junit.Before; |
|
16 |
import org.junit.BeforeClass; |
|
17 |
import org.junit.Test; |
|
18 |
import org.junit.runner.RunWith; |
|
19 |
import org.springframework.test.context.ContextConfiguration; |
|
20 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
21 |
|
|
22 |
import eu.dnetlib.enabling.resultset.rmi.ResultSetException; |
|
23 |
import eu.dnetlib.enabling.resultset.rmi.ResultSetService; |
|
24 |
import eu.dnetlib.soap.cxf.CxfEndpointReferenceBuilder; |
|
25 |
import eu.dnetlib.soap.cxf.JaxwsEndpointReferenceBuilder; |
|
26 |
|
|
27 |
/** |
|
28 |
* jaxws service resolution. |
|
29 |
* |
|
30 |
* @author marko |
|
31 |
* |
|
32 |
*/ |
|
33 |
|
|
34 |
@RunWith(SpringJUnit4ClassRunner.class) |
|
35 |
@ContextConfiguration(locations = "local-cxf.xml") |
|
36 |
public class JaxwsServiceResolverImplTest { |
|
37 |
|
|
38 |
/** |
|
39 |
* logger. |
|
40 |
*/ |
|
41 |
private static final Log log = LogFactory.getLog(JaxwsServiceResolverImplTest.class); // NOPMD by marko on |
|
42 |
// 11/24/08 5:02 PM |
|
43 |
|
|
44 |
/** |
|
45 |
* instance under test. |
|
46 |
*/ |
|
47 |
private transient JaxwsServiceResolverImpl resolver; |
|
48 |
|
|
49 |
/** |
|
50 |
* epr builder. |
|
51 |
*/ |
|
52 |
private transient JaxwsEndpointReferenceBuilder eprBuilder; |
|
53 |
|
|
54 |
/** |
|
55 |
* resultset mock. |
|
56 |
*/ |
|
57 |
private transient ResultSetService resultSetService; |
|
58 |
|
|
59 |
/** |
|
60 |
* cleanup cxf. This test requires the local transport (declared in local-cxf.xml), but other tests may have already instantiated the |
|
61 |
* cxf bus singleton. |
|
62 |
*/ |
|
63 |
@BeforeClass |
|
64 |
public static void resetCxf() { |
|
65 |
BusFactory.getDefaultBus().shutdown(true); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* common. |
|
70 |
*/ |
|
71 |
@Before |
|
72 |
public void setUp() { |
|
73 |
resolver = new JaxwsServiceResolverImpl(); |
|
74 |
eprBuilder = new JaxwsEndpointReferenceBuilder(); |
|
75 |
eprBuilder.setBuilder(new CxfEndpointReferenceBuilder()); |
|
76 |
|
|
77 |
resultSetService = mock(ResultSetService.class); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* get service. |
|
82 |
* |
|
83 |
* @throws ResultSetException |
|
84 |
* shoudn't happen |
|
85 |
*/ |
|
86 |
@Test |
|
87 |
public void testGetService() throws ResultSetException { |
|
88 |
final String rsId = "1235"; |
|
89 |
|
|
90 |
when(resultSetService.identify()).thenReturn("foo"); |
|
91 |
when(resultSetService.getNumberOfElements(rsId)).thenReturn(2); |
|
92 |
|
|
93 |
final Endpoint endpoint = Endpoint.publish("local://test", resultSetService); |
|
94 |
|
|
95 |
assertNotNull("check endpoint", endpoint); |
|
96 |
|
|
97 |
final W3CEndpointReference epr = eprBuilder.getEndpointReference(endpoint, rsId); |
|
98 |
|
|
99 |
epr.writeTo(new StreamResult(System.out)); |
|
100 |
|
|
101 |
final ResultSetService rset = resolver.getService(ResultSetService.class, epr); |
|
102 |
|
|
103 |
assertNotNull("check resultset", rset); |
|
104 |
|
|
105 |
log.info(rset.getClass()); |
|
106 |
log.info(rset); |
|
107 |
|
|
108 |
// NOTE: call to identify and getNumberOfElements fail because it seems that the methods are not |
|
109 |
// in the wsdl. This error may be related with the use of mockito and |
|
110 |
// method inheritance of services because there is no such error with |
|
111 |
// non-mocked result set service methods. |
|
112 |
// rset.identify(); |
|
113 |
|
|
114 |
// assertEquals("check resultset communication", "foo", |
|
115 |
// rset.identify()); |
|
116 |
|
|
117 |
assertEquals("check resolver resource id", rsId, resolver.getResourceIdentifier(epr)); |
|
118 |
|
|
119 |
// assertEquals("check resultset communication with param", 2, |
|
120 |
// rset.getNumberOfElements(resolver.getResourceIdentifier(epr))); |
|
121 |
} |
|
122 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/tools/CompatResourceIdentifierResolverImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools; |
|
2 |
|
|
3 |
import static org.junit.Assert.*; // NOPMD |
|
4 |
|
|
5 |
import org.junit.Before; |
|
6 |
import org.junit.Test; |
|
7 |
|
|
8 |
/** |
|
9 |
* test the CompatResourceIdentifierResolverImpl. |
|
10 |
* |
|
11 |
* @author marko |
|
12 |
* |
|
13 |
*/ |
|
14 |
public class CompatResourceIdentifierResolverImplTest { |
|
15 |
|
|
16 |
/** |
|
17 |
* test resource identifier. |
|
18 |
* |
|
19 |
*/ |
|
20 |
private static final String TEST_RES_ID = "first_c2Vjb25k"; |
|
21 |
|
|
22 |
/** |
|
23 |
* instance under test. |
|
24 |
*/ |
|
25 |
private transient CompatResourceIdentifierResolverImpl resIdResolver; |
|
26 |
|
|
27 |
/** |
|
28 |
* prepare the instance under test. |
|
29 |
*/ |
|
30 |
@Before |
|
31 |
public void setUp() { |
|
32 |
resIdResolver = new CompatResourceIdentifierResolverImpl(); |
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* test get collection name. |
|
37 |
*/ |
|
38 |
@Test |
|
39 |
public void testGetCollectionName() { |
|
40 |
assertEquals("check collection name", "second", resIdResolver.getCollectionName(TEST_RES_ID)); |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* test get file name. |
|
45 |
*/ |
|
46 |
@Test |
|
47 |
public void testGetFileName() { |
|
48 |
assertEquals("check file name", "first", resIdResolver.getFileName(TEST_RES_ID)); |
|
49 |
} |
|
50 |
|
|
51 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/tools/DOMOpaqueResourceTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools; |
|
2 |
|
|
3 |
import static org.junit.Assert.*; // NOPMD |
|
4 |
import static org.mockito.Mockito.*; // NOPMD |
|
5 |
|
|
6 |
import java.io.IOException; |
|
7 |
import java.io.StringReader; |
|
8 |
import java.io.StringWriter; |
|
9 |
|
|
10 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
11 |
import javax.xml.parsers.ParserConfigurationException; |
|
12 |
import javax.xml.xpath.XPathExpressionException; |
|
13 |
|
|
14 |
import org.apache.commons.io.IOUtils; |
|
15 |
import org.junit.Before; |
|
16 |
import org.junit.Test; |
|
17 |
import org.w3c.dom.Document; |
|
18 |
import org.xml.sax.InputSource; |
|
19 |
import org.xml.sax.SAXException; |
|
20 |
|
|
21 |
import javax.xml.transform.Result; |
|
22 |
import javax.xml.transform.Source; |
|
23 |
import javax.xml.transform.Transformer; |
|
24 |
import javax.xml.transform.TransformerException; |
|
25 |
|
|
26 |
/** |
|
27 |
* Test DOM opaque resource. |
|
28 |
* |
|
29 |
* @author marko |
|
30 |
* |
|
31 |
*/ |
|
32 |
public class DOMOpaqueResourceTest { |
|
33 |
|
|
34 |
/** |
|
35 |
* instance under test. |
|
36 |
*/ |
|
37 |
private transient DOMOpaqueResource resource; |
|
38 |
|
|
39 |
/** |
|
40 |
* xml source, read from test-profile.xml. |
|
41 |
*/ |
|
42 |
private transient String xmlSource; |
|
43 |
|
|
44 |
/** |
|
45 |
* common preparation. |
|
46 |
* |
|
47 |
* @throws ParserConfigurationException |
|
48 |
* shouldn't happen |
|
49 |
* @throws IOException |
|
50 |
* shouldn't happen |
|
51 |
* @throws SAXException |
|
52 |
* shouldn't happen |
|
53 |
* @throws XPathExpressionException |
|
54 |
* shouldn't happen |
|
55 |
*/ |
|
56 |
@Before |
|
57 |
public void setUp() throws SAXException, IOException, ParserConfigurationException, XPathExpressionException { |
|
58 |
final StringWriter writer = new StringWriter(); |
|
59 |
IOUtils.copy(getClass().getResourceAsStream("test-profile.xml"), writer); |
|
60 |
xmlSource = writer.getBuffer().toString(); |
|
61 |
final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xmlSource))); |
|
62 |
resource = new DOMOpaqueResource(document); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* test dom. |
|
67 |
*/ |
|
68 |
@Test |
|
69 |
public void testAsDom() { |
|
70 |
assertEquals("check that dom is not recreated", resource.getDom(), resource.asDom()); |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* serialization check. |
|
75 |
* |
|
76 |
* TODO: use xmlunit |
|
77 |
*/ |
|
78 |
@Test |
|
79 |
public void testAsString() { |
|
80 |
assertEquals("check xml serialization", xmlSource, resource.asString()); |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* test with exception in transformer. |
|
85 |
* @throws TransformerException expected |
|
86 |
*/ |
|
87 |
@Test |
|
88 |
public void testAsStringException() throws TransformerException { |
|
89 |
final Transformer transformer = mock(Transformer.class); |
|
90 |
doThrow(new TransformerException("dummy")).when(transformer).transform((Source) anyObject(), (Result) anyObject()); |
|
91 |
|
|
92 |
resource.setTransformer(transformer); |
|
93 |
assertNull("checks that upon exception we get a null string", resource.asString()); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* check resource id extraction. |
|
98 |
*/ |
|
99 |
@Test |
|
100 |
public void testGetResourceId() { |
|
101 |
assertEquals("check resource id", |
|
102 |
"111-6b4ea417-d940-4dda-a194-3096f685789b_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=", resource |
|
103 |
.getResourceId()); |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* check resource type extraction. |
|
108 |
*/ |
|
109 |
@Test |
|
110 |
public void testGetResourceType() { |
|
111 |
assertEquals("check resource type", "RepositoryServiceResourceType", resource.getResourceType()); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* check resource kind extraction. |
|
116 |
*/ |
|
117 |
@Test |
|
118 |
public void testGetResourceKind() { |
|
119 |
assertEquals("check resource kind", "RepositoryServiceResources", resource.getResourceKind()); |
|
120 |
} |
|
121 |
|
|
122 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/tools/blackboard/BlackboardMessageImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools.blackboard; |
|
2 |
|
|
3 |
|
|
4 |
import static org.junit.Assert.assertEquals; |
|
5 |
|
|
6 |
import javax.xml.bind.JAXBException; |
|
7 |
|
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.junit.Test; |
|
11 |
|
|
12 |
import eu.dnetlib.miscutils.jaxb.JaxbFactory; |
|
13 |
|
|
14 |
/** |
|
15 |
* Jaxb Blackboard message implementation test. |
|
16 |
* |
|
17 |
* @author marko |
|
18 |
* |
|
19 |
*/ |
|
20 |
public class BlackboardMessageImplTest { |
|
21 |
|
|
22 |
/** |
|
23 |
* logger. |
|
24 |
*/ |
|
25 |
private static final Log log = LogFactory.getLog(BlackboardMessageImplTest.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
26 |
|
|
27 |
/** |
|
28 |
* test message (de)serialization. |
|
29 |
* |
|
30 |
* @throws JAXBException could happen |
|
31 |
*/ |
|
32 |
@Test |
|
33 |
public void testMessage() throws JAXBException { |
|
34 |
final JaxbFactory<BlackboardMessage> factory = new JaxbFactory<BlackboardMessage>(BlackboardMessageImpl.class); |
|
35 |
|
|
36 |
final BlackboardMessage message = factory.newInstance(); |
|
37 |
message.setAction("FEED"); |
|
38 |
message.setActionStatus(ActionStatus.ONGOING); |
|
39 |
message.setId("12"); |
|
40 |
message.setDate("5123"); |
|
41 |
|
|
42 |
final BlackboardParameter param1 = new BlackboardParameterImpl(); |
|
43 |
param1.setName("someName"); |
|
44 |
param1.setValue("someValue"); |
|
45 |
message.getParameters().add(param1); |
|
46 |
|
|
47 |
final BlackboardParameter param2 = new BlackboardParameterImpl(); |
|
48 |
param2.setName("otherName"); |
|
49 |
param2.setValue("otherValue"); |
|
50 |
message.getParameters().add(param2); |
|
51 |
|
|
52 |
final String serialized = factory.serialize(message); |
|
53 |
log.info(serialized); |
|
54 |
|
|
55 |
final BlackboardMessage res = factory.parse(serialized); |
|
56 |
log.info(res.getParameters()); |
|
57 |
|
|
58 |
assertEquals("list serialization", 2, res.getParameters().size()); |
|
59 |
assertEquals("enum serialization", ActionStatus.ONGOING, res.getActionStatus()); |
|
60 |
} |
|
61 |
|
|
62 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/tools/registration/ServiceRegistratorTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools.registration; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.mockito.Mockito.when; |
|
5 |
import static org.mockito.Matchers.anyString; |
|
6 |
import static org.mockito.Matchers.eq; |
|
7 |
|
|
8 |
import javax.xml.namespace.QName; |
|
9 |
|
|
10 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException; |
|
11 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
12 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
13 |
import org.apache.cxf.endpoint.Endpoint; |
|
14 |
import org.apache.cxf.endpoint.ServerImpl; |
|
15 |
import org.apache.cxf.jaxws.EndpointImpl; |
|
16 |
import org.apache.cxf.service.Service; |
|
17 |
import org.apache.cxf.service.model.EndpointInfo; |
|
18 |
|
|
19 |
import org.junit.Before; |
|
20 |
import org.junit.Test; |
|
21 |
import org.junit.Ignore; |
|
22 |
import org.junit.runner.RunWith; |
|
23 |
import org.mockito.Mock; |
|
24 |
import org.mockito.junit.MockitoJUnitRunner; |
|
25 |
|
|
26 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
27 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
28 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
29 |
import eu.dnetlib.enabling.tools.HNMLocator; |
|
30 |
import eu.dnetlib.soap.cxf.CxfEndpointReferenceBuilder; |
|
31 |
import eu.dnetlib.soap.cxf.JaxwsEndpointReferenceBuilder; |
|
32 |
|
|
33 |
/** |
|
34 |
* ServiceRegistrator test. |
|
35 |
* |
|
36 |
* @author marko |
|
37 |
* |
|
38 |
*/ |
|
39 |
@RunWith(MockitoJUnitRunner.class) |
|
40 |
public class ServiceRegistratorTest { |
|
41 |
/** |
|
42 |
* instance under test. |
|
43 |
*/ |
|
44 |
private transient ServiceRegistrator registrator; |
|
45 |
|
|
46 |
/** |
|
47 |
* service mock. |
|
48 |
*/ |
|
49 |
@Mock |
|
50 |
private transient Service service; |
|
51 |
|
|
52 |
/** |
|
53 |
* endpoint info mock. |
|
54 |
*/ |
|
55 |
@Mock |
|
56 |
private transient EndpointInfo endpointInfo; |
|
57 |
|
|
58 |
/** |
|
59 |
* endpoint mock. |
|
60 |
*/ |
|
61 |
@Mock |
|
62 |
private transient Endpoint endpoint; |
|
63 |
|
|
64 |
/** |
|
65 |
* registry service mock. |
|
66 |
*/ |
|
67 |
@Mock |
|
68 |
private transient ISRegistryService registryService; |
|
69 |
|
|
70 |
/** |
|
71 |
* isLookup service mock. |
|
72 |
*/ |
|
73 |
@Mock |
|
74 |
private transient ISLookUpService isLookUpService; |
|
75 |
|
|
76 |
/** |
|
77 |
* jaxws endpoint mock. |
|
78 |
*/ |
|
79 |
@Mock |
|
80 |
private transient EndpointImpl jaxwsEndpoint; |
|
81 |
|
|
82 |
/** |
|
83 |
* cxf server mock. |
|
84 |
*/ |
|
85 |
@Mock |
|
86 |
private transient ServerImpl server; |
|
87 |
|
|
88 |
/** |
|
89 |
* hnm locator mock. |
|
90 |
*/ |
|
91 |
@Mock |
|
92 |
private transient HNMLocator hnmLocator; |
|
93 |
@Mock |
|
94 |
private UniqueServiceLocator serviceLocator; |
|
95 |
|
|
96 |
/** |
|
97 |
* setup common stuff. |
|
98 |
* |
|
99 |
*/ |
|
100 |
@Before |
|
101 |
public void disabled() throws ISLookUpException { |
|
102 |
final String service = "TestService"; |
|
103 |
when(this.service.getName()).thenReturn(new QName("http://my.test", service)); |
|
104 |
|
|
105 |
when(endpoint.getEndpointInfo()).thenReturn(endpointInfo); |
|
106 |
when(endpoint.getService()).thenReturn(this.service); |
|
107 |
when(endpointInfo.getAddress()).thenReturn("http://localhost/something"); |
|
108 |
when(endpointInfo.getName()).thenReturn(new QName("http://my.test", "TestServiceEndpoint")); |
|
109 |
|
|
110 |
when(jaxwsEndpoint.getServer()).thenReturn(server); |
|
111 |
when(server.getEndpoint()).thenReturn(endpoint); |
|
112 |
|
|
113 |
when(hnmLocator.getHNMForUrl("http://localhost/something")).thenReturn("555444"); |
|
114 |
|
|
115 |
// serviceLocator.getService(ISLookUpService.class).getResourceTypeSchema(serviceName); |
|
116 |
|
|
117 |
when(isLookUpService.getResourceTypeSchema(service)).thenThrow(ISLookUpDocumentNotFoundException.class); |
|
118 |
|
|
119 |
when(serviceLocator.getService(ISLookUpService.class)).thenReturn(isLookUpService); |
|
120 |
when(serviceLocator.getService(ISRegistryService.class, true)).thenReturn(registryService); |
|
121 |
|
|
122 |
|
|
123 |
registrator = new ServiceRegistrator(); |
|
124 |
registrator.setServiceLocator(serviceLocator); |
|
125 |
|
|
126 |
final CxfEndpointReferenceBuilder cxfEprBuilder = new CxfEndpointReferenceBuilder(); |
|
127 |
|
|
128 |
final JaxwsEndpointReferenceBuilder eprBuilder = new JaxwsEndpointReferenceBuilder(); |
|
129 |
eprBuilder.setBuilder(cxfEprBuilder); |
|
130 |
|
|
131 |
registrator.setEprBuilder(eprBuilder); |
|
132 |
registrator.setHnmLocator(hnmLocator); |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* test register service. |
|
137 |
* @throws ISRegistryException shouldn't happen |
|
138 |
*/ |
|
139 |
@Test |
|
140 |
//@Ignore |
|
141 |
public void testRegisterService() throws ISRegistryException { |
|
142 |
when(registryService.insertProfileForValidation(eq("TestServiceResourceType"), anyString())).thenReturn("123"); |
|
143 |
|
|
144 |
final String rsId = registrator.registerService("TestService", jaxwsEndpoint); |
|
145 |
assertEquals("registered", "123", rsId); |
|
146 |
} |
|
147 |
|
|
148 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/tools/registration/ServiceRegistrationManagerImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools.registration; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.mockito.Matchers.anyObject; |
|
5 |
import static org.mockito.Matchers.anyString; |
|
6 |
import static org.mockito.Mockito.when; |
|
7 |
|
|
8 |
import javax.xml.ws.Endpoint; |
|
9 |
|
|
10 |
import org.junit.Before; |
|
11 |
import org.junit.Ignore; |
|
12 |
import org.junit.Test; |
|
13 |
import org.junit.runner.RunWith; |
|
14 |
import org.mockito.Mock; |
|
15 |
import org.mockito.junit.MockitoJUnitRunner; |
|
16 |
|
|
17 |
import eu.dnetlib.enabling.is.lookup.ISLookUpServiceImpl; |
|
18 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
19 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
20 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
21 |
|
|
22 |
/** |
|
23 |
* test ServiceRegistrationManagerImpl. |
|
24 |
* |
|
25 |
* @author marko |
|
26 |
* |
|
27 |
*/ |
|
28 |
@RunWith(MockitoJUnitRunner.class) |
|
29 |
public class ServiceRegistrationManagerImplTest { |
|
30 |
|
|
31 |
/** |
|
32 |
* fake profile. |
|
33 |
*/ |
|
34 |
private static final String PROFILE = "<RESOURCE_PROFILE><HEADER><RESOURCE_KIND value=\"PendingServiceResources\"/></HEADER></RESOURCE_PROFILE>"; |
|
35 |
|
|
36 |
/** |
|
37 |
* instance under test. |
|
38 |
*/ |
|
39 |
private transient ServiceRegistrationManagerImpl manager; |
|
40 |
|
|
41 |
/** |
|
42 |
* registrator mock. |
|
43 |
*/ |
|
44 |
@Mock |
|
45 |
private transient ServiceRegistrator registrator; |
|
46 |
|
|
47 |
/** |
|
48 |
* is lookup mock. |
|
49 |
*/ |
|
50 |
@Mock |
|
51 |
private transient ISLookUpService lookUpService; |
|
52 |
@Mock |
|
53 |
private UniqueServiceLocator serviceLocator; |
|
54 |
|
|
55 |
/** |
|
56 |
* prepare. |
|
57 |
* |
|
58 |
* @throws ISLookUpException |
|
59 |
* cannot happen |
|
60 |
*/ |
|
61 |
@Before |
|
62 |
public void setUp() throws ISLookUpException { |
|
63 |
manager = new ServiceRegistrationManagerImpl(); |
|
64 |
manager.setServiceLocator(serviceLocator); |
|
65 |
manager.setRegistrator(registrator); |
|
66 |
manager.setService(new ISLookUpServiceImpl()); |
|
67 |
|
|
68 |
when(serviceLocator.getService(ISLookUpService.class)).thenReturn(lookUpService); |
|
69 |
when(serviceLocator.getService(ISLookUpService.class, true)).thenReturn(lookUpService); |
|
70 |
when(lookUpService.getResourceProfile("123")).thenReturn(PROFILE); |
|
71 |
when(lookUpService.getResourceProfileByQuery(anyString())).thenReturn(PROFILE); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* test state machine. |
|
76 |
*/ |
|
77 |
@Test |
|
78 |
@Ignore |
|
79 |
public void testTick() { |
|
80 |
when(registrator.registerService(anyObject(), (Endpoint) anyObject())).thenReturn("123"); |
|
81 |
|
|
82 |
assertEquals("check unregistered state", ServiceRegistrationManagerImpl.State.UNREGISTERED, manager.getState()); |
|
83 |
manager.tick(); |
|
84 |
assertEquals("check pending state", ServiceRegistrationManagerImpl.State.PENDING, manager.getState()); |
|
85 |
assertEquals("ensure that the mock is correct", "PendingServiceResources", manager.getServiceProfile().getResourceKind()); |
|
86 |
manager.tick(); |
|
87 |
assertEquals("should remain pending", ServiceRegistrationManagerImpl.State.PENDING, manager.getState()); |
|
88 |
|
|
89 |
manager.tick(); |
|
90 |
assertEquals("should remain pending forever", ServiceRegistrationManagerImpl.State.PENDING, manager.getState()); |
|
91 |
} |
|
92 |
|
|
93 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/tools/registration/InterfaceServiceNameGeneratorTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools.registration; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
|
|
5 |
import org.junit.Before; |
|
6 |
import org.junit.Test; |
|
7 |
import org.junit.runner.RunWith; |
|
8 |
import org.mockito.Mock; |
|
9 |
import org.mockito.junit.MockitoJUnitRunner; |
|
10 |
|
|
11 |
import eu.dnetlib.enabling.is.registry.ISRegistryServiceImpl; |
|
12 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
13 |
|
|
14 |
/** |
|
15 |
* test heuristic service name generator. |
|
16 |
* @author marko |
|
17 |
* |
|
18 |
*/ |
|
19 |
@RunWith(MockitoJUnitRunner.class) |
|
20 |
public class InterfaceServiceNameGeneratorTest { |
|
21 |
|
|
22 |
/** |
|
23 |
* instance under test. |
|
24 |
*/ |
|
25 |
private transient ServiceNameResolver generator = new InterfaceServiceNameResolver(); |
|
26 |
|
|
27 |
/** |
|
28 |
* simulates the extension of the service interface. |
|
29 |
* |
|
30 |
* @author marko |
|
31 |
* |
|
32 |
*/ |
|
33 |
interface SomeDummyInterface extends ISRegistryService { |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* simulates the implementation of the service interface. |
|
38 |
* @author marko |
|
39 |
* |
|
40 |
*/ |
|
41 |
abstract class AbstractDummyService implements SomeDummyInterface { |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* simulates the subclassing of the service implementation class. |
|
46 |
* |
|
47 |
* @author marko |
|
48 |
* |
|
49 |
*/ |
|
50 |
abstract class AbstractDummyServiceImpl extends AbstractDummyService { |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* service mock. |
|
55 |
*/ |
|
56 |
@Mock |
|
57 |
private transient AbstractDummyServiceImpl service; |
|
58 |
|
|
59 |
/** |
|
60 |
* setup. |
|
61 |
*/ |
|
62 |
@Before |
|
63 |
public void setUp() { |
|
64 |
generator = new InterfaceServiceNameResolver(); |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* test getName(). |
|
69 |
*/ |
|
70 |
@Test |
|
71 |
public void testGetName() { |
|
72 |
assertEquals("check service name", "ISRegistryService", generator.getName(service)); |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* test getName() on real classes. |
|
77 |
*/ |
|
78 |
@Test |
|
79 |
public void testGetNameReal() { |
|
80 |
assertEquals("check service name", "ISRegistryService", generator.getName(new ISRegistryServiceImpl())); |
|
81 |
} |
|
82 |
|
|
83 |
|
|
84 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/tools/registration/ValidatingServiceRegistrationManagerImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools.registration; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.mockito.Matchers.anyObject; |
|
5 |
import static org.mockito.Matchers.anyString; |
|
6 |
import static org.mockito.Mockito.*; // NOPMD |
|
7 |
|
|
8 |
import javax.xml.ws.Endpoint; |
|
9 |
|
|
10 |
import org.junit.Before; |
|
11 |
import org.junit.Ignore; |
|
12 |
import org.junit.Test; |
|
13 |
import org.junit.runner.RunWith; |
|
14 |
import org.mockito.Mock; |
|
15 |
import org.mockito.junit.MockitoJUnitRunner; |
|
16 |
|
|
17 |
import eu.dnetlib.enabling.is.lookup.ISLookUpServiceImpl; |
|
18 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
19 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
20 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
21 |
|
|
22 |
/** |
|
23 |
* test ValidatingServiceRegistrationManagerImpl. |
|
24 |
* |
|
25 |
* @author marko |
|
26 |
* |
|
27 |
*/ |
|
28 |
@RunWith(MockitoJUnitRunner.class) |
|
29 |
public class ValidatingServiceRegistrationManagerImplTest { |
|
30 |
|
|
31 |
/** |
|
32 |
* profile id. |
|
33 |
*/ |
|
34 |
private static final String PROF_ID = "123"; |
|
35 |
|
|
36 |
/** |
|
37 |
* validated profile id. |
|
38 |
*/ |
|
39 |
private static final String VPROF_ID = "V123"; |
|
40 |
|
|
41 |
/** |
|
42 |
* fake profile. |
|
43 |
*/ |
|
44 |
private static final String PROFILE = "<RESOURCE_PROFILE><HEADER><RESOURCE_KIND value=\"PendingServiceResources\"/></HEADER></RESOURCE_PROFILE>"; |
|
45 |
|
|
46 |
/** |
|
47 |
* fake profile. |
|
48 |
*/ |
|
49 |
private static final String VPROFILE = "<RESOURCE_PROFILE><HEADER><RESOURCE_IDENTIFIER value=\"V123\"/><RESOURCE_KIND value=\"ServiceResources\"/></HEADER></RESOURCE_PROFILE>"; |
|
50 |
|
|
51 |
/** |
|
52 |
* instance under test. |
|
53 |
*/ |
|
54 |
private transient ServiceRegistrationManagerImpl manager; |
|
55 |
|
|
56 |
/** |
|
57 |
* registrator mock. |
|
58 |
*/ |
|
59 |
@Mock |
|
60 |
private transient ServiceRegistrator registrator; |
|
61 |
|
|
62 |
/** |
|
63 |
* is lookup mock. |
|
64 |
*/ |
|
65 |
@Mock |
|
66 |
private transient ISLookUpService lookUpService; |
|
67 |
|
|
68 |
@Mock |
|
69 |
private UniqueServiceLocator serviceLocator; |
|
70 |
|
|
71 |
/** |
|
72 |
* prepare. |
|
73 |
* |
|
74 |
* @throws ISLookUpException |
|
75 |
* cannot happen |
|
76 |
*/ |
|
77 |
@Before |
|
78 |
public void setUp() throws ISLookUpException { |
|
79 |
manager = new ValidatingServiceRegistrationManagerImpl(); |
|
80 |
|
|
81 |
manager.setServiceLocator(serviceLocator); |
|
82 |
manager.setRegistrator(registrator); |
|
83 |
manager.setService(new ISLookUpServiceImpl()); |
|
84 |
|
|
85 |
when(lookUpService.getResourceProfile(PROF_ID)).thenReturn(PROFILE); |
|
86 |
when(lookUpService.getResourceProfile(VPROF_ID)).thenReturn(VPROFILE); |
|
87 |
when(lookUpService.getResourceProfileByQuery(anyString())).thenReturn(PROFILE); |
|
88 |
when(registrator.validateProfile(eq(PROF_ID), any(Endpoint.class))).thenReturn(VPROF_ID); |
|
89 |
when(serviceLocator.getService(ISLookUpService.class)).thenReturn(lookUpService); |
|
90 |
when(serviceLocator.getService(ISLookUpService.class, true)).thenReturn(lookUpService); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* test state machine. |
|
95 |
* |
|
96 |
* @throws ISLookUpException |
|
97 |
* cannot happen |
|
98 |
*/ |
|
99 |
@Test |
|
100 |
@Ignore |
|
101 |
public void testTick() throws ISLookUpException { |
|
102 |
when(registrator.registerService(anyObject(), (Endpoint) anyObject())).thenReturn(PROF_ID); |
|
103 |
|
|
104 |
assertEquals("check unregistered state", ServiceRegistrationManagerImpl.State.UNKNOWN, manager.getState()); |
|
105 |
manager.tick(); |
|
106 |
assertEquals("check pending state", ServiceRegistrationManagerImpl.State.PENDING, manager.getState()); |
|
107 |
assertEquals("ensure that the mock is correct", "PendingServiceResources", manager.getServiceProfile().getResourceKind()); |
|
108 |
manager.tick(); |
|
109 |
|
|
110 |
assertEquals("should register directly", ServiceRegistrationManagerImpl.State.REGISTERED, manager.getState()); |
|
111 |
|
|
112 |
verify(registrator).validateProfile(eq(PROF_ID), (Endpoint) anyObject()); |
|
113 |
|
|
114 |
assertEquals("check validation id", VPROF_ID, manager.getProfileId()); |
|
115 |
assertEquals("check validation profile", VPROF_ID, manager.getServiceProfile().getResourceId()); |
|
116 |
|
|
117 |
manager.tick(); |
|
118 |
assertEquals("should remain registered", ServiceRegistrationManagerImpl.State.REGISTERED, manager.getState()); |
|
119 |
} |
|
120 |
|
|
121 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/tools/registration/InterfaceServiceNameResolverCompatibilityTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools.registration; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
|
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
import org.junit.Before; |
|
9 |
import org.junit.Test; |
|
10 |
|
|
11 |
import eu.dnetlib.enabling.is.store.ISStoreServiceImpl; |
|
12 |
|
|
13 |
/** |
|
14 |
* compatibility interface service name tester. |
|
15 |
* @author marko |
|
16 |
* |
|
17 |
*/ |
|
18 |
public class InterfaceServiceNameResolverCompatibilityTest { |
|
19 |
|
|
20 |
/** |
|
21 |
* instance under test. |
|
22 |
*/ |
|
23 |
private transient InterfaceServiceNameResolverCompatibility resolver; |
|
24 |
|
|
25 |
/** |
|
26 |
* setup. |
|
27 |
*/ |
|
28 |
@Before |
|
29 |
public void setUp() { |
|
30 |
resolver = new InterfaceServiceNameResolverCompatibility(); |
|
31 |
|
|
32 |
} |
|
33 |
|
|
34 |
/** |
|
35 |
* test mapping without override. |
|
36 |
*/ |
|
37 |
@Test |
|
38 |
public void testGetName() { |
|
39 |
assertEquals("check without override", "ISStoreService", resolver.getName(new ISStoreServiceImpl())); |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* test mapping override. |
|
44 |
*/ |
|
45 |
@Test |
|
46 |
public void testGetNameWithOverride() { |
|
47 |
final Map<String, String> mapping = new HashMap<String, String>(); |
|
48 |
mapping.put("ISStoreService", "IS_StoreService"); |
|
49 |
resolver.setMapping(mapping); |
|
50 |
|
|
51 |
assertEquals("check is store service name", "IS_StoreService", resolver.getName(new ISStoreServiceImpl())); |
|
52 |
} |
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/is/sn/AbstractSubscriptionRegistryTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn; |
|
2 |
|
|
3 |
import static org.junit.Assert.*; // NOPMD |
|
4 |
|
|
5 |
import java.util.Collection; |
|
6 |
|
|
7 |
import org.junit.Before; |
|
8 |
import org.junit.Test; |
|
9 |
|
|
10 |
import java.util.Arrays; |
|
11 |
|
|
12 |
/** |
|
13 |
* abstract subscription registry test. |
|
14 |
* |
|
15 |
* @author marko |
|
16 |
* |
|
17 |
*/ |
|
18 |
public class AbstractSubscriptionRegistryTest { |
|
19 |
|
|
20 |
/** |
|
21 |
* object under test. |
|
22 |
*/ |
|
23 |
private transient AbstractSubscriptionRegistry registry; |
|
24 |
|
|
25 |
/** |
|
26 |
* setup . |
|
27 |
* |
|
28 |
* @throws Exception |
|
29 |
*/ |
|
30 |
@Before |
|
31 |
public void setUp() { |
|
32 |
registry = new AbstractSubscriptionRegistry() { |
|
33 |
|
|
34 |
@Override |
|
35 |
protected Collection<String> getAcceptedPrefixes() { |
|
36 |
return Arrays.asList(new String[] { "CREATE", "DELETE", "UPDATE", "DEEP/SUB" }); |
|
37 |
} |
|
38 |
|
|
39 |
}; |
|
40 |
|
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* test prefixes. |
|
45 |
*/ |
|
46 |
@Test |
|
47 |
public void testMatchPrefix() { |
|
48 |
final SubscriptionRequest sub = new SubscriptionRequest(); |
|
49 |
|
|
50 |
sub.setTopicExpression("CREATE/MyResourceType"); |
|
51 |
assertNotNull("check create", registry.matchPrefix(sub)); |
|
52 |
|
|
53 |
sub.setTopicExpression("DELETE/MyResourceType"); |
|
54 |
assertNotNull("check delete", registry.matchPrefix(sub)); |
|
55 |
|
|
56 |
sub.setTopicExpression("UPDATE/MyResourceType"); |
|
57 |
assertNotNull("check update", registry.matchPrefix(sub)); |
|
58 |
|
|
59 |
sub.setTopicExpression("VERIFY/MyResourceType"); |
|
60 |
assertNull("check non declared prefix", registry.matchPrefix(sub)); |
|
61 |
|
|
62 |
sub.setTopicExpression("UPDATED/MyResourceType"); |
|
63 |
assertNull("check non delimited prefix", registry.matchPrefix(sub)); |
|
64 |
|
|
65 |
sub.setTopicExpression("UPDATE"); |
|
66 |
assertNotNull("check only prefix", registry.matchPrefix(sub)); |
|
67 |
|
|
68 |
sub.setTopicExpression("DEEP/MyResourceType"); |
|
69 |
assertNull("check deep", registry.matchPrefix(sub)); |
|
70 |
|
|
71 |
sub.setTopicExpression("DEEP/SUB/MyResourceType"); |
|
72 |
assertNotNull("check deep sub", registry.matchPrefix(sub)); |
|
73 |
} |
|
74 |
|
|
75 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/is/sn/NotificationDetectorImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn; |
|
2 |
|
|
3 |
import static org.junit.Assert.*; // NOPMD |
|
4 |
import static org.mockito.Mockito.*; // NOPMD |
|
5 |
|
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
10 |
import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder; |
|
11 |
|
|
12 |
import org.junit.Before; |
|
13 |
import org.junit.Test; |
|
14 |
import org.junit.runner.RunWith; |
|
15 |
import org.mockito.ArgumentMatcher; |
|
16 |
import org.mockito.Mock; |
|
17 |
|
|
18 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscription; |
|
19 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscriptionRegistry; |
|
20 |
import eu.dnetlib.enabling.tools.OpaqueResource; |
|
21 |
import org.mockito.junit.MockitoJUnitRunner; |
|
22 |
|
|
23 |
/** |
|
24 |
* Test the default notification detector implementation. |
|
25 |
* |
|
26 |
* @author marko |
|
27 |
* |
|
28 |
*/ |
|
29 |
@RunWith(MockitoJUnitRunner.class) |
|
30 |
public class NotificationDetectorImplTest { |
|
31 |
|
|
32 |
/** |
|
33 |
* some type. |
|
34 |
*/ |
|
35 |
private static final String SOME_TYPE = "SomeType"; |
|
36 |
|
|
37 |
/** |
|
38 |
* some resource identifier. |
|
39 |
*/ |
|
40 |
private static final String SOME_ID = "123"; |
|
41 |
|
|
42 |
/** |
|
43 |
* Check if a message has the correct content. |
|
44 |
* |
|
45 |
* @author marko |
|
46 |
* |
|
47 |
*/ |
|
48 |
private final class CheckMessage implements ArgumentMatcher<NotificationMessage> { |
|
49 |
|
|
50 |
/** |
|
51 |
* prefix. |
|
52 |
*/ |
|
53 |
private final transient String prefix; |
|
54 |
|
|
55 |
/** |
|
56 |
* constructor. |
|
57 |
* |
|
58 |
* @param prefix topic prefix |
|
59 |
*/ |
|
60 |
CheckMessage(final String prefix) { |
|
61 |
super(); |
|
62 |
this.prefix = prefix; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* {@inheritDoc} |
|
67 |
* @see org.mockito.ArgumentMatcher#matches(java.lang.Object) |
|
68 |
*/ |
|
69 |
@Override |
|
70 |
public boolean matches(final NotificationMessage argument) { |
|
71 |
return argument.getSubscriptionId() == subscription.getSubscriptionId() && argument.getResourceId().equals("123") |
|
72 |
&& argument.getTopic().equals(prefix + ".*.*"); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* instance under test. |
|
78 |
*/ |
|
79 |
private transient NotificationDetectorImpl detector; |
|
80 |
|
|
81 |
/** |
|
82 |
* registry mock. |
|
83 |
*/ |
|
84 |
@Mock |
|
85 |
private transient ResourceStateSubscriptionRegistry registry; |
|
86 |
|
|
87 |
/** |
|
88 |
* sender mock. |
|
89 |
*/ |
|
90 |
@Mock |
|
91 |
private transient NotificationSender sender; |
|
92 |
|
|
93 |
/** |
|
94 |
* resource mock. |
|
95 |
*/ |
|
96 |
@Mock |
|
97 |
private transient OpaqueResource resource; |
|
98 |
|
|
99 |
/** |
|
100 |
* resource subscription. |
|
101 |
*/ |
|
102 |
@Mock |
|
103 |
private transient ResourceStateSubscription subscription; |
|
104 |
|
|
105 |
/** |
|
106 |
* mock subscriber. |
|
107 |
*/ |
|
108 |
private transient W3CEndpointReference subscriber; |
|
109 |
|
|
110 |
/** |
|
111 |
* common. |
|
112 |
*/ |
|
113 |
@Before |
|
114 |
public void setUp() { |
|
115 |
detector = new NotificationDetectorImpl(); |
|
116 |
|
|
117 |
detector.setRegistry(registry); |
|
118 |
|
|
119 |
detector.setSender(sender); |
|
120 |
|
|
121 |
final W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder(); |
|
122 |
builder.address("http://test.com/test/test"); |
|
123 |
subscriber = builder.build(); |
|
124 |
|
|
125 |
final List<ResourceStateSubscription> subscriptions = new ArrayList<ResourceStateSubscription>(); |
|
126 |
subscriptions.add(subscription); |
|
127 |
when(registry.listMatchingSubscriptions(ResourceStateSubscription.PREFIX_CREATE, SOME_TYPE, SOME_ID)).thenReturn(subscriptions); |
|
128 |
when(registry.listMatchingSubscriptions(ResourceStateSubscription.PREFIX_DELETE, SOME_TYPE, SOME_ID)).thenReturn(subscriptions); |
|
129 |
when(registry.listMatchingSubscriptions(ResourceStateSubscription.PREFIX_UPDATE, SOME_TYPE, SOME_ID)).thenReturn(subscriptions); |
|
130 |
|
|
131 |
when(resource.getResourceId()).thenReturn(SOME_ID); |
|
132 |
when(resource.getResourceType()).thenReturn(SOME_TYPE); |
|
133 |
|
|
134 |
when(subscription.getSubscriptionId()).thenReturn("sn123"); |
|
135 |
when(subscription.getSubscriberAsEpr()).thenReturn(subscriber); |
|
136 |
when(subscription.getXpath()).thenReturn(""); |
|
137 |
when(subscription.getType()).thenReturn("*"); |
|
138 |
when(subscription.getResourceId()).thenReturn("*"); |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* test 'create'. |
|
143 |
*/ |
|
144 |
@Test |
|
145 |
public void testResourceCreated() { |
|
146 |
when(subscription.getPrefix()).thenReturn(ResourceStateSubscription.PREFIX_CREATE); |
|
147 |
|
|
148 |
detector.resourceCreated(resource); |
|
149 |
|
|
150 |
verify(sender).send(eq(subscriber), argThat(new CheckMessage(ResourceStateSubscription.PREFIX_CREATE))); |
|
151 |
|
|
152 |
assertNotNull("dummy", sender); |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* test 'delete'. |
|
157 |
*/ |
|
158 |
@Test |
|
159 |
public void testResourceDeleted() { |
|
160 |
when(subscription.getPrefix()).thenReturn(ResourceStateSubscription.PREFIX_DELETE); |
|
161 |
|
|
162 |
detector.resourceDeleted(resource); |
|
163 |
|
|
164 |
verify(sender).send(eq(subscriber), argThat(new CheckMessage(ResourceStateSubscription.PREFIX_DELETE))); |
|
165 |
|
|
166 |
assertNotNull("dummy", sender); |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* test 'update'. |
|
171 |
*/ |
|
172 |
@Test |
|
173 |
public void testResourceUpdated() { |
|
174 |
when(subscription.getXpath()).thenReturn(null); |
|
175 |
when(subscription.getPrefix()).thenReturn(ResourceStateSubscription.PREFIX_UPDATE); |
|
176 |
|
|
177 |
detector.resourceUpdated(resource, resource); |
|
178 |
|
|
179 |
verify(sender).send(eq(subscriber), argThat(new CheckMessage(ResourceStateSubscription.PREFIX_UPDATE))); |
|
180 |
|
|
181 |
assertNotNull("dummy", sender); |
|
182 |
|
|
183 |
} |
|
184 |
|
|
185 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/is/sn/resourcestate/MemoryResourceStateSubscriptionRegistryTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn.resourcestate; |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* Perform ResourceStateSubscriptionRegistryTest tests on a memory backed resource state subscription dao instance. |
|
6 |
* |
|
7 |
* @author marko |
|
8 |
* |
|
9 |
*/ |
|
10 |
public class MemoryResourceStateSubscriptionRegistryTest extends AbstractResourceStateSubscriptionRegistryTest { // NOPMD |
|
11 |
|
|
12 |
|
|
13 |
/** |
|
14 |
* {@inheritDoc} |
|
15 |
* @see eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionRegistryTest#setUpDao() |
|
16 |
*/ |
|
17 |
@Override |
|
18 |
protected void setUpDao() { |
|
19 |
getRegistry().setSubscriptionDao(new MemoryResourceStateSubscriptionDAOImpl()); |
|
20 |
} |
|
21 |
|
|
22 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/is/sn/resourcestate/hib/HibernateResourceStateSubscriptionDAOImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn.resourcestate.hib; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
import javax.annotation.Resource; |
|
5 |
|
|
6 |
import eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionDAOImplTest; |
|
7 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscription; |
|
8 |
import eu.dnetlib.test.utils.EPRTestUtil; |
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
import org.junit.After; |
|
12 |
import org.junit.Test; |
|
13 |
import org.junit.runner.RunWith; |
|
14 |
import org.springframework.dao.DataIntegrityViolationException; |
|
15 |
import org.springframework.test.annotation.DirtiesContext; |
|
16 |
import org.springframework.test.context.ContextConfiguration; |
|
17 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
18 |
|
|
19 |
import static org.junit.Assert.*; |
|
20 |
|
|
21 |
/** |
|
22 |
* test HibernateResourceStateSubscriptionDAOImplTest. |
|
23 |
* |
|
24 |
* @author marko |
|
25 |
* |
|
26 |
*/ |
|
27 |
@RunWith(SpringJUnit4ClassRunner.class) |
|
28 |
@ContextConfiguration |
|
29 |
public class HibernateResourceStateSubscriptionDAOImplTest extends AbstractResourceStateSubscriptionDAOImplTest { |
|
30 |
/** |
|
31 |
* logger. |
|
32 |
*/ |
|
33 |
private static final Log log = LogFactory.getLog(HibernateResourceStateSubscriptionDAOImplTest.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
34 |
|
|
35 |
/** |
|
36 |
* instance under test. |
|
37 |
*/ |
|
38 |
@Resource |
|
39 |
private transient HibernateResourceStateSubscriptionDAOImpl hibdao; |
|
40 |
|
|
41 |
/** |
|
42 |
* cleanup db. |
|
43 |
*/ |
|
44 |
@After |
|
45 |
public void tearDown() { |
|
46 |
final Collection<ResourceStateSubscription> subs = hibdao.listSubscriptions(); |
|
47 |
if (subs != null) { |
|
48 |
subs.forEach(r -> hibdao.removeSubscription(r.getSubscriptionId())); |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* test addition. |
|
54 |
*/ |
|
55 |
@Test |
|
56 |
public void testAddSubscription() { |
|
57 |
assertNotNull("check dao", getDao()); |
|
58 |
|
|
59 |
getDao().addSubscription(getSub()); |
|
60 |
|
|
61 |
log.info("sub id: " + getSub().getSubscriptionId()); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* test encoding of endpoint references. |
|
66 |
*/ |
|
67 |
@Test |
|
68 |
@DirtiesContext |
|
69 |
public void testEndpoint() { |
|
70 |
getSub().setSubscriber(EPRTestUtil.getTestEpr()); |
|
71 |
|
|
72 |
getDao().addSubscription(getSub()); |
|
73 |
|
|
74 |
final ResourceStateSubscription fresh = getDao().getSubscription(getSub().getSubscriptionId()); |
|
75 |
|
|
76 |
assertNotNull("check", fresh); |
|
77 |
assertTrue("equals", compare(getSub(), fresh)); |
|
78 |
|
|
79 |
assertNotNull("epr", getSub().getSubscriber()); |
|
80 |
assertNotNull("fetched epr", fresh.getSubscriber()); |
|
81 |
|
|
82 |
assertEquals("eprs", getSub().getSubscriber().toString(), fresh.getSubscriber().toString()); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* multiple subscriptions should not be allowed. |
|
87 |
*/ |
|
88 |
@Test(expected = DataIntegrityViolationException.class) |
|
89 |
@DirtiesContext |
|
90 |
public void testMultiple() { // NOPMD |
|
91 |
getDao().addSubscription(getSub()); |
|
92 |
getDao().addSubscription(getSub()); |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
/** |
|
97 |
* {@inheritDoc} |
|
98 |
* |
|
99 |
* @see eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionDAOImplTest#prepareDao() |
|
100 |
*/ |
|
101 |
@Override |
|
102 |
protected void prepareDao() { |
|
103 |
setDao(hibdao); |
|
104 |
} |
|
105 |
|
|
106 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/is/sn/resourcestate/hib/HibernateResourceStateSubscriptionRegistryTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn.resourcestate.hib; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
|
|
5 |
import javax.annotation.Resource; |
|
6 |
|
|
7 |
import org.junit.After; |
|
8 |
import org.junit.runner.RunWith; |
|
9 |
import org.springframework.test.context.ContextConfiguration; |
|
10 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
11 |
|
|
12 |
import eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionRegistryTest; |
|
13 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscription; |
|
14 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscriptionDAO; |
|
15 |
|
|
16 |
/** |
|
17 |
* Perform ResourceStateSubscriptionRegistryTest tests on a hibernate backed resource state subscription dao instance. |
|
18 |
* |
|
19 |
* @author marko |
|
20 |
* |
|
21 |
*/ |
|
22 |
@RunWith(SpringJUnit4ClassRunner.class) |
|
23 |
@ContextConfiguration(locations = { "HibernateResourceStateSubscriptionDAOImplTest-context.xml" }) |
|
24 |
public class HibernateResourceStateSubscriptionRegistryTest extends AbstractResourceStateSubscriptionRegistryTest { // NOPMD |
|
25 |
|
|
26 |
/** |
|
27 |
* hibernate subscription dao. |
|
28 |
*/ |
|
29 |
@Resource |
|
30 |
private transient ResourceStateSubscriptionDAO dao; |
|
31 |
|
|
32 |
/** |
|
33 |
* cleanup db. hsql doesn't recreate the database on spring context reload. |
|
34 |
*/ |
|
35 |
@After |
|
36 |
public void tearDown() { |
|
37 |
final Collection<ResourceStateSubscription> subs = dao.listSubscriptions(); |
|
38 |
if (subs != null) |
|
39 |
for (ResourceStateSubscription r : subs) |
|
40 |
dao.removeSubscription(r.getSubscriptionId()); |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* {@inheritDoc} |
|
45 |
* |
|
46 |
* @see eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionRegistryTest#setUpDao() |
|
47 |
*/ |
|
48 |
@Override |
|
49 |
protected void setUpDao() { |
|
50 |
getRegistry().setSubscriptionDao(dao); |
|
51 |
} |
|
52 |
|
|
53 |
} |
modules/cnr-enabling-services/tags/cnr-enabling-services-2.2.3/src/test/java/eu/dnetlib/enabling/is/sn/resourcestate/ResourceStateSubscriptionRegistryTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn.resourcestate; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.junit.Assert.assertNotNull; // NOPMD |
|
5 |
import static org.mockito.Matchers.argThat; |
|
6 |
import static org.mockito.Mockito.verify; // NOPMD |
|
7 |
|
|
8 |
import org.junit.Before; |
|
9 |
import org.junit.Test; |
|
10 |
import org.junit.runner.RunWith; |
|
11 |
import org.mockito.ArgumentMatcher; |
|
12 |
import org.mockito.Mock; |
|
13 |
import org.mockito.junit.MockitoJUnitRunner; |
|
14 |
|
|
15 |
import eu.dnetlib.enabling.is.sn.SubscriptionRequest; |
|
16 |
import eu.dnetlib.enabling.is.sn.rmi.SubscriptionRequestRejectedException; |
|
17 |
|
|
18 |
/** |
|
19 |
* test ResourceStateSubscriptionRegistryTest. |
|
20 |
* |
|
21 |
* @author marko |
|
22 |
* |
|
23 |
*/ |
|
24 |
@RunWith(MockitoJUnitRunner.class) |
|
25 |
public class ResourceStateSubscriptionRegistryTest { |
|
26 |
|
|
27 |
/** |
|
28 |
* matches. |
|
29 |
* |
|
30 |
* @author marko |
|
31 |
* |
|
32 |
*/ |
|
33 |
public static class MatchSubscription implements ArgumentMatcher<ResourceStateSubscription> { |
|
34 |
|
|
35 |
/** |
|
36 |
* prefix. |
|
37 |
*/ |
|
38 |
private final transient String prefix; |
|
39 |
|
|
40 |
/** |
|
41 |
* type. |
|
42 |
*/ |
|
43 |
private final transient String type; |
|
44 |
|
|
45 |
/** |
|
46 |
* resource id. |
|
47 |
*/ |
|
48 |
private final transient String resId; |
|
49 |
|
|
50 |
/** |
|
51 |
* create a new match subscription checker for a given prefix and a given type. |
|
52 |
* |
|
53 |
* @param prefix |
|
54 |
* prefix |
|
55 |
* @param type |
|
56 |
* type |
|
57 |
* @param resId |
|
58 |
* resource id |
|
59 |
*/ |
|
60 |
MatchSubscription(final String prefix, final String type, final String resId) { |
|
61 |
super(); |
|
62 |
this.prefix = prefix; |
|
63 |
this.type = type; |
|
64 |
this.resId = resId; |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* {@inheritDoc} |
|
69 |
* |
|
70 |
* @see org.mockito.ArgumentMatcher#matches(java.lang.Object) |
|
71 |
*/ |
|
72 |
@Override |
|
73 |
public boolean matches(final ResourceStateSubscription sub) { |
|
74 |
return sub.getPrefix().equals(this.prefix) && sub.getType().equals(this.type) && sub.getResourceId().equals(this.resId); |
|
75 |
} |
|
76 |
|
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* object under test. |
|
81 |
*/ |
|
82 |
private transient ResourceStateSubscriptionRegistry registry; |
|
83 |
|
|
84 |
/** |
|
85 |
* DAO mock. |
|
86 |
*/ |
|
87 |
@Mock |
|
88 |
private transient ResourceStateSubscriptionDAO subscriptionDao; |
|
89 |
|
|
90 |
/** |
|
91 |
* subscription request. |
|
92 |
*/ |
|
93 |
private transient SubscriptionRequest sub; |
|
94 |
|
|
95 |
/** |
|
96 |
* common setup. |
|
97 |
*/ |
|
98 |
@Before |
|
99 |
public void setUp() { |
|
100 |
registry = new ResourceStateSubscriptionRegistry(); |
|
101 |
registry.setSubscriptionDao(subscriptionDao); |
|
102 |
|
|
103 |
final SubscriptionRequestFilter filter = new SubscriptionRequestFilter(); |
|
104 |
filter.setActive(true); |
|
105 |
registry.setSubscriptionRequestFilter(filter); |
|
106 |
|
|
107 |
sub = new SubscriptionRequest(); |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* test registration. |
|
112 |
* |
|
113 |
* @throws SubscriptionRequestRejectedException |
|
114 |
*/ |
|
115 |
@Test |
|
116 |
public void testRegisterSubscription() throws SubscriptionRequestRejectedException { |
|
117 |
sub.setTopicExpression("CREATE/MyResourceType/123/some/path"); |
|
118 |
registry.registerSubscription(sub); |
|
119 |
verify(subscriptionDao).addSubscription(argThat(new MatchSubscription("CREATE", "MyResourceType", "123"))); |
Also available in: Unified diff
[maven-release-plugin] copy for tag cnr-enabling-services-2.2.3