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