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 |
|
|
38 |
|
import info.magnolia.event.RecordingEventBus; |
39 |
|
import info.magnolia.jcr.node2bean.Node2BeanException; |
40 |
|
import info.magnolia.jcr.node2bean.Node2BeanProcessor; |
41 |
|
import info.magnolia.jcr.node2bean.impl.Node2BeanProcessorImpl; |
42 |
|
import info.magnolia.jcr.node2bean.impl.Node2BeanTransformerImpl; |
43 |
|
import info.magnolia.jcr.node2bean.impl.TypeMappingImpl; |
44 |
|
import info.magnolia.registry.RegistrationException; |
45 |
|
import info.magnolia.rest.EndpointDefinition; |
46 |
|
import info.magnolia.test.ComponentsTestUtil; |
47 |
|
import info.magnolia.test.MgnlTestCase; |
48 |
|
import info.magnolia.test.mock.jcr.MockNode; |
49 |
|
|
50 |
|
import java.util.ArrayList; |
51 |
|
import java.util.Arrays; |
52 |
|
import java.util.HashSet; |
53 |
|
import java.util.Set; |
54 |
|
|
55 |
|
import javax.jcr.RepositoryException; |
56 |
|
|
57 |
|
import org.junit.Before; |
58 |
|
import org.junit.Test; |
59 |
|
|
60 |
|
|
61 |
|
@link |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (54) |
Complexity: 8 |
Complexity Density: 0.17 |
|
63 |
|
public class EndpointDefinitionRegistryTest extends MgnlTestCase { |
64 |
|
|
65 |
|
private EndpointDefinitionRegistry endpointDefinitionRegistry; |
66 |
|
private RecordingEventBus eventBus; |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
68 |
5 |
@Before... |
69 |
|
public void setUp() throws Exception { |
70 |
5 |
eventBus = new RecordingEventBus(); |
71 |
5 |
endpointDefinitionRegistry = new EndpointDefinitionRegistry(eventBus); |
72 |
|
|
73 |
5 |
TypeMappingImpl typeMapping = new TypeMappingImpl(); |
74 |
5 |
Node2BeanTransformerImpl transformer = new Node2BeanTransformerImpl(); |
75 |
5 |
ComponentsTestUtil.setInstance(Node2BeanProcessor.class, new Node2BeanProcessorImpl(typeMapping, transformer)); |
76 |
5 |
ComponentsTestUtil.setImplementation(EndpointDefinition.class, ConfiguredEndpointDefinition.class); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
79 |
1 |
@Test... |
80 |
|
public void testGetEndpointDefinition() throws Node2BeanException, RepositoryException, RegistrationException { |
81 |
|
|
82 |
1 |
final String endpoint1 = "endpoint1"; |
83 |
1 |
EndpointDefinitionProvider endpointDefinitionProvider = createEndpointDefinitionProvider(endpoint1, true); |
84 |
|
|
85 |
1 |
endpointDefinitionRegistry.unregisterAndRegister(new HashSet<String>(), Arrays.asList(endpointDefinitionProvider)); |
86 |
|
|
87 |
|
|
88 |
1 |
EndpointDefinition definition = endpointDefinitionRegistry.getEndpointDefinition(endpoint1); |
89 |
|
|
90 |
|
|
91 |
1 |
assertNotNull(definition); |
92 |
1 |
assertEquals(endpoint1, definition.getName()); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
95 |
1 |
@Test(expected = RegistrationException.class)... |
96 |
|
public void testGetEndpointDefinitionThrowsExceptionWhenEndpointNotFound() throws Node2BeanException, RepositoryException, RegistrationException { |
97 |
|
|
98 |
1 |
final String endpoint2 = "endpoint2"; |
99 |
1 |
EndpointDefinitionProvider endpointDefinitionProvider = createEndpointDefinitionProvider(endpoint2, true); |
100 |
|
|
101 |
1 |
endpointDefinitionRegistry.unregisterAndRegister(new HashSet<String>(), Arrays.asList(endpointDefinitionProvider)); |
102 |
|
|
103 |
|
|
104 |
1 |
endpointDefinitionRegistry.getEndpointDefinition("xx"); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
107 |
1 |
@Test... |
108 |
|
public void testUnregisterAndRegisterWhenEmpty() throws Node2BeanException, RepositoryException, RegistrationException { |
109 |
|
|
110 |
1 |
String endpoint3 = "endpoint3"; |
111 |
1 |
EndpointDefinitionProvider endpointDefinitionProvider = createEndpointDefinitionProvider(endpoint3, true); |
112 |
|
|
113 |
|
|
114 |
1 |
Set<String> registeredNames = endpointDefinitionRegistry.unregisterAndRegister(new HashSet<String>(), Arrays.asList(endpointDefinitionProvider)); |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
1 |
assertNotNull(registeredNames); |
119 |
1 |
assertEquals(1, registeredNames.size()); |
120 |
1 |
assertEquals(endpoint3, registeredNames.toArray()[0]); |
121 |
1 |
assertEquals(1, eventBus.getSentEvents().size()); |
122 |
1 |
assertEquals("endpoint3", ((EndpointDefinitionRegistryEvent) eventBus.getEvent()).getEndpointDefinition().getName()); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void testRegister() throws RepositoryException, Node2BeanException, RegistrationException { |
127 |
|
|
128 |
1 |
final String endpoint4 = "endpoint4"; |
129 |
1 |
EndpointDefinitionProvider provider = createEndpointDefinitionProvider(endpoint4, true); |
130 |
|
|
131 |
1 |
assertFalse(endpointDefinitionRegistry.isEndpointDefinitionRegistered(endpoint4)); |
132 |
|
|
133 |
|
|
134 |
1 |
endpointDefinitionRegistry.unregisterAndRegister(new HashSet<String>(), Arrays.asList(provider)); |
135 |
|
|
136 |
|
|
137 |
1 |
assertTrue(endpointDefinitionRegistry.isEndpointDefinitionRegistered(endpoint4)); |
138 |
1 |
assertEquals(1, eventBus.getSentEvents().size()); |
139 |
1 |
assertEquals("endpoint4", ((EndpointDefinitionRegistryEvent) eventBus.getEvent()).getEndpointDefinition().getName()); |
140 |
|
} |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
142 |
1 |
@Test... |
143 |
|
public void testUnregister() throws RepositoryException, Node2BeanException, RegistrationException { |
144 |
|
|
145 |
1 |
final String endpoint5 = "endpoint5"; |
146 |
1 |
EndpointDefinitionProvider provider = createEndpointDefinitionProvider(endpoint5, true); |
147 |
|
|
148 |
1 |
assertFalse(endpointDefinitionRegistry.isEndpointDefinitionRegistered(endpoint5)); |
149 |
|
|
150 |
1 |
endpointDefinitionRegistry.unregisterAndRegister(new HashSet<String>(), Arrays.asList(provider)); |
151 |
1 |
eventBus.getSentEvents().clear(); |
152 |
|
|
153 |
1 |
assertTrue(endpointDefinitionRegistry.isEndpointDefinitionRegistered(endpoint5)); |
154 |
|
|
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
1 |
endpointDefinitionRegistry.unregisterAndRegister(new HashSet<String>() {{ add(endpoint5); }}, new ArrayList<EndpointDefinitionProvider>());... |
157 |
|
|
158 |
|
|
159 |
1 |
assertFalse(endpointDefinitionRegistry.isEndpointDefinitionRegistered(endpoint5)); |
160 |
1 |
assertEquals(1, eventBus.getSentEvents().size()); |
161 |
1 |
assertEquals("endpoint5", ((EndpointDefinitionRegistryEvent) eventBus.getEvent()).getEndpointName()); |
162 |
|
} |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
164 |
5 |
private EndpointDefinitionProvider createEndpointDefinitionProvider(String name, boolean enabled) throws RepositoryException, Node2BeanException {... |
165 |
5 |
MockNode node = new MockNode("name"); |
166 |
5 |
node.setProperty("name", name); |
167 |
5 |
node.setProperty("enabled", enabled); |
168 |
5 |
return new ConfiguredEndpointDefinitionProvider(name, node); |
169 |
|
} |
170 |
|
|
171 |
|
} |