1
|
package eu.dnetlib.enabling.is.registry;
|
2
|
|
3
|
import javax.xml.xpath.XPathExpressionException;
|
4
|
|
5
|
import eu.dnetlib.enabling.is.registry.schema.ValidationException;
|
6
|
import eu.dnetlib.enabling.is.registry.validation.ProfileValidationStrategy;
|
7
|
import eu.dnetlib.enabling.tools.OpaqueResource;
|
8
|
import eu.dnetlib.rmi.enabling.ISRegistryException;
|
9
|
import eu.dnetlib.rmi.enabling.ISRegistryService;
|
10
|
import org.junit.Before;
|
11
|
import org.junit.Test;
|
12
|
import org.junit.runner.RunWith;
|
13
|
import org.mockito.Mock;
|
14
|
import org.mockito.junit.MockitoJUnitRunner;
|
15
|
|
16
|
import static org.junit.Assert.*;
|
17
|
import static org.mockito.ArgumentMatchers.anyString;
|
18
|
import static org.mockito.Mockito.verify;
|
19
|
import static org.mockito.Mockito.when;
|
20
|
|
21
|
/**
|
22
|
* test compatibility pending resource manager implementation.
|
23
|
*
|
24
|
* @author marko
|
25
|
*
|
26
|
*/
|
27
|
@RunWith(MockitoJUnitRunner.class)
|
28
|
public class CompatPendingResourceManagerImplTest {
|
29
|
|
30
|
/**
|
31
|
* instance under test.
|
32
|
*/
|
33
|
private transient CompatPendingResourceManagerImpl pendingManager;
|
34
|
|
35
|
/**
|
36
|
* registry service mock.
|
37
|
*/
|
38
|
@Mock
|
39
|
private transient ISRegistryService registryService;
|
40
|
|
41
|
/**
|
42
|
* resource mock.
|
43
|
*/
|
44
|
@Mock
|
45
|
private transient OpaqueResource resource;
|
46
|
/**
|
47
|
* used to validate resources w.r.t. a set of defined properties.
|
48
|
*/
|
49
|
@Mock
|
50
|
private ProfileValidationStrategy profileValidationStrategy;
|
51
|
|
52
|
/**
|
53
|
* prepare instance for testing.
|
54
|
*/
|
55
|
@Before
|
56
|
public void setUp() {
|
57
|
pendingManager = new CompatPendingResourceManagerImpl();
|
58
|
pendingManager.setIsRegistry(registryService);
|
59
|
pendingManager.setResourceKindResolver(new ApplicationProfileResourceKindResolver());
|
60
|
pendingManager.setProfileValidationStrategy(profileValidationStrategy);
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* test that the application profile can be queried correctly.
|
65
|
*
|
66
|
* @throws XPathExpressionException
|
67
|
* shouldn't happen
|
68
|
*/
|
69
|
@Test
|
70
|
public void testGetPendingKindForType() throws XPathExpressionException {
|
71
|
assertEquals("check pending", "PendingRepositoryResources", pendingManager.getPendingKindForType("RepositoryServiceResourceType"));
|
72
|
assertEquals("check pending", "PendingDSResources", pendingManager.getPendingKindForType("UserDSResourceType"));
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* check that unexistent types throw an exception.
|
77
|
*
|
78
|
* @throws XPathExpressionException
|
79
|
* shouldn't happen
|
80
|
*/
|
81
|
@Test(expected = IllegalStateException.class)
|
82
|
public void testGetPendingKindForNoSuchType() throws XPathExpressionException {
|
83
|
pendingManager.getPendingKindForType("NoSuchType");
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* test that the application profile can be queried correctly.
|
88
|
*
|
89
|
* @throws XPathExpressionException
|
90
|
* shouldn't happen
|
91
|
*/
|
92
|
@Test
|
93
|
public void testGetNormalKindForType() throws XPathExpressionException {
|
94
|
assertEquals("check kind", "RepositoryServiceResources", pendingManager.getNormalKindForType("RepositoryServiceResourceType"));
|
95
|
assertEquals("check kind", "UserDSResources", pendingManager.getNormalKindForType("UserDSResourceType"));
|
96
|
assertNull("check unexisting type", pendingManager.getNormalKindForType("NoSuchType"));
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* test that the resource is correctly moved from the pending collection to the new collection.
|
101
|
*
|
102
|
* @throws ISRegistryException
|
103
|
* shoudn't happen
|
104
|
* @throws ValidationException
|
105
|
*/
|
106
|
@Test
|
107
|
public void testSetValid() throws ISRegistryException, ValidationException {
|
108
|
final String profId = "123";
|
109
|
when(resource.asString()).thenReturn("");
|
110
|
when(resource.getResourceId()).thenReturn(profId);
|
111
|
|
112
|
pendingManager.setValid(resource);
|
113
|
|
114
|
verify(registryService).deleteProfile(profId);
|
115
|
verify(registryService).registerProfile(anyString());
|
116
|
|
117
|
assertNotNull("dummy", registryService);
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* test that the resource is correctly moved from the current collection to the correct pending collection.
|
122
|
*
|
123
|
* @throws ISRegistryException
|
124
|
* shoudn't happen
|
125
|
*/
|
126
|
@Test
|
127
|
public void testSetPending() throws ISRegistryException {
|
128
|
final String profId = "321";
|
129
|
when(resource.asString()).thenReturn("");
|
130
|
when(resource.getResourceId()).thenReturn(profId);
|
131
|
when(resource.getResourceType()).thenReturn("RepositoryServiceResourceType");
|
132
|
|
133
|
pendingManager.setPending(resource);
|
134
|
|
135
|
verify(registryService).deleteProfile(profId);
|
136
|
verify(registryService).registerProfile(anyString());
|
137
|
|
138
|
assertNotNull("dummy", registryService);
|
139
|
}
|
140
|
|
141
|
}
|