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.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 ValidatingServiceRegistrationManagerImpl.
|
24
|
*
|
25
|
* @author marko
|
26
|
*
|
27
|
*/
|
28
|
@RunWith(MockitoJUnitRunner.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), any(Endpoint.class))).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
|
}
|