1
|
package eu.dnetlib.enabling.tools.registration;
|
2
|
|
3
|
import static org.junit.Assert.assertEquals;
|
4
|
import static org.mockito.Matchers.anyObject;
|
5
|
import static org.mockito.Matchers.anyString;
|
6
|
import static org.mockito.Mockito.when;
|
7
|
|
8
|
import javax.xml.ws.Endpoint;
|
9
|
|
10
|
import org.junit.Before;
|
11
|
import org.junit.Ignore;
|
12
|
import org.junit.Test;
|
13
|
import org.junit.runner.RunWith;
|
14
|
import org.mockito.Mock;
|
15
|
import org.mockito.junit.MockitoJUnitRunner;
|
16
|
|
17
|
import eu.dnetlib.enabling.is.lookup.ISLookUpServiceImpl;
|
18
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
19
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
20
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
21
|
|
22
|
/**
|
23
|
* test ServiceRegistrationManagerImpl.
|
24
|
*
|
25
|
* @author marko
|
26
|
*
|
27
|
*/
|
28
|
@RunWith(MockitoJUnitRunner.class)
|
29
|
public class ServiceRegistrationManagerImplTest {
|
30
|
|
31
|
/**
|
32
|
* fake profile.
|
33
|
*/
|
34
|
private static final String PROFILE = "<RESOURCE_PROFILE><HEADER><RESOURCE_KIND value=\"PendingServiceResources\"/></HEADER></RESOURCE_PROFILE>";
|
35
|
|
36
|
/**
|
37
|
* instance under test.
|
38
|
*/
|
39
|
private transient ServiceRegistrationManagerImpl manager;
|
40
|
|
41
|
/**
|
42
|
* registrator mock.
|
43
|
*/
|
44
|
@Mock
|
45
|
private transient ServiceRegistrator registrator;
|
46
|
|
47
|
/**
|
48
|
* is lookup mock.
|
49
|
*/
|
50
|
@Mock
|
51
|
private transient ISLookUpService lookUpService;
|
52
|
@Mock
|
53
|
private UniqueServiceLocator serviceLocator;
|
54
|
|
55
|
/**
|
56
|
* prepare.
|
57
|
*
|
58
|
* @throws ISLookUpException
|
59
|
* cannot happen
|
60
|
*/
|
61
|
@Before
|
62
|
public void setUp() throws ISLookUpException {
|
63
|
manager = new ServiceRegistrationManagerImpl();
|
64
|
manager.setServiceLocator(serviceLocator);
|
65
|
manager.setRegistrator(registrator);
|
66
|
manager.setService(new ISLookUpServiceImpl());
|
67
|
|
68
|
when(serviceLocator.getService(ISLookUpService.class)).thenReturn(lookUpService);
|
69
|
when(serviceLocator.getService(ISLookUpService.class, true)).thenReturn(lookUpService);
|
70
|
when(lookUpService.getResourceProfile("123")).thenReturn(PROFILE);
|
71
|
when(lookUpService.getResourceProfileByQuery(anyString())).thenReturn(PROFILE);
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* test state machine.
|
76
|
*/
|
77
|
@Test
|
78
|
@Ignore
|
79
|
public void testTick() {
|
80
|
when(registrator.registerService(anyObject(), (Endpoint) anyObject())).thenReturn("123");
|
81
|
|
82
|
assertEquals("check unregistered state", ServiceRegistrationManagerImpl.State.UNREGISTERED, manager.getState());
|
83
|
manager.tick();
|
84
|
assertEquals("check pending state", ServiceRegistrationManagerImpl.State.PENDING, manager.getState());
|
85
|
assertEquals("ensure that the mock is correct", "PendingServiceResources", manager.getServiceProfile().getResourceKind());
|
86
|
manager.tick();
|
87
|
assertEquals("should remain pending", ServiceRegistrationManagerImpl.State.PENDING, manager.getState());
|
88
|
|
89
|
manager.tick();
|
90
|
assertEquals("should remain pending forever", ServiceRegistrationManagerImpl.State.PENDING, manager.getState());
|
91
|
}
|
92
|
|
93
|
}
|