6578d5114967320950f347f7f6b1f6d29b79f92e
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / restconf / rest / services / impl / RestconfOperationsServiceTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.rest.services.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
12 import static org.junit.Assert.assertTrue;
13
14 import com.google.common.collect.ImmutableSet;
15 import java.net.URI;
16 import java.util.Set;
17 import javax.ws.rs.core.UriInfo;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
23 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
24 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
25 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
26 import org.opendaylight.restconf.handlers.SchemaContextHandler;
27 import org.opendaylight.yangtools.yang.common.QName;
28 import org.opendaylight.yangtools.yang.common.QNameModule;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
30 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
32 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
33
34 public class RestconfOperationsServiceTest {
35
36     @Mock
37     private DOMMountPointService domMountPointService;
38
39     @Mock
40     private UriInfo uriInfo;
41
42     private SchemaContext schemaContext;
43     private SchemaContextHandler schemaContextHandler;
44     private DOMMountPointServiceHandler domMountPointServiceHandler;
45
46     private Set<QName> listOfRpcsNames;
47
48     @Before
49     public void init() throws Exception {
50         MockitoAnnotations.initMocks(this);
51         this.schemaContext = TestRestconfUtils.loadSchemaContext("/modules");
52         this.schemaContextHandler = new SchemaContextHandler();
53         this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
54         this.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService);
55
56         final QNameModule module1 = QNameModule.create(new URI("module:1"), null);
57         final QNameModule module2 = QNameModule.create(new URI("module:2"), null);
58
59         listOfRpcsNames = ImmutableSet.of(
60             QName.create(module1, "dummy-rpc1-module1"), QName.create(module1, "dummy-rpc2-module1"),
61             QName.create(module2, "dummy-rpc1-module2"), QName.create(module2, "dummy-rpc2-module2"));
62     }
63
64     @Test
65     public void getOperationsTest() {
66         final RestconfOperationsServiceImpl oper = new RestconfOperationsServiceImpl(this.schemaContextHandler,
67             this.domMountPointServiceHandler);
68         final NormalizedNodeContext operations = oper.getOperations(this.uriInfo);
69         final ContainerNode data = (ContainerNode) operations.getData();
70         assertEquals("urn:ietf:params:xml:ns:yang:ietf-restconf", data.getNodeType().getNamespace().toString());
71         assertEquals("operations", data.getNodeType().getLocalName());
72
73         assertEquals(4, data.getValue().size());
74
75         for (final DataContainerChild<? extends PathArgument, ?> child : data.getValue()) {
76             assertNull(child.getValue());
77
78             final QName qname = child.getNodeType().withoutRevision();
79             assertTrue(listOfRpcsNames.contains(qname));
80         }
81     }
82 }