Revision 57161
Added by Enrico Ottonello about 5 years ago
modules/dnet-information-service/branches/saxonHE-SOLR-772/deploy.info | ||
---|---|---|
1 |
{ |
|
2 |
"type_source": "SVN", |
|
3 |
"goal": "package -U source:jar", |
|
4 |
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet50/modules/dnet-information-service/branches/saxonHE", |
|
5 |
"deploy_repository": "dnet5-snapshots", |
|
6 |
"version": "5", |
|
7 |
"mail": "alessia.bardi@isti.cnr.it", |
|
8 |
"deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet5-snapshots", |
|
9 |
"name": "dnet-information-service-saxonHE" |
|
10 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/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/dnet-information-service/branches/saxonHE-SOLR-772/src/test/java/eu/dnetlib/enabling/tools/DOMOpaqueResourceTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.StringReader; |
|
5 |
import java.io.StringWriter; |
|
6 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
7 |
import javax.xml.parsers.ParserConfigurationException; |
|
8 |
import javax.xml.transform.*; |
|
9 |
import javax.xml.xpath.XPathExpressionException; |
|
10 |
|
|
11 |
import org.apache.commons.io.IOUtils; |
|
12 |
import org.junit.Before; |
|
13 |
import org.junit.Test; |
|
14 |
import org.w3c.dom.Document; |
|
15 |
import org.xml.sax.InputSource; |
|
16 |
import org.xml.sax.SAXException; |
|
17 |
|
|
18 |
import static org.junit.Assert.assertEquals; |
|
19 |
import static org.junit.Assert.assertNull; |
|
20 |
import static org.mockito.Mockito.*; |
|
21 |
|
|
22 |
/** |
|
23 |
* Test DOM opaque resource. |
|
24 |
* |
|
25 |
* @author marko |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class DOMOpaqueResourceTest { |
|
29 |
|
|
30 |
/** |
|
31 |
* instance under test. |
|
32 |
*/ |
|
33 |
private transient DOMOpaqueResource resource; |
|
34 |
|
|
35 |
/** |
|
36 |
* xml source, read from test-profile.xml. |
|
37 |
*/ |
|
38 |
private transient String xmlSource; |
|
39 |
|
|
40 |
private TransformerFactory tf; |
|
41 |
|
|
42 |
/** |
|
43 |
* common preparation. |
|
44 |
* |
|
45 |
* @throws ParserConfigurationException |
|
46 |
* shouldn't happen |
|
47 |
* @throws IOException |
|
48 |
* shouldn't happen |
|
49 |
* @throws SAXException |
|
50 |
* shouldn't happen |
|
51 |
* @throws XPathExpressionException |
|
52 |
* shouldn't happen |
|
53 |
*/ |
|
54 |
@Before |
|
55 |
public void setUp() throws SAXException, IOException, ParserConfigurationException, XPathExpressionException { |
|
56 |
tf = TransformerFactory.newInstance(); |
|
57 |
final StringWriter writer = new StringWriter(); |
|
58 |
IOUtils.copy(getClass().getResourceAsStream("test-profile.xml"), writer); |
|
59 |
xmlSource = writer.getBuffer().toString(); |
|
60 |
final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xmlSource))); |
|
61 |
resource = new DOMOpaqueResource(document, tf); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* test dom. |
|
66 |
*/ |
|
67 |
@Test |
|
68 |
public void testAsDom() { |
|
69 |
assertEquals("check that dom is not recreated", resource.getDom(), resource.asDom()); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* serialization check. |
|
74 |
* |
|
75 |
* TODO: use xmlunit |
|
76 |
*/ |
|
77 |
@Test |
|
78 |
public void testAsString() { |
|
79 |
assertEquals("check xml serialization", xmlSource, resource.asString()); |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* test with exception in transformer. |
|
84 |
* @throws TransformerException expected |
|
85 |
*/ |
|
86 |
@Test |
|
87 |
public void testAsStringException() throws TransformerException { |
|
88 |
final Transformer transformer = mock(Transformer.class); |
|
89 |
doThrow(new TransformerException("dummy")).when(transformer).transform((Source) any(), (Result) any()); |
|
90 |
|
|
91 |
resource.setTransformer(transformer); |
|
92 |
assertNull("checks that upon exception we get a null string", resource.asString()); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* check resource id extraction. |
|
97 |
*/ |
|
98 |
@Test |
|
99 |
public void testGetResourceId() { |
|
100 |
assertEquals("check resource id", |
|
101 |
"111-6b4ea417-d940-4dda-a194-3096f685789b_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=", resource |
|
102 |
.getResourceId()); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* check resource type extraction. |
|
107 |
*/ |
|
108 |
@Test |
|
109 |
public void testGetResourceType() { |
|
110 |
assertEquals("check resource type", "RepositoryServiceResourceType", resource.getResourceType()); |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* check resource kind extraction. |
|
115 |
*/ |
|
116 |
@Test |
|
117 |
public void testGetResourceKind() { |
|
118 |
assertEquals("check resource kind", "RepositoryServiceResources", resource.getResourceKind()); |
|
119 |
} |
|
120 |
|
|
121 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/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/dnet-information-service/branches/saxonHE-SOLR-772/src/test/java/eu/dnetlib/enabling/tools/registration/ServiceRegistrationManagerImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.tools.registration; |
|
2 |
|
|
3 |
import java.util.Arrays; |
|
4 |
import javax.xml.ws.Endpoint; |
|
5 |
|
|
6 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
7 |
import eu.dnetlib.rmi.common.BaseService; |
|
8 |
import eu.dnetlib.rmi.enabling.ISLookUpException; |
|
9 |
import eu.dnetlib.rmi.enabling.ISLookUpService; |
|
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 static org.junit.Assert.assertFalse; |
|
18 |
import static org.junit.Assert.assertTrue; |
|
19 |
import static org.mockito.ArgumentMatchers.any; |
|
20 |
import static org.mockito.ArgumentMatchers.anyString; |
|
21 |
import static org.mockito.Mockito.when; |
|
22 |
|
|
23 |
/** |
|
24 |
* test ServiceRegistrationManagerImpl. |
|
25 |
* |
|
26 |
* @author marko |
|
27 |
* |
|
28 |
*/ |
|
29 |
@RunWith(MockitoJUnitRunner.class) |
|
30 |
public class ServiceRegistrationManagerImplTest { |
|
31 |
|
|
32 |
/** |
|
33 |
* fake profile. |
|
34 |
*/ |
|
35 |
private static final String PROFILE = "<RESOURCE_PROFILE><HEADER><RESOURCE_KIND value=\"PendingServiceResources\"/></HEADER></RESOURCE_PROFILE>"; |
|
36 |
|
|
37 |
/** |
|
38 |
* instance under test. |
|
39 |
*/ |
|
40 |
private transient ServiceRegistrationManager manager; |
|
41 |
|
|
42 |
/** |
|
43 |
* registrator mock. |
|
44 |
*/ |
|
45 |
@Mock |
|
46 |
private transient ServiceRegistrator registrator; |
|
47 |
|
|
48 |
/** |
|
49 |
* is lookup mock. |
|
50 |
*/ |
|
51 |
@Mock |
|
52 |
private transient ISLookUpService lookUpService; |
|
53 |
|
|
54 |
@Mock |
|
55 |
private transient Endpoint lookUpServiceEndpoint; |
|
56 |
|
|
57 |
@Mock |
|
58 |
private UniqueServiceLocator serviceLocator; |
|
59 |
|
|
60 |
/** |
|
61 |
* prepare. |
|
62 |
* |
|
63 |
* @throws ISLookUpException |
|
64 |
* cannot happen |
|
65 |
*/ |
|
66 |
@Before |
|
67 |
public void setUp() throws ISLookUpException { |
|
68 |
this.manager = new ServiceRegistrationManager(); |
|
69 |
this.manager.setServiceLocator(this.serviceLocator); |
|
70 |
this.manager.setRegistrator(this.registrator); |
|
71 |
this.manager.setServices(Arrays.asList(this.lookUpServiceEndpoint)); |
|
72 |
|
|
73 |
when(this.lookUpServiceEndpoint.getImplementor()).thenReturn(this.lookUpService); |
|
74 |
when(this.serviceLocator.getService(ISLookUpService.class)).thenReturn(this.lookUpService); |
|
75 |
when(this.serviceLocator.getService(ISLookUpService.class, true)).thenReturn(this.lookUpService); |
|
76 |
when(this.lookUpService.getResourceProfile("123")).thenReturn(PROFILE); |
|
77 |
when(this.lookUpService.getResourceProfileByQuery(anyString())).thenReturn(PROFILE); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* test state machine. |
|
82 |
* |
|
83 |
* @throws Exception |
|
84 |
*/ |
|
85 |
@Test |
|
86 |
@Ignore |
|
87 |
public void testTick() throws Exception { |
|
88 |
when(this.registrator.registerService(any(BaseService.class), any(Endpoint.class))).thenReturn("123"); |
|
89 |
|
|
90 |
assertFalse(this.manager.isDisabled()); |
|
91 |
this.manager.registerAllServices(); |
|
92 |
assertTrue(this.manager.isDisabled()); |
|
93 |
} |
|
94 |
|
|
95 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/src/test/java/eu/dnetlib/enabling/inspector/ResourceLinkToolTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.inspector; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.CompatResourceIdentifierResolverImpl; |
|
4 |
import org.junit.Before; |
|
5 |
import org.junit.Test; |
|
6 |
|
|
7 |
public class ResourceLinkToolTest { |
|
8 |
|
|
9 |
private static String PROFILE = |
|
10 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+ |
|
11 |
"<RESOURCE_PROFILE xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"+ |
|
12 |
"<HEADER>\n"+ |
|
13 |
"<RESOURCE_IDENTIFIER value=\"3cdc5e58-24c6-47ac-b678-401c84956e35_VHJhbnNmb3JtYXRpb25EU1Jlc291cmNlcy9UcmFuc2Zvcm1hdGlvbkRTUmVzb3VyY2VUeXBl\"/>\n"+ |
|
14 |
"<RESOURCE_TYPE value=\"TransformationDSResourceType\"/>\n"+ |
|
15 |
"<RESOURCE_KIND value=\"TransformationDSResources\"/>\n"+ |
|
16 |
"<RESOURCE_URI value=\"http://146.48.85.175:8280/efg-is/services/msro\"/>\n"+ |
|
17 |
"<DATE_OF_CREATION value=\"2010-10-27T10:41:24+02:00\"/>\n"+ |
|
18 |
"</HEADER>\n"+ |
|
19 |
"<BODY>\n"+ |
|
20 |
"<CONFIGURATION>\n"+ |
|
21 |
"<REPOSITORY_SERVICE_IDENTIFIER>d937bab1-d44c-44aa-bf7d-df5312a3b623_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</REPOSITORY_SERVICE_IDENTIFIER>\n"+ |
|
22 |
"<TRANSFORMATION_MANAGER_SERVICE_IDENTIFIER/>\n"+ |
|
23 |
"<TRANSFORMATION_MANAGER_SERVICE_URI/>\n"+ |
|
24 |
"<SOURCE_METADATA_FORMATS>\n"+ |
|
25 |
"<SOURCE_METADATA_FORMAT name=\"efg\" layout=\"store\" interpretation=\"native\"/>\n" + |
|
26 |
"</SOURCE_METADATA_FORMATS>\n"+ |
|
27 |
"<SINK_METADATA_FORMAT interpretation=\"cleaned\" name=\"efg\" layout=\"store\"/>\n" + |
|
28 |
"<DATA_SOURCES>\n"+ |
|
29 |
"<DATA_SOURCE>dnet://MDStoreDS/8d1ab5bb-176c-4eef-9ed3-b46a0aa31d09_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==</DATA_SOURCE>\n"+ |
|
30 |
"</DATA_SOURCES>\n"+ |
|
31 |
"<DATA_SINK>dnet://MDStoreDS/a3a2c757-1726-41b2-9e37-bceb3f8bbd8b_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==?type=REFRESH</DATA_SINK>\n"+ |
|
32 |
"<TRANSFORMATION_RULE_DS_IDENTIFIER/>\n"+ |
|
33 |
"<SCHEDULING/>\n"+ |
|
34 |
"</CONFIGURATION>\n"+ |
|
35 |
"<STATUS>\n"+ |
|
36 |
"<LAST_UPDATE_DATE>2011-01-24T17:22:09+01:00</LAST_UPDATE_DATE>\n"+ |
|
37 |
"<LAST_UPDATE_STATUS>LAST_UPDATE_STATUS</LAST_UPDATE_STATUS>\n"+ |
|
38 |
"<LAST_UPDATE_ERROR_MESSAGE>LAST_UPDATE_ERROR_MESSAGE</LAST_UPDATE_ERROR_MESSAGE>\n"+ |
|
39 |
"</STATUS>\n"+ |
|
40 |
"<SECURITY_PARAMETERS>SECURITY_PARAMETERS</SECURITY_PARAMETERS>\n"+ |
|
41 |
"</BODY>\n"+ |
|
42 |
"</RESOURCE_PROFILE>"; |
|
43 |
|
|
44 |
private ResourceLinkTool linkTool; |
|
45 |
|
|
46 |
@Before |
|
47 |
public void setUp() throws Exception { |
|
48 |
linkTool = new ResourceLinkTool(); |
|
49 |
linkTool.setResolver(new CompatResourceIdentifierResolverImpl()); |
|
50 |
} |
|
51 |
|
|
52 |
@Test |
|
53 |
public void linkfyToHtmlTest() { |
|
54 |
System.out.println(linkTool.linkfyToHtml(PROFILE)); |
|
55 |
} |
|
56 |
|
|
57 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/src/test/java/eu/dnetlib/enabling/is/sn/AbstractSubscriptionRegistryTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn; |
|
2 |
|
|
3 |
import java.util.Arrays; |
|
4 |
import java.util.Collection; |
|
5 |
|
|
6 |
import org.junit.Before; |
|
7 |
import org.junit.Test; |
|
8 |
|
|
9 |
import static org.junit.Assert.assertNotNull; |
|
10 |
import static org.junit.Assert.assertNull; |
|
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 |
* test prefixes. |
|
43 |
*/ |
|
44 |
@Test |
|
45 |
public void testMatchPrefix() { |
|
46 |
final SubscriptionRequest sub = new SubscriptionRequest(); |
|
47 |
|
|
48 |
sub.setTopicExpression("CREATE/MyResourceType"); |
|
49 |
assertNotNull("check create", registry.matchPrefix(sub)); |
|
50 |
|
|
51 |
sub.setTopicExpression("DELETE/MyResourceType"); |
|
52 |
assertNotNull("check delete", registry.matchPrefix(sub)); |
|
53 |
|
|
54 |
sub.setTopicExpression("UPDATE/MyResourceType"); |
|
55 |
assertNotNull("check update", registry.matchPrefix(sub)); |
|
56 |
|
|
57 |
sub.setTopicExpression("VERIFY/MyResourceType"); |
|
58 |
assertNull("check non declared prefix", registry.matchPrefix(sub)); |
|
59 |
|
|
60 |
sub.setTopicExpression("UPDATED/MyResourceType"); |
|
61 |
assertNull("check non delimited prefix", registry.matchPrefix(sub)); |
|
62 |
|
|
63 |
sub.setTopicExpression("UPDATE"); |
|
64 |
assertNotNull("check only prefix", registry.matchPrefix(sub)); |
|
65 |
|
|
66 |
sub.setTopicExpression("DEEP/MyResourceType"); |
|
67 |
assertNull("check deep", registry.matchPrefix(sub)); |
|
68 |
|
|
69 |
sub.setTopicExpression("DEEP/SUB/MyResourceType"); |
|
70 |
assertNotNull("check deep sub", registry.matchPrefix(sub)); |
|
71 |
} |
|
72 |
|
|
73 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/src/test/java/eu/dnetlib/enabling/is/sn/NotificationDetectorImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
6 |
import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder; |
|
7 |
|
|
8 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscription; |
|
9 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscriptionRegistry; |
|
10 |
import eu.dnetlib.enabling.tools.OpaqueResource; |
|
11 |
import org.junit.Before; |
|
12 |
import org.junit.Test; |
|
13 |
import org.junit.runner.RunWith; |
|
14 |
import org.mockito.ArgumentMatcher; |
|
15 |
import org.mockito.Mock; |
|
16 |
import org.mockito.junit.MockitoJUnitRunner; |
|
17 |
|
|
18 |
import static org.junit.Assert.assertNotNull; |
|
19 |
import static org.mockito.Mockito.*; |
|
20 |
|
|
21 |
/** |
|
22 |
* Test the default notification detector implementation. |
|
23 |
* |
|
24 |
* @author marko |
|
25 |
* |
|
26 |
*/ |
|
27 |
@RunWith(MockitoJUnitRunner.class) |
|
28 |
public class NotificationDetectorImplTest { |
|
29 |
|
|
30 |
/** |
|
31 |
* some type. |
|
32 |
*/ |
|
33 |
private static final String SOME_TYPE = "SomeType"; |
|
34 |
|
|
35 |
/** |
|
36 |
* some resource identifier. |
|
37 |
*/ |
|
38 |
private static final String SOME_ID = "123"; |
|
39 |
|
|
40 |
/** |
|
41 |
* Check if a message has the correct content. |
|
42 |
* |
|
43 |
* @author marko |
|
44 |
* |
|
45 |
*/ |
|
46 |
private final class CheckMessage implements ArgumentMatcher<NotificationMessage> { |
|
47 |
|
|
48 |
/** |
|
49 |
* prefix. |
|
50 |
*/ |
|
51 |
private final transient String prefix; |
|
52 |
|
|
53 |
/** |
|
54 |
* constructor. |
|
55 |
* |
|
56 |
* @param prefix topic prefix |
|
57 |
*/ |
|
58 |
CheckMessage(final String prefix) { |
|
59 |
super(); |
|
60 |
this.prefix = prefix; |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* {@inheritDoc} |
|
65 |
* @see org.mockito.ArgumentMatcher#matches(java.lang.Object) |
|
66 |
*/ |
|
67 |
@Override |
|
68 |
public boolean matches(final NotificationMessage message) { |
|
69 |
return message.getSubscriptionId() == subscription.getSubscriptionId() && message.getResourceId().equals("123") |
|
70 |
&& message.getTopic().equals(prefix + ".*.*"); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* instance under test. |
|
76 |
*/ |
|
77 |
private transient NotificationDetectorImpl detector; |
|
78 |
|
|
79 |
/** |
|
80 |
* registry mock. |
|
81 |
*/ |
|
82 |
@Mock |
|
83 |
private transient ResourceStateSubscriptionRegistry registry; |
|
84 |
|
|
85 |
/** |
|
86 |
* sender mock. |
|
87 |
*/ |
|
88 |
@Mock |
|
89 |
private transient NotificationSender sender; |
|
90 |
|
|
91 |
/** |
|
92 |
* resource mock. |
|
93 |
*/ |
|
94 |
@Mock |
|
95 |
private transient OpaqueResource resource; |
|
96 |
|
|
97 |
/** |
|
98 |
* resource subscription. |
|
99 |
*/ |
|
100 |
@Mock |
|
101 |
private transient ResourceStateSubscription subscription; |
|
102 |
|
|
103 |
/** |
|
104 |
* mock subscriber. |
|
105 |
*/ |
|
106 |
private transient W3CEndpointReference subscriber; |
|
107 |
|
|
108 |
/** |
|
109 |
* common. |
|
110 |
*/ |
|
111 |
@Before |
|
112 |
public void setUp() { |
|
113 |
detector = new NotificationDetectorImpl(); |
|
114 |
final List<ResourceStateSubscriptionRegistry> registries = new ArrayList<ResourceStateSubscriptionRegistry>(); |
|
115 |
registries.add(registry); |
|
116 |
detector.setRegistries(registries); |
|
117 |
|
|
118 |
detector.setSender(sender); |
|
119 |
|
|
120 |
final W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder(); |
|
121 |
builder.address("http://test.com/test/test"); |
|
122 |
subscriber = builder.build(); |
|
123 |
|
|
124 |
final List<ResourceStateSubscription> subscriptions = new ArrayList<ResourceStateSubscription>(); |
|
125 |
subscriptions.add(subscription); |
|
126 |
when(registry.listMatchingSubscriptions(ResourceStateSubscription.PREFIX_CREATE, SOME_TYPE, SOME_ID)).thenReturn(subscriptions); |
|
127 |
when(registry.listMatchingSubscriptions(ResourceStateSubscription.PREFIX_DELETE, SOME_TYPE, SOME_ID)).thenReturn(subscriptions); |
|
128 |
when(registry.listMatchingSubscriptions(ResourceStateSubscription.PREFIX_UPDATE, SOME_TYPE, SOME_ID)).thenReturn(subscriptions); |
|
129 |
|
|
130 |
when(resource.getResourceId()).thenReturn(SOME_ID); |
|
131 |
when(resource.getResourceType()).thenReturn(SOME_TYPE); |
|
132 |
|
|
133 |
when(subscription.getSubscriptionId()).thenReturn("sn123"); |
|
134 |
when(subscription.getSubscriberAsEpr()).thenReturn(subscriber); |
|
135 |
when(subscription.getXpath()).thenReturn(""); |
|
136 |
when(subscription.getType()).thenReturn("*"); |
|
137 |
when(subscription.getResourceId()).thenReturn("*"); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* test 'create'. |
|
142 |
*/ |
|
143 |
@Test |
|
144 |
public void testResourceCreated() { |
|
145 |
when(subscription.getPrefix()).thenReturn(ResourceStateSubscription.PREFIX_CREATE); |
|
146 |
|
|
147 |
detector.resourceCreated(resource); |
|
148 |
|
|
149 |
verify(sender).send(eq(subscriber), argThat(new CheckMessage(ResourceStateSubscription.PREFIX_CREATE))); |
|
150 |
|
|
151 |
assertNotNull("dummy", sender); |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* test 'delete'. |
|
156 |
*/ |
|
157 |
@Test |
|
158 |
public void testResourceDeleted() { |
|
159 |
when(subscription.getPrefix()).thenReturn(ResourceStateSubscription.PREFIX_DELETE); |
|
160 |
|
|
161 |
detector.resourceDeleted(resource); |
|
162 |
|
|
163 |
verify(sender).send(eq(subscriber), argThat(new CheckMessage(ResourceStateSubscription.PREFIX_DELETE))); |
|
164 |
|
|
165 |
assertNotNull("dummy", sender); |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* test 'update'. |
|
170 |
*/ |
|
171 |
@Test |
|
172 |
public void testResourceUpdated() { |
|
173 |
when(subscription.getXpath()).thenReturn(null); |
|
174 |
when(subscription.getPrefix()).thenReturn(ResourceStateSubscription.PREFIX_UPDATE); |
|
175 |
|
|
176 |
detector.resourceUpdated(resource, resource); |
|
177 |
|
|
178 |
verify(sender).send(eq(subscriber), argThat(new CheckMessage(ResourceStateSubscription.PREFIX_UPDATE))); |
|
179 |
|
|
180 |
assertNotNull("dummy", sender); |
|
181 |
|
|
182 |
} |
|
183 |
|
|
184 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/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/dnet-information-service/branches/saxonHE-SOLR-772/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 |
|
|
5 |
import eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionDAOImplTest; |
|
6 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscription; |
|
7 |
import eu.dnetlib.test.utils.EPRTestUtil; |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.junit.After; |
|
11 |
import org.junit.Test; |
|
12 |
import org.junit.runner.RunWith; |
|
13 |
import org.springframework.beans.factory.annotation.Autowired; |
|
14 |
import org.springframework.orm.hibernate5.HibernateJdbcException; |
|
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 |
@Autowired |
|
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 |
for (ResourceStateSubscription r : subs) |
|
49 |
hibdao.removeSubscription(r.getSubscriptionId()); |
|
50 |
|
|
51 |
// for (ResourceStateSubscription r : subs) |
|
52 |
// log.info("deleted: " + r); |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* test addition. |
|
57 |
*/ |
|
58 |
@Test |
|
59 |
public void testAddSubscription() { |
|
60 |
assertNotNull("check dao", getDao()); |
|
61 |
|
|
62 |
getDao().addSubscription(getSub()); |
|
63 |
|
|
64 |
log.info("sub id: " + getSub().getSubscriptionId()); |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* test encoding of endpoint references. |
|
69 |
*/ |
|
70 |
@Test |
|
71 |
@DirtiesContext |
|
72 |
public void testEndpoint() { |
|
73 |
getSub().setSubscriber(EPRTestUtil.getTestEpr()); |
|
74 |
|
|
75 |
getDao().addSubscription(getSub()); |
|
76 |
|
|
77 |
final ResourceStateSubscription fresh = getDao().getSubscription(getSub().getSubscriptionId()); |
|
78 |
|
|
79 |
assertNotNull("check", fresh); |
|
80 |
assertTrue("equals", compare(getSub(), fresh)); |
|
81 |
|
|
82 |
assertNotNull("epr", getSub().getSubscriber()); |
|
83 |
assertNotNull("fetched epr", fresh.getSubscriber()); |
|
84 |
|
|
85 |
assertEquals("eprs", getSub().getSubscriber().toString(), fresh.getSubscriber().toString()); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* multiple subscriptions should not be allowed. |
|
90 |
*/ |
|
91 |
@Test(expected = HibernateJdbcException.class) |
|
92 |
@DirtiesContext |
|
93 |
public void testMultiple() { // NOPMD |
|
94 |
getDao().addSubscription(getSub()); |
|
95 |
getDao().addSubscription(getSub()); |
|
96 |
} |
|
97 |
|
|
98 |
|
|
99 |
/** |
|
100 |
* {@inheritDoc} |
|
101 |
* |
|
102 |
* @see eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionDAOImplTest#prepareDao() |
|
103 |
*/ |
|
104 |
@Override |
|
105 |
protected void prepareDao() { |
|
106 |
setDao(hibdao); |
|
107 |
} |
|
108 |
|
|
109 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/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 eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionRegistryTest; |
|
6 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscription; |
|
7 |
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscriptionDAO; |
|
8 |
import org.junit.After; |
|
9 |
import org.junit.runner.RunWith; |
|
10 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 |
import org.springframework.test.context.ContextConfiguration; |
|
12 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
13 |
|
|
14 |
/** |
|
15 |
* Perform ResourceStateSubscriptionRegistryTest tests on a hibernate backed resource state subscription dao instance. |
|
16 |
* |
|
17 |
* @author marko |
|
18 |
* |
|
19 |
*/ |
|
20 |
@RunWith(SpringJUnit4ClassRunner.class) |
|
21 |
@ContextConfiguration(locations = { "HibernateResourceStateSubscriptionDAOImplTest-context.xml" }) |
|
22 |
public class HibernateResourceStateSubscriptionRegistryTest extends AbstractResourceStateSubscriptionRegistryTest { // NOPMD |
|
23 |
|
|
24 |
/** |
|
25 |
* hibernate subscription dao. |
|
26 |
*/ |
|
27 |
@Autowired |
|
28 |
private transient ResourceStateSubscriptionDAO dao; |
|
29 |
|
|
30 |
/** |
|
31 |
* cleanup db. hsql doesn't recreate the database on spring context reload. |
|
32 |
*/ |
|
33 |
@After |
|
34 |
public void tearDown() { |
|
35 |
final Collection<ResourceStateSubscription> subs = dao.listSubscriptions(); |
|
36 |
if (subs != null) |
|
37 |
for (ResourceStateSubscription r : subs) |
|
38 |
dao.removeSubscription(r.getSubscriptionId()); |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* {@inheritDoc} |
|
43 |
* |
|
44 |
* @see eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionRegistryTest#setUpDao() |
|
45 |
*/ |
|
46 |
@Override |
|
47 |
protected void setUpDao() { |
|
48 |
getRegistry().setSubscriptionDao(dao); |
|
49 |
} |
|
50 |
|
|
51 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/src/test/java/eu/dnetlib/enabling/is/sn/resourcestate/ResourceStateSubscriptionRegistryTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn.resourcestate; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.is.sn.SubscriptionRequest; |
|
4 |
import eu.dnetlib.rmi.enabling.SubscriptionRequestRejectedException; |
|
5 |
import org.junit.Before; |
|
6 |
import org.junit.Test; |
|
7 |
import org.junit.runner.RunWith; |
|
8 |
import org.mockito.ArgumentMatcher; |
|
9 |
import org.mockito.Mock; |
|
10 |
import org.mockito.junit.MockitoJUnitRunner; |
|
11 |
|
|
12 |
import static org.junit.Assert.assertEquals; |
|
13 |
import static org.junit.Assert.assertNotNull; |
|
14 |
import static org.mockito.ArgumentMatchers.*; |
|
15 |
import static org.mockito.Mockito.verify; |
|
16 |
|
|
17 |
/** |
|
18 |
* test ResourceStateSubscriptionRegistryTest. |
|
19 |
* |
|
20 |
* @author marko |
|
21 |
* |
|
22 |
*/ |
|
23 |
@RunWith(MockitoJUnitRunner.class) |
|
24 |
public class ResourceStateSubscriptionRegistryTest { |
|
25 |
|
|
26 |
/** |
|
27 |
* matches. |
|
28 |
* |
|
29 |
* @author marko |
|
30 |
* |
|
31 |
*/ |
|
32 |
public static class MatchSubscription implements ArgumentMatcher<ResourceStateSubscription> { |
|
33 |
|
|
34 |
/** |
|
35 |
* prefix. |
|
36 |
*/ |
|
37 |
private final transient String prefix; |
|
38 |
|
|
39 |
/** |
|
40 |
* type. |
|
41 |
*/ |
|
42 |
private final transient String type; |
|
43 |
|
|
44 |
/** |
|
45 |
* resource id. |
|
46 |
*/ |
|
47 |
private final transient String resId; |
|
48 |
|
|
49 |
/** |
|
50 |
* create a new match subscription checker for a given prefix and a given type. |
|
51 |
* |
|
52 |
* @param prefix |
|
53 |
* prefix |
|
54 |
* @param type |
|
55 |
* type |
|
56 |
* @param resId |
|
57 |
* resource id |
|
58 |
*/ |
|
59 |
MatchSubscription(final String prefix, final String type, final String resId) { |
|
60 |
super(); |
|
61 |
this.prefix = prefix; |
|
62 |
this.type = type; |
|
63 |
this.resId = resId; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* {@inheritDoc} |
|
68 |
* |
|
69 |
* @see org.mockito.ArgumentMatcher#matches(java.lang.Object) |
|
70 |
*/ |
|
71 |
@Override |
|
72 |
public boolean matches(final ResourceStateSubscription sub) { |
|
73 |
return sub.getPrefix().equals(this.prefix) && sub.getType().equals(this.type) && sub.getResourceId().equals(this.resId); |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* object under test. |
|
80 |
*/ |
|
81 |
private transient ResourceStateSubscriptionRegistry registry; |
|
82 |
|
|
83 |
/** |
|
84 |
* DAO mock. |
|
85 |
*/ |
|
86 |
@Mock |
|
87 |
private transient ResourceStateSubscriptionDAO subscriptionDao; |
|
88 |
|
|
89 |
/** |
|
90 |
* subscription request. |
|
91 |
*/ |
|
92 |
private transient SubscriptionRequest sub; |
|
93 |
|
|
94 |
/** |
|
95 |
* common setup. |
|
96 |
*/ |
|
97 |
@Before |
|
98 |
public void setUp() { |
|
99 |
registry = new ResourceStateSubscriptionRegistry(); |
|
100 |
registry.setSubscriptionDao(subscriptionDao); |
|
101 |
|
|
102 |
final SubscriptionRequestFilter filter = new SubscriptionRequestFilter(); |
|
103 |
filter.setActive(true); |
|
104 |
registry.setSubscriptionRequestFilter(filter); |
|
105 |
|
|
106 |
sub = new SubscriptionRequest(); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* test registration. |
|
111 |
* |
|
112 |
* @throws SubscriptionRequestRejectedException |
|
113 |
*/ |
|
114 |
@Test |
|
115 |
public void testRegisterSubscription() throws SubscriptionRequestRejectedException { |
|
116 |
sub.setTopicExpression("CREATE/MyResourceType/123/some/path"); |
|
117 |
registry.registerSubscription(sub); |
|
118 |
verify(subscriptionDao).addSubscription(argThat(new MatchSubscription("CREATE", "MyResourceType", "123"))); |
|
119 |
|
|
120 |
assertNotNull("dummy", subscriptionDao); |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* test registration. |
|
125 |
* |
|
126 |
* @throws SubscriptionRequestRejectedException |
|
127 |
*/ |
|
128 |
@Test(expected = SubscriptionRequestRejectedException.class) |
|
129 |
public void testRegisterSubscriptionReject1() throws SubscriptionRequestRejectedException { |
|
130 |
|
|
131 |
sub.setTopicExpression("UPDATE/OtherResourceType"); |
|
132 |
registry.registerSubscription(sub); |
|
133 |
verify(subscriptionDao).addSubscription(argThat(new MatchSubscription("UPDATE", "OtherResourceType", "*"))); |
|
134 |
|
|
135 |
assertNotNull("dummy", subscriptionDao); |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* test registration. |
|
140 |
* |
|
141 |
* @throws SubscriptionRequestRejectedException |
|
142 |
*/ |
|
143 |
@Test(expected = SubscriptionRequestRejectedException.class) |
|
144 |
public void testRegisterSubscriptionReject2() throws SubscriptionRequestRejectedException { |
|
145 |
|
|
146 |
sub.setTopicExpression("DELETE/*"); |
|
147 |
registry.registerSubscription(sub); |
|
148 |
// verify(subscriptionDao).addSubscription(argThat(new MatchSubscription("DELETE", "*", "*"))); |
|
149 |
// |
|
150 |
// assertNotNull("dummy", subscriptionDao); |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* test registration. |
|
155 |
* |
|
156 |
* @throws SubscriptionRequestRejectedException |
|
157 |
*/ |
|
158 |
@Test(expected = SubscriptionRequestRejectedException.class) |
|
159 |
public void testRegisterSubscriptionReject3() throws SubscriptionRequestRejectedException { |
|
160 |
|
|
161 |
sub.setTopicExpression("CREATE"); |
|
162 |
registry.registerSubscription(sub); |
|
163 |
verify(subscriptionDao).addSubscription(argThat(new MatchSubscription("CREATE", "*", "*"))); |
|
164 |
|
|
165 |
assertNotNull("dummy", subscriptionDao); |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* test match id. |
|
170 |
*/ |
|
171 |
@Test |
|
172 |
public void testMatchId() { |
|
173 |
assertEquals("check pure id", "1234123", registry.matchId("1234123").getPrefix()); |
|
174 |
assertEquals("check with suffix", "1234123", registry.matchId("1234123/blabla/blabla").getPrefix()); |
|
175 |
assertEquals("check suffix", "/blabla/blabla", registry.matchId("1234123/blabla/blabla").getRest()); |
|
176 |
} |
|
177 |
|
|
178 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/src/test/java/eu/dnetlib/enabling/is/sn/resourcestate/AbstractResourceStateSubscriptionDAOImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn.resourcestate; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.junit.Assert.assertNotNull; |
|
5 |
import static org.junit.Assert.assertTrue; |
|
6 |
|
|
7 |
import java.util.Collection; |
|
8 |
|
|
9 |
import org.apache.commons.beanutils.BeanComparator; |
|
10 |
import org.junit.Before; |
|
11 |
import org.junit.Ignore; |
|
12 |
import org.junit.Test; |
|
13 |
|
|
14 |
/** |
|
15 |
* testing MemoryResourceStateSubscriptionDAOImpl. |
|
16 |
* |
|
17 |
* @author marko |
|
18 |
* |
|
19 |
*/ |
|
20 |
public abstract class AbstractResourceStateSubscriptionDAOImplTest { |
|
21 |
|
|
22 |
/** |
|
23 |
* update topic prefix. |
|
24 |
*/ |
|
25 |
private static final String UPDATE = "UPDATE"; |
|
26 |
|
|
27 |
/** |
|
28 |
* create topic prefix. |
|
29 |
*/ |
|
30 |
private static final String CREATE = "CREATE"; |
|
31 |
|
|
32 |
/** |
|
33 |
* test resource type. |
|
34 |
*/ |
|
35 |
private static final String SOME_TYPE = "someType"; |
|
36 |
|
|
37 |
/** |
|
38 |
* test other resource type. |
|
39 |
*/ |
|
40 |
private static final String SOME_OTHER_TYPE = "someOtherType"; |
|
41 |
|
|
42 |
/** |
|
43 |
* test resource id. |
|
44 |
*/ |
|
45 |
private static final String SOME_ID = "123"; |
|
46 |
|
|
47 |
/** |
|
48 |
* class under test. |
|
49 |
*/ |
|
50 |
private ResourceStateSubscriptionDAO dao; |
|
51 |
|
|
52 |
/** |
|
53 |
* test subscription. |
|
54 |
*/ |
|
55 |
private transient ResourceStateSubscription sub; |
|
56 |
|
|
57 |
/** |
|
58 |
* test subscription. |
|
59 |
*/ |
|
60 |
private transient ResourceStateSubscription sub2; |
|
61 |
|
|
62 |
/** |
|
63 |
* test subscription. |
|
64 |
*/ |
|
65 |
private transient ResourceStateSubscription sub3; |
|
66 |
|
|
67 |
/** |
|
68 |
* test subscription. |
|
69 |
*/ |
|
70 |
private transient ResourceStateSubscription sub4; |
|
71 |
|
|
72 |
/** |
|
73 |
* test subscription. |
|
74 |
*/ |
|
75 |
private transient ResourceStateSubscription sub5; |
|
76 |
|
|
77 |
/** |
|
78 |
* common setup. |
|
79 |
*/ |
|
80 |
@Before |
|
81 |
public void setUp() { |
|
82 |
prepareDao(); |
|
83 |
|
|
84 |
sub = new ResourceStateSubscription(); |
|
85 |
sub.setSubscriptionId("sn123"); |
|
86 |
sub.setPrefix(CREATE); |
|
87 |
sub.setType(SOME_TYPE); |
|
88 |
sub.setXpath("somePath"); |
|
89 |
|
|
90 |
sub2 = new ResourceStateSubscription(); |
|
91 |
sub2.setSubscriptionId("sn666"); |
|
92 |
sub2.setPrefix(UPDATE); |
|
93 |
sub2.setType(SOME_TYPE); |
|
94 |
sub2.setXpath("somePath"); |
|
95 |
|
|
96 |
sub3 = new ResourceStateSubscription(); |
|
97 |
sub3.setSubscriptionId("sn000"); |
|
98 |
sub3.setPrefix(CREATE); |
|
99 |
sub3.setType(SOME_TYPE); |
|
100 |
sub3.setXpath("somePath"); |
|
101 |
|
|
102 |
sub4 = new ResourceStateSubscription(); |
|
103 |
sub4.setSubscriptionId("sn987"); |
|
104 |
sub4.setPrefix(CREATE); |
|
105 |
sub4.setType("*"); |
|
106 |
sub4.setResourceId(SOME_ID); |
|
107 |
|
|
108 |
sub5 = new ResourceStateSubscription(); |
|
109 |
sub5.setSubscriptionId("sn888"); |
|
110 |
sub5.setPrefix(UPDATE); |
|
111 |
sub5.setType(SOME_TYPE); |
|
112 |
sub5.setResourceId(SOME_ID); |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* subsclasses should implement this in order to plug their implementation of the dao. |
|
117 |
*/ |
|
118 |
protected abstract void prepareDao(); |
|
119 |
|
|
120 |
/** |
|
121 |
* compare two subscriptions. |
|
122 |
* |
|
123 |
* @param left |
|
124 |
* lhs |
|
125 |
* @param right |
|
126 |
* rhs |
|
127 |
* @return true if the objects are equal |
|
128 |
*/ |
|
129 |
protected boolean compare(final ResourceStateSubscription left, final ResourceStateSubscription right) { |
|
130 |
return new BeanComparator("subscriptionId").compare(left, right) == 0 && new BeanComparator("prefix").compare(left, right) == 0 |
|
131 |
&& new BeanComparator("type").compare(left, right) == 0 && new BeanComparator("resourceId").compare(left, right) == 0; |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* test list subscriptions for prefix and type. |
|
136 |
*/ |
|
137 |
@Test |
|
138 |
public void testListSubscriptionsStringString() { |
|
139 |
dao.addSubscription(sub); |
|
140 |
dao.addSubscription(sub2); |
|
141 |
dao.addSubscription(sub3); |
|
142 |
dao.addSubscription(sub4); |
|
143 |
|
|
144 |
for (ResourceStateSubscription s : dao.listSubscriptions(UPDATE, SOME_TYPE, SOME_ID)) |
|
145 |
assertTrue("check subscription", compare(s, sub2)); |
|
146 |
|
|
147 |
assertEquals("check size", 2, dao.listSubscriptions(CREATE, SOME_TYPE, "*").size()); |
|
148 |
|
|
149 |
for (ResourceStateSubscription s : dao.listSubscriptions(CREATE, "*", SOME_ID)) |
|
150 |
assertTrue("check subscription star", compare(s, sub4)); |
|
151 |
|
|
152 |
assertEquals("check size star", 1, dao.listSubscriptions(CREATE, "*", SOME_ID).size()); |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* enable this test when the manual merging of subscriptions is removed from the ResourceStateSubscriptionRegistry. |
|
157 |
* The ResourceState subscription DAO alone should be able to quickly resolve wildcards. |
|
158 |
*/ |
|
159 |
@Test |
|
160 |
@Ignore |
|
161 |
public void testListSubscriptionsStar() { |
|
162 |
dao.addSubscription(sub); |
|
163 |
dao.addSubscription(sub2); |
|
164 |
dao.addSubscription(sub3); |
|
165 |
dao.addSubscription(sub4); |
|
166 |
|
|
167 |
for (ResourceStateSubscription s : dao.listSubscriptions(CREATE, SOME_OTHER_TYPE, SOME_ID)) |
|
168 |
assertTrue("check subscription fixed star", compare(s, sub4)); |
|
169 |
|
|
170 |
assertEquals("check size fixed tar", 1, dao.listSubscriptions(CREATE, SOME_OTHER_TYPE, SOME_ID).size()); |
|
171 |
|
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* test get a specific subscription by id. |
|
176 |
*/ |
|
177 |
@Test |
|
178 |
public void testGetSubscription() { |
|
179 |
|
|
180 |
dao.addSubscription(sub); |
|
181 |
|
|
182 |
assertNotNull("check that it's registered", dao.getSubscription(sub.getSubscriptionId())); |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* test list all subscriptions. |
|
187 |
*/ |
|
188 |
@Test |
|
189 |
public void testListSubscriptions() { |
|
190 |
dao.addSubscription(sub); |
|
191 |
for (ResourceStateSubscription s : dao.listSubscriptions()) |
|
192 |
assertTrue("check subscription", compare(s, sub)); |
|
193 |
|
|
194 |
assertEquals("check size", 1, dao.listSubscriptions().size()); |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* test specific subscription. |
|
199 |
*/ |
|
200 |
@Test |
|
201 |
public void testSpecificSubscription() { |
|
202 |
dao.addSubscription(sub5); |
|
203 |
|
|
204 |
final Collection<ResourceStateSubscription> res = dao.listSubscriptions(UPDATE, SOME_TYPE, SOME_ID); |
|
205 |
assertEquals("only one", 1, res.size()); |
|
206 |
|
|
207 |
assertNotNull("", res.iterator().next()); |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* test list subscriptions for a given prefix. |
|
212 |
*/ |
|
213 |
@Test |
|
214 |
public void testListSubscriptionsString() { |
|
215 |
dao.addSubscription(sub); |
|
216 |
dao.addSubscription(sub2); |
|
217 |
|
|
218 |
for (ResourceStateSubscription s : dao.listSubscriptions(UPDATE)) |
|
219 |
assertTrue("check subscription", compare(s, sub2)); |
|
220 |
} |
|
221 |
|
|
222 |
public ResourceStateSubscriptionDAO getDao() { |
|
223 |
return dao; |
|
224 |
} |
|
225 |
|
|
226 |
public void setDao(final ResourceStateSubscriptionDAO dao) { |
|
227 |
this.dao = dao; |
|
228 |
} |
|
229 |
|
|
230 |
public ResourceStateSubscription getSub() { |
|
231 |
return sub; |
|
232 |
} |
|
233 |
|
|
234 |
public void setSub(final ResourceStateSubscription sub) { |
|
235 |
this.sub = sub; |
|
236 |
} |
|
237 |
|
|
238 |
public ResourceStateSubscription getSub2() { |
|
239 |
return sub2; |
|
240 |
} |
|
241 |
|
|
242 |
public void setSub2(final ResourceStateSubscription sub2) { |
|
243 |
this.sub2 = sub2; |
|
244 |
} |
|
245 |
|
|
246 |
public ResourceStateSubscription getSub3() { |
|
247 |
return sub3; |
|
248 |
} |
|
249 |
|
|
250 |
public void setSub3(final ResourceStateSubscription sub3) { |
|
251 |
this.sub3 = sub3; |
|
252 |
} |
|
253 |
|
|
254 |
public ResourceStateSubscription getSub4() { |
|
255 |
return sub4; |
|
256 |
} |
|
257 |
|
|
258 |
public void setSub4(final ResourceStateSubscription sub4) { |
|
259 |
this.sub4 = sub4; |
|
260 |
} |
|
261 |
|
|
262 |
} |
modules/dnet-information-service/branches/saxonHE-SOLR-772/src/test/java/eu/dnetlib/enabling/is/sn/resourcestate/AbstractResourceStateSubscriptionRegistryTest.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.is.sn.resourcestate; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.junit.Assert.assertFalse; |
|
5 |
import static org.junit.Assert.assertTrue; |
|
6 |
|
|
7 |
import java.util.Collection; |
|
8 |
|
|
9 |
import org.junit.Before; |
|
10 |
import org.junit.Test; |
|
11 |
|
|
12 |
import eu.dnetlib.enabling.is.sn.SubscriptionRequest; |
|
13 |
import eu.dnetlib.rmi.enabling.SubscriptionRequestRejectedException; |
|
14 |
import eu.dnetlib.test.utils.EPRTestUtil; |
|
15 |
|
|
16 |
/** |
|
17 |
* Common tests for resource state subscription registry tests. |
|
18 |
* |
|
19 |
* @author marko |
|
20 |
* |
|
21 |
*/ |
|
22 |
public abstract class AbstractResourceStateSubscriptionRegistryTest { |
|
23 |
|
|
24 |
/** |
|
25 |
* star. |
|
26 |
*/ |
|
27 |
private static final String STAR = "*"; |
|
28 |
|
|
29 |
/** |
|
30 |
* create topic prefix. |
|
31 |
*/ |
|
32 |
private static final String CREATE = "CREATE"; |
|
33 |
|
|
34 |
/** |
|
35 |
* test resource type. |
|
36 |
*/ |
|
37 |
private static final String SOME_TYPE = "someType"; |
|
38 |
|
|
39 |
/** |
|
40 |
* test other resource type. |
|
41 |
*/ |
|
42 |
private static final String SOME_OTHER_TYPE = "someOtherType"; |
|
43 |
|
|
44 |
/** |
|
45 |
* test resource id. |
|
46 |
*/ |
|
47 |
private static final String SOME_ID = "sub123"; |
|
48 |
|
|
49 |
/** |
|
50 |
* instance under test. |
|
51 |
*/ |
|
52 |
private ResourceStateSubscriptionRegistry registry; |
|
53 |
|
|
54 |
/** |
|
55 |
* test subscritpion request. |
|
56 |
*/ |
|
57 |
private transient SubscriptionRequest sub; |
|
58 |
|
|
59 |
/** |
|
60 |
* setup registry. subclasses should set the dao. |
|
61 |
*/ |
|
62 |
@Before |
|
63 |
public void setUpRegistry() { |
|
64 |
registry = new ResourceStateSubscriptionRegistry(); |
|
65 |
|
|
66 |
final SubscriptionRequestFilter filter = new SubscriptionRequestFilter(); |
|
67 |
filter.setActive(true); |
|
68 |
registry.setSubscriptionRequestFilter(filter); |
|
69 |
|
|
70 |
setUpDao(); |
|
71 |
|
|
72 |
sub = new SubscriptionRequest(SOME_ID, EPRTestUtil.getTestEpr(), "CREATE/*/*/someXpath", 0); |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* test subscription registration. |
|
77 |
* |
|
78 |
* @throws SubscriptionRequestRejectedException |
|
79 |
*/ |
|
80 |
@Test |
|
81 |
public void testRegisterSubscription() throws SubscriptionRequestRejectedException { |
|
82 |
registry.registerSubscription(sub); |
|
83 |
|
|
84 |
final Collection<ResourceStateSubscription> res = registry.listMatchingSubscriptions(CREATE, STAR, STAR); |
|
85 |
for (final ResourceStateSubscription r : res) { |
|
86 |
assertEquals("check add subscription", SOME_ID, r.getSubscriptionId()); |
|
87 |
} |
|
88 |
|
|
89 |
assertEquals("check that is really added", 1, res.size()); |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* test match. |
|
94 |
* |
|
95 |
* @throws SubscriptionRequestRejectedException |
|
96 |
*/ |
|
97 |
@Test |
|
98 |
public void testMatch() throws SubscriptionRequestRejectedException { |
|
99 |
registry.registerSubscription(sub); |
|
100 |
|
|
101 |
ResourceStateSubscription re1 = null; // NOPMD |
|
102 |
ResourceStateSubscription re2 = null; // NOPMD |
|
103 |
|
|
104 |
final Collection<ResourceStateSubscription> res = registry.listMatchingSubscriptions(CREATE, SOME_TYPE, STAR); |
|
105 |
for (final ResourceStateSubscription r : res) { |
|
106 |
re1 = r; // NOPMD |
|
107 |
assertEquals("check match subscription", SOME_ID, r.getSubscriptionId()); |
|
108 |
} |
|
109 |
|
|
110 |
assertEquals("check that only one matched", 1, res.size()); |
|
111 |
|
|
112 |
final Collection<ResourceStateSubscription> res2 = registry.listMatchingSubscriptions(CREATE, SOME_OTHER_TYPE, STAR); |
|
113 |
for (final ResourceStateSubscription r : res2) { |
|
114 |
re2 = r; // NOPMD |
|
115 |
assertEquals("check match subscription", SOME_ID, r.getSubscriptionId()); |
|
116 |
} |
|
117 |
|
|
118 |
assertEquals("check that only one matched", 1, res2.size()); |
|
119 |
assertEquals("check that the same subscription is returned", re1, re2); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* multiple subscriptions should be registered only once. |
|
124 |
* |
|
125 |
* @throws SubscriptionRequestRejectedException |
|
126 |
*/ |
|
127 |
@Test |
|
128 |
public void testMultiple() throws SubscriptionRequestRejectedException { |
|
129 |
final String subId = registry.registerSubscription(sub); |
|
130 |
final String subId2 = registry.registerSubscription(sub); |
|
131 |
|
|
132 |
assertEquals("avoid duplicates", subId, subId2); |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* test unsubscribe. |
|
137 |
* |
|
138 |
* @throws SubscriptionRequestRejectedException |
|
139 |
*/ |
|
140 |
@Test |
|
141 |
public void testUnsubscribe() throws SubscriptionRequestRejectedException { |
|
142 |
final String subId = registry.registerSubscription(sub); |
|
143 |
final boolean res = registry.unsubscribe(subId); |
|
144 |
|
|
145 |
assertTrue("unsubscribed", res); |
|
146 |
|
|
147 |
final boolean res2 = registry.unsubscribe(subId); |
|
148 |
|
|
149 |
assertFalse("not unsubscribed", res2); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* subclasses should implement this with a specific instance of the dao. |
|
154 |
*/ |
|
155 |
protected abstract void setUpDao(); |
Also available in: Unified diff
new branch for solr 772 integration