1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest.registry; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
import static org.mockito.Mockito.mock; |
38 |
|
|
39 |
|
import info.magnolia.context.MgnlContext; |
40 |
|
import info.magnolia.event.RecordingEventBus; |
41 |
|
import info.magnolia.jcr.util.NodeTypes; |
42 |
|
import info.magnolia.jcr.util.NodeUtil; |
43 |
|
import info.magnolia.module.ModuleRegistry; |
44 |
|
import info.magnolia.registry.RegistrationException; |
45 |
|
import info.magnolia.repository.RepositoryConstants; |
46 |
|
import info.magnolia.rest.EndpointDefinition; |
47 |
|
import info.magnolia.test.RepositoryTestCase; |
48 |
|
|
49 |
|
import java.util.ArrayList; |
50 |
|
import java.util.List; |
51 |
|
|
52 |
|
import javax.jcr.Node; |
53 |
|
import javax.jcr.RepositoryException; |
54 |
|
import javax.jcr.Session; |
55 |
|
|
56 |
|
import org.junit.Before; |
57 |
|
import org.junit.Test; |
58 |
|
|
59 |
|
|
60 |
|
@link |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (54) |
Complexity: 5 |
Complexity Density: 0.1 |
|
62 |
|
public class ConfiguredEndpointDefinitionManagerTest extends RepositoryTestCase { |
63 |
|
|
64 |
|
private ConfiguredEndpointDefinitionManager configuredEndpointDefinitionManager; |
65 |
|
private EndpointDefinitionRegistry endpointDefinitionRegistry; |
66 |
|
private Session configSession; |
67 |
|
private List<Node> nodes; |
68 |
|
private RecordingEventBus eventBus; |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
|
70 |
4 |
@Before... |
71 |
|
public void setUp() throws Exception { |
72 |
4 |
super.setUp(); |
73 |
|
|
74 |
4 |
configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
75 |
|
|
76 |
4 |
ModuleRegistry moduleRegistry = mock(ModuleRegistry.class); |
77 |
|
|
78 |
4 |
eventBus = new RecordingEventBus(); |
79 |
4 |
endpointDefinitionRegistry = new EndpointDefinitionRegistry(eventBus); |
80 |
4 |
configuredEndpointDefinitionManager = new ConfiguredEndpointDefinitionManager(moduleRegistry, endpointDefinitionRegistry); |
81 |
|
|
82 |
4 |
final Node testEndpointNode = NodeUtil.createPath(configSession.getRootNode(), "/modules/test/rest-endpoints", NodeTypes.ContentNode.NAME); |
83 |
4 |
final Node testEndpoint = NodeUtil.createPath(testEndpointNode, "/test", NodeTypes.ContentNode.NAME); |
84 |
4 |
testEndpoint.setProperty("enabled", true); |
85 |
4 |
testEndpoint.setProperty("class", ConfiguredEndpointDefinition.class.getName()); |
86 |
4 |
testEndpoint.setProperty("implementationClass", TestEndpoint.class.getName()); |
87 |
4 |
configSession.save(); |
88 |
|
|
89 |
4 |
nodes = new ArrayList<Node>(); |
90 |
4 |
nodes.add(testEndpointNode); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
93 |
1 |
@Test... |
94 |
|
public void testGetEndpointDefinition() throws RepositoryException, RegistrationException { |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
1 |
configuredEndpointDefinitionManager.reload(nodes); |
99 |
|
|
100 |
|
|
101 |
1 |
EndpointDefinition endpointDefinition = endpointDefinitionRegistry.getEndpointDefinition("test"); |
102 |
|
|
103 |
1 |
assertEquals("test", endpointDefinition.getName()); |
104 |
1 |
assertEquals(TestEndpoint.class.getName(), endpointDefinition.getImplementationClass().getName()); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
107 |
1 |
@Test... |
108 |
|
public void testSendsRegisteredEvent() throws RepositoryException { |
109 |
|
|
110 |
|
|
111 |
1 |
configuredEndpointDefinitionManager.reload(nodes); |
112 |
|
|
113 |
|
|
114 |
1 |
assertEquals(1, eventBus.getSentEvents().size()); |
115 |
1 |
EndpointDefinitionRegistryEvent event = (EndpointDefinitionRegistryEvent) eventBus.getSentEvents().get(0); |
116 |
1 |
assertEquals(EndpointDefinitionRegistryEventType.REGISTERED, event.getType()); |
117 |
1 |
assertEquals("test", event.getEndpointDefinition().getName()); |
118 |
1 |
assertTrue(event.getEndpointDefinition().isEnabled()); |
119 |
1 |
assertEquals(TestEndpoint.class, event.getEndpointDefinition().getImplementationClass()); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
122 |
1 |
@Test... |
123 |
|
public void testSendsRegisteredEventForDisabledEndpoint() throws RepositoryException { |
124 |
|
|
125 |
1 |
final Node testEndpointNode = NodeUtil.createPath(configSession.getRootNode(), "/modules/yet-another-test/rest-endpoints", NodeTypes.ContentNode.NAME); |
126 |
1 |
final Node testEndpoint = NodeUtil.createPath(testEndpointNode, "/test-2", NodeTypes.ContentNode.NAME); |
127 |
1 |
testEndpoint.setProperty("enabled", false); |
128 |
1 |
testEndpoint.setProperty("class", ConfiguredEndpointDefinition.class.getName()); |
129 |
1 |
testEndpoint.setProperty("implementationClass", TestEndpoint.class.getName()); |
130 |
1 |
configSession.save(); |
131 |
|
|
132 |
1 |
List<Node> nodes = new ArrayList<Node>(); |
133 |
1 |
nodes.add(testEndpointNode); |
134 |
|
|
135 |
|
|
136 |
1 |
configuredEndpointDefinitionManager.reload(nodes); |
137 |
|
|
138 |
|
|
139 |
1 |
assertEquals(1, eventBus.getSentEvents().size()); |
140 |
1 |
EndpointDefinitionRegistryEvent event = (EndpointDefinitionRegistryEvent) eventBus.getSentEvents().get(0); |
141 |
1 |
assertEquals(EndpointDefinitionRegistryEventType.REGISTERED, event.getType()); |
142 |
1 |
assertEquals("test-2", event.getEndpointDefinition().getName()); |
143 |
1 |
assertFalse(event.getEndpointDefinition().isEnabled()); |
144 |
1 |
assertEquals(TestEndpoint.class, event.getEndpointDefinition().getImplementationClass()); |
145 |
|
} |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
147 |
1 |
@Test... |
148 |
|
public void testIgnoresIncompleteEndpointDefinition() throws RepositoryException { |
149 |
|
|
150 |
1 |
final Node testEndpointNode = NodeUtil.createPath(configSession.getRootNode(), "/modules/yet-another-test/rest-endpoints", NodeTypes.ContentNode.NAME); |
151 |
1 |
final Node testEndpoint = NodeUtil.createPath(testEndpointNode, "/test-2", NodeTypes.ContentNode.NAME); |
152 |
1 |
testEndpoint.setProperty("enabled", true); |
153 |
1 |
testEndpoint.setProperty("class", ConfiguredEndpointDefinition.class.getName()); |
154 |
1 |
configSession.save(); |
155 |
|
|
156 |
1 |
List<Node> nodes = new ArrayList<Node>(); |
157 |
1 |
nodes.add(testEndpointNode); |
158 |
|
|
159 |
|
|
160 |
1 |
configuredEndpointDefinitionManager.reload(nodes); |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
1 |
assertTrue(eventBus.isEmpty()); |
165 |
|
} |
166 |
|
} |