Project

General

Profile

« Previous | Next » 

Revision 45125

codebase used to migrate to java8 the production system

View differences:

modules/cnr-enabling-services/trunk/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-enabling-services/trunk/", "deploy_repository": "dnet4-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/dnet4-snapshots", "name": "cnr-enabling-services"}
modules/cnr-enabling-services/trunk/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/trunk/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/trunk/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/trunk/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/trunk/src/test/java/eu/dnetlib/enabling/tools/registration/ServiceRegistratorTest.java
1
package eu.dnetlib.enabling.tools.registration;
2

  
3

  
4
import static org.junit.Assert.assertEquals;
5
import static org.mockito.Mockito.when;
6
import static org.mockito.Matchers.anyString;
7
import static org.mockito.Matchers.eq;
8

  
9
import javax.xml.namespace.QName;
10

  
11
import org.apache.cxf.endpoint.Endpoint;
12
import org.apache.cxf.endpoint.ServerImpl;
13
import org.apache.cxf.jaxws.EndpointImpl;
14
import org.apache.cxf.service.Service;
15
import org.apache.cxf.service.model.EndpointInfo;
16
//import org.junit.Before;
17
import org.junit.Test;
18
import org.junit.Ignore;
19
import org.junit.runner.RunWith;
20
import org.mockito.Mock;
21
import org.mockito.runners.MockitoJUnit44Runner;
22

  
23
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
24
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
25
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
26
import eu.dnetlib.enabling.tools.HNMLocator;
27
import eu.dnetlib.soap.cxf.CxfEndpointReferenceBuilder;
28
import eu.dnetlib.soap.cxf.JaxwsEndpointReferenceBuilder;
29

  
30
/**
31
 * ServiceRegistrator test.
32
 *
33
 * @author marko
34
 *
35
 */
36
@RunWith(MockitoJUnit44Runner.class)
37
public class ServiceRegistratorTest {
38
	/**
39
	 * instance under test.
40
	 */
41
	private transient ServiceRegistrator registrator;
42

  
43
	/**
44
	 * service mock.
45
	 */
46
	@Mock
47
	private transient Service service;
48

  
49
	/**
50
	 * endpoint info mock.
51
	 */
52
	@Mock
53
	private transient EndpointInfo endpointInfo;
54

  
55
	/**
56
	 * endpoint mock.
57
	 */
58
	@Mock
59
	private transient Endpoint endpoint;
60

  
61
	/**
62
	 * registry service mock.
63
	 */
64
	@Mock
65
	private transient ISRegistryService registryService;
66

  
67
	/**
68
	 * jaxws endpoint mock.
69
	 */
70
	@Mock
71
	private transient EndpointImpl jaxwsEndpoint;
72

  
73
	/**
74
	 * cxf server mock.
75
	 */
76
	@Mock
77
	private transient ServerImpl server;
78

  
79
	/**
80
	 * hnm locator mock.
81
	 */
82
	@Mock
83
	private transient HNMLocator hnmLocator;
84
	@Mock
85
	private UniqueServiceLocator serviceLocator;
86

  
87
	/**
88
	 * setup common stuff.
89
	 *
90
	 */
91
        //@Before
92
	public void disabled() {
93
		when(service.getName()).thenReturn(new QName("http://my.test", "TestService"));
94

  
95
		when(endpoint.getEndpointInfo()).thenReturn(endpointInfo);
96
		when(endpoint.getService()).thenReturn(service);
97
		when(endpointInfo.getAddress()).thenReturn("http://localhost/something");
98
		when(endpointInfo.getName()).thenReturn(new QName("http://my.test", "TestServiceEndpoint"));
99

  
100
		when(jaxwsEndpoint.getServer()).thenReturn(server);
101
		when(server.getEndpoint()).thenReturn(endpoint);
102

  
103
		when(hnmLocator.getHNMForUrl("http://localhost/something")).thenReturn("555444");
104

  
105
		when(serviceLocator.getService(ISRegistryService.class)).thenReturn(registryService);
106
		when(serviceLocator.getService(ISRegistryService.class, true)).thenReturn(registryService);
107
		
108
		
109
		registrator = new ServiceRegistrator();
110
		registrator.setServiceLocator(serviceLocator);
111

  
112
		final CxfEndpointReferenceBuilder cxfEprBuilder = new CxfEndpointReferenceBuilder();
113

  
114
		final JaxwsEndpointReferenceBuilder eprBuilder = new JaxwsEndpointReferenceBuilder();
115
		eprBuilder.setBuilder(cxfEprBuilder);
116

  
117
		registrator.setEprBuilder(eprBuilder);
118
		registrator.setHnmLocator(hnmLocator);
119
	}
120

  
121
	/**
122
	 * test register service.
123
	 * @throws ISRegistryException shouldn't happen
124
	 */
125
	@Test
126
        @Ignore
127
	public void testRegisterService() throws ISRegistryException {
128
		when(registryService.insertProfileForValidation(eq("TestServiceResourceType"), anyString())).thenReturn("123");
129

  
130
		final String rsId = registrator.registerService("TestService", jaxwsEndpoint);
131
		assertEquals("registered", "123", rsId);
132
	}
133

  
134
}
modules/cnr-enabling-services/trunk/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.runners.MockitoJUnit44Runner;
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(MockitoJUnit44Runner.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/trunk/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.runners.MockitoJUnit44Runner;
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(MockitoJUnit44Runner.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/trunk/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.runners.MockitoJUnit44Runner;
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(MockitoJUnit44Runner.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), (Endpoint) anyObject())).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/trunk/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/trunk/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/trunk/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
import org.mockito.runners.MockitoJUnit44Runner;
18

  
19
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscription;
20
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscriptionRegistry;
21
import eu.dnetlib.enabling.tools.OpaqueResource;
22

  
23
/**
24
 * Test the default notification detector implementation.
25
 *
26
 * @author marko
27
 *
28
 */
29
@RunWith(MockitoJUnit44Runner.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 extends 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 Object argument) {
71
			final NotificationMessage message = (NotificationMessage) argument;
72
			return message.getSubscriptionId() == subscription.getSubscriptionId() && message.getResourceId().equals("123")
73
					&& message.getTopic().equals(prefix + ".*.*");
74
		}
75
	}
76

  
77
	/**
78
	 * instance under test.
79
	 */
80
	private transient NotificationDetectorImpl detector;
81

  
82
	/**
83
	 * registry mock.
84
	 */
85
	@Mock
86
	private transient ResourceStateSubscriptionRegistry registry;
87

  
88
	/**
89
	 * sender mock.
90
	 */
91
	@Mock
92
	private transient NotificationSender sender;
93

  
94
	/**
95
	 * resource mock.
96
	 */
97
	@Mock
98
	private transient OpaqueResource resource;
99

  
100
	/**
101
	 * resource subscription.
102
	 */
103
	@Mock
104
	private transient ResourceStateSubscription subscription;
105

  
106
	/**
107
	 * mock subscriber.
108
	 */
109
	private transient W3CEndpointReference subscriber;
110

  
111
	/**
112
	 * common.
113
	 */
114
	@Before
115
	public void setUp() {
116
		detector = new NotificationDetectorImpl();
117

  
118
		detector.setRegistry(registry);
119

  
120
		detector.setSender(sender);
121

  
122
		final W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
123
		builder.address("http://test.com/test/test");
124
		subscriber = builder.build();
125

  
126
		final List<ResourceStateSubscription> subscriptions = new ArrayList<ResourceStateSubscription>();
127
		subscriptions.add(subscription);
128
		when(registry.listMatchingSubscriptions(ResourceStateSubscription.PREFIX_CREATE, SOME_TYPE, SOME_ID)).thenReturn(subscriptions);
129
		when(registry.listMatchingSubscriptions(ResourceStateSubscription.PREFIX_DELETE, SOME_TYPE, SOME_ID)).thenReturn(subscriptions);
130
		when(registry.listMatchingSubscriptions(ResourceStateSubscription.PREFIX_UPDATE, SOME_TYPE, SOME_ID)).thenReturn(subscriptions);
131

  
132
		when(resource.getResourceId()).thenReturn(SOME_ID);
133
		when(resource.getResourceType()).thenReturn(SOME_TYPE);
134

  
135
		when(subscription.getSubscriptionId()).thenReturn("sn123");
136
		when(subscription.getSubscriberAsEpr()).thenReturn(subscriber);
137
		when(subscription.getXpath()).thenReturn("");
138
		when(subscription.getType()).thenReturn("*");
139
		when(subscription.getResourceId()).thenReturn("*");
140
	}
141

  
142
	/**
143
	 * test 'create'.
144
	 */
145
	@Test
146
	public void testResourceCreated() {
147
		when(subscription.getPrefix()).thenReturn(ResourceStateSubscription.PREFIX_CREATE);
148

  
149
		detector.resourceCreated(resource);
150

  
151
		verify(sender).send(eq(subscriber), argThat(new CheckMessage(ResourceStateSubscription.PREFIX_CREATE)));
152

  
153
		assertNotNull("dummy", sender);
154
	}
155

  
156
	/**
157
	 * test 'delete'.
158
	 */
159
	@Test
160
	public void testResourceDeleted() {
161
		when(subscription.getPrefix()).thenReturn(ResourceStateSubscription.PREFIX_DELETE);
162

  
163
		detector.resourceDeleted(resource);
164

  
165
		verify(sender).send(eq(subscriber), argThat(new CheckMessage(ResourceStateSubscription.PREFIX_DELETE)));
166

  
167
		assertNotNull("dummy", sender);
168
	}
169

  
170
	/**
171
	 * test 'update'.
172
	 */
173
	@Test
174
	public void testResourceUpdated() {
175
		when(subscription.getXpath()).thenReturn(null);
176
		when(subscription.getPrefix()).thenReturn(ResourceStateSubscription.PREFIX_UPDATE);
177

  
178
		detector.resourceUpdated(resource, resource);
179

  
180
		verify(sender).send(eq(subscriber), argThat(new CheckMessage(ResourceStateSubscription.PREFIX_UPDATE)));
181

  
182
		assertNotNull("dummy", sender);
183

  
184
	}
185

  
186
}
modules/cnr-enabling-services/trunk/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/trunk/src/test/java/eu/dnetlib/enabling/is/sn/resourcestate/hib/HibernateResourceStateSubscriptionDAOImplTest.java
1
package eu.dnetlib.enabling.is.sn.resourcestate.hib;
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 javax.annotation.Resource;
10

  
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.junit.After;
14
import org.junit.Test;
15
import org.junit.runner.RunWith;
16
import org.springframework.dao.DataIntegrityViolationException;
17
import org.springframework.test.annotation.DirtiesContext;
18
import org.springframework.test.context.ContextConfiguration;
19
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
20

  
21
import eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionDAOImplTest;
22
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscription;
23
import eu.dnetlib.test.utils.EPRTestUtil;
24

  
25
/**
26
 * test HibernateResourceStateSubscriptionDAOImplTest.
27
 * 
28
 * @author marko
29
 * 
30
 */
31
@RunWith(SpringJUnit4ClassRunner.class)
32
@ContextConfiguration
33
public class HibernateResourceStateSubscriptionDAOImplTest extends AbstractResourceStateSubscriptionDAOImplTest {
34
	/**
35
	 * logger.
36
	 */
37
	private static final Log log = LogFactory.getLog(HibernateResourceStateSubscriptionDAOImplTest.class); // NOPMD by marko on 11/24/08 5:02 PM
38

  
39
	/**
40
	 * instance under test.
41
	 */
42
	@Resource
43
	private transient HibernateResourceStateSubscriptionDAOImpl hibdao;
44

  
45
	/**
46
	 * cleanup db.
47
	 */
48
	@After
49
	public void tearDown() {
50
		final Collection<ResourceStateSubscription> subs = hibdao.listSubscriptions();
51
		if (subs != null)
52
			for (ResourceStateSubscription r : subs)
53
				hibdao.removeSubscription(r.getSubscriptionId());
54
		
55
//		for (ResourceStateSubscription r : subs)
56
//			log.info("deleted: " + r);
57
	}
58

  
59
	/**
60
	 * test addition.
61
	 */
62
	@Test
63
	public void testAddSubscription() {
64
		assertNotNull("check dao", getDao());
65

  
66
		getDao().addSubscription(getSub());
67

  
68
		log.info("sub id: " + getSub().getSubscriptionId());
69
	}
70

  
71
	/**
72
	 * test encoding of endpoint references.
73
	 */
74
	@Test
75
	@DirtiesContext
76
	public void testEndpoint() {
77
		getSub().setSubscriber(EPRTestUtil.getTestEpr());
78

  
79
		getDao().addSubscription(getSub());
80

  
81
		final ResourceStateSubscription fresh = getDao().getSubscription(getSub().getSubscriptionId());
82

  
83
		assertNotNull("check", fresh);
84
		assertTrue("equals", compare(getSub(), fresh));
85

  
86
		assertNotNull("epr", getSub().getSubscriber());
87
		assertNotNull("fetched epr", fresh.getSubscriber());
88

  
89
		assertEquals("eprs", getSub().getSubscriber().toString(), fresh.getSubscriber().toString());
90
	}
91

  
92
	/**
93
	 * multiple subscriptions should not be allowed.
94
	 */
95
	@Test(expected = DataIntegrityViolationException.class)
96
	@DirtiesContext
97
	public void testMultiple() { // NOPMD
98
		getDao().addSubscription(getSub());
99
		getDao().addSubscription(getSub());
100
	}
101

  
102
	
103
	/**
104
	 * {@inheritDoc}
105
	 * 
106
	 * @see eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionDAOImplTest#prepareDao()
107
	 */
108
	@Override
109
	protected void prepareDao() {
110
		setDao(hibdao);
111
	}
112

  
113
}
modules/cnr-enabling-services/trunk/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/trunk/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.runners.MockitoJUnit44Runner;
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(MockitoJUnit44Runner.class)
25
public class ResourceStateSubscriptionRegistryTest {
26

  
27
	/**
28
	 * matches.
29
	 * 
30
	 * @author marko
31
	 *
32
	 */
33
	public static class MatchSubscription extends 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 Object argument) {
74
			final ResourceStateSubscription sub = (ResourceStateSubscription) argument;
75
			return sub.getPrefix().equals(this.prefix) && sub.getType().equals(this.type) && sub.getResourceId().equals(this.resId);
76
		}
77

  
78
	}
79

  
80
	/**
81
	 * object under test.
82
	 */
83
	private transient ResourceStateSubscriptionRegistry registry;
84

  
85
	/**
86
	 * DAO mock.
87
	 */
88
	@Mock
89
	private transient ResourceStateSubscriptionDAO subscriptionDao;
90

  
91
	/**
92
	 * subscription request.
93
	 */
94
	private transient SubscriptionRequest sub;
95

  
96
	/**
97
	 * common setup.
98
	 */
99
	@Before
100
	public void setUp() {
101
		registry = new ResourceStateSubscriptionRegistry();
102
		registry.setSubscriptionDao(subscriptionDao);
103

  
104
		final SubscriptionRequestFilter filter = new SubscriptionRequestFilter();
105
		filter.setActive(true);
106
		registry.setSubscriptionRequestFilter(filter);
107

  
108
		sub = new SubscriptionRequest();
109
	}
110

  
111
	/**
112
	 * test registration.
113
	 * 
114
	 * @throws SubscriptionRequestRejectedException
115
	 */
116
	@Test
117
	public void testRegisterSubscription() throws SubscriptionRequestRejectedException {
118
		sub.setTopicExpression("CREATE/MyResourceType/123/some/path");
119
		registry.registerSubscription(sub);
120
		verify(subscriptionDao).addSubscription(argThat(new MatchSubscription("CREATE", "MyResourceType", "123")));
121

  
122
		assertNotNull("dummy", subscriptionDao);
123
	}
124

  
125
	/**
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff