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.Matchers.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
|
}
|