Clover icon

Magnolia REST Integration 2.1.5

  1. Project Clover database Tue Jan 28 2020 16:36:47 CET
  2. Package info.magnolia.rest.registry

File ConfiguredEndpointDefinitionManagerTest.java

 

Code metrics

0
49
5
1
166
93
5
0.1
9.8
5
1

Classes

Class Line # Actions
ConfiguredEndpointDefinitionManagerTest 58 49 0% 5 54
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2013-2018 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
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   
 
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   
 
66  0 toggle @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   
 
89  0 toggle @Test
90    @Ignore("ConfiguredEndpointDefinitionManagerTest is deprecated and should not be used anymore.")
91    public void testGetEndpointDefinition() throws Exception {
92    // GIVEN
93   
94    // WHEN
95  0 configuredEndpointDefinitionManager.reload(nodes);
96   
97    // THEN
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   
 
104  0 toggle @Test
105    @Ignore("ConfiguredEndpointDefinitionManagerTest is deprecated and should not be used anymore.")
106    public void testSendsRegisteredEvent() throws Exception {
107   
108    // WHEN
109  0 configuredEndpointDefinitionManager.reload(nodes);
110   
111    // THEN
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   
 
120  0 toggle @Test
121    @Ignore("ConfiguredEndpointDefinitionManagerTest is deprecated and should not be used anymore.")
122    public void testSendsRegisteredEventForDisabledEndpoint() throws Exception {
123    // GIVEN
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    // WHEN
135  0 configuredEndpointDefinitionManager.reload(nodes);
136   
137    // THEN
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   
 
146  0 toggle @Test
147    @Ignore("ConfiguredEndpointDefinitionManagerTest is deprecated and should not be used anymore.")
148    public void testIgnoresIncompleteEndpointDefinition() throws Exception {
149    // GIVEN
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    // WHEN
160  0 configuredEndpointDefinitionManager.reload(nodes);
161   
162    // THEN
163    // Should be empty, as endpoint was not yet fully configured
164  0 assertTrue(eventBus.isEmpty());
165    }
166    }