Project

General

Profile

1
package eu.dnetlib.enabling.tools.registration;
2

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

    
8
import javax.xml.namespace.QName;
9

    
10
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
11
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
12
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
13
import org.apache.cxf.endpoint.Endpoint;
14
import org.apache.cxf.endpoint.ServerImpl;
15
import org.apache.cxf.jaxws.EndpointImpl;
16
import org.apache.cxf.service.Service;
17
import org.apache.cxf.service.model.EndpointInfo;
18

    
19
import org.junit.Before;
20
import org.junit.Test;
21
import org.junit.Ignore;
22
import org.junit.runner.RunWith;
23
import org.mockito.Mock;
24
import org.mockito.junit.MockitoJUnitRunner;
25

    
26
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
27
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
28
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
29
import eu.dnetlib.enabling.tools.HNMLocator;
30
import eu.dnetlib.soap.cxf.CxfEndpointReferenceBuilder;
31
import eu.dnetlib.soap.cxf.JaxwsEndpointReferenceBuilder;
32

    
33
/**
34
 * ServiceRegistrator test.
35
 *
36
 * @author marko
37
 *
38
 */
39
@RunWith(MockitoJUnitRunner.class)
40
public class ServiceRegistratorTest {
41
	/**
42
	 * instance under test.
43
	 */
44
	private transient ServiceRegistrator registrator;
45

    
46
	/**
47
	 * service mock.
48
	 */
49
	@Mock
50
	private transient Service service;
51

    
52
	/**
53
	 * endpoint info mock.
54
	 */
55
	@Mock
56
	private transient EndpointInfo endpointInfo;
57

    
58
	/**
59
	 * endpoint mock.
60
	 */
61
	@Mock
62
	private transient Endpoint endpoint;
63

    
64
	/**
65
	 * registry service mock.
66
	 */
67
	@Mock
68
	private transient ISRegistryService registryService;
69

    
70
	/**
71
	 * isLookup service mock.
72
	 */
73
	@Mock
74
	private transient ISLookUpService isLookUpService;
75

    
76
	/**
77
	 * jaxws endpoint mock.
78
	 */
79
	@Mock
80
	private transient EndpointImpl jaxwsEndpoint;
81

    
82
	/**
83
	 * cxf server mock.
84
	 */
85
	@Mock
86
	private transient ServerImpl server;
87

    
88
	/**
89
	 * hnm locator mock.
90
	 */
91
	@Mock
92
	private transient HNMLocator hnmLocator;
93
	@Mock
94
	private UniqueServiceLocator serviceLocator;
95

    
96
	/**
97
	 * setup common stuff.
98
	 *
99
	 */
100
    @Before
101
	public void disabled() throws ISLookUpException {
102
	     final String service = "TestService";
103
	     when(this.service.getName()).thenReturn(new QName("http://my.test", service));
104

    
105
		when(endpoint.getEndpointInfo()).thenReturn(endpointInfo);
106
		when(endpoint.getService()).thenReturn(this.service);
107
		when(endpointInfo.getAddress()).thenReturn("http://localhost/something");
108
		when(endpointInfo.getName()).thenReturn(new QName("http://my.test", "TestServiceEndpoint"));
109

    
110
		when(jaxwsEndpoint.getServer()).thenReturn(server);
111
		when(server.getEndpoint()).thenReturn(endpoint);
112

    
113
		when(hnmLocator.getHNMForUrl("http://localhost/something")).thenReturn("555444");
114

    
115
	    // serviceLocator.getService(ISLookUpService.class).getResourceTypeSchema(serviceName);
116

    
117
	    when(isLookUpService.getResourceTypeSchema(service)).thenThrow(ISLookUpDocumentNotFoundException.class);
118

    
119
	    when(serviceLocator.getService(ISLookUpService.class)).thenReturn(isLookUpService);
120
		when(serviceLocator.getService(ISRegistryService.class, true)).thenReturn(registryService);
121
		
122
		
123
		registrator = new ServiceRegistrator();
124
		registrator.setServiceLocator(serviceLocator);
125

    
126
		final CxfEndpointReferenceBuilder cxfEprBuilder = new CxfEndpointReferenceBuilder();
127

    
128
		final JaxwsEndpointReferenceBuilder eprBuilder = new JaxwsEndpointReferenceBuilder();
129
		eprBuilder.setBuilder(cxfEprBuilder);
130

    
131
		registrator.setEprBuilder(eprBuilder);
132
		registrator.setHnmLocator(hnmLocator);
133
	}
134

    
135
	/**
136
	 * test register service.
137
	 * @throws ISRegistryException shouldn't happen
138
	 */
139
	@Test
140
    //@Ignore
141
	public void testRegisterService() throws ISRegistryException {
142
		when(registryService.insertProfileForValidation(eq("TestServiceResourceType"), anyString())).thenReturn("123");
143

    
144
		final String rsId = registrator.registerService("TestService", jaxwsEndpoint);
145
		assertEquals("registered", "123", rsId);
146
	}
147

    
148
}
(4-4/5)