Bug 5553 - Impl get operations
[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 java.util.ArrayList;
11 import java.util.List;
12 import javax.ws.rs.core.UriInfo;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.mockito.Mock;
17 import org.mockito.MockitoAnnotations;
18 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
19 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
20 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
21 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
22 import org.opendaylight.restconf.handlers.SchemaContextHandler;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
24 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27
28 public class RestconfOperationsServiceTest {
29
30     @Mock
31     private DOMMountPointService domMountPointService;
32
33     @Mock
34     private UriInfo uriInfo;
35
36     private SchemaContext schemaContext;
37     private SchemaContextHandler schemaContextHandler;
38     private DOMMountPointServiceHandler domMountPointServiceHandler;
39
40     private static final List<String> listOfRpcsNames = new ArrayList<>();
41
42     @Before
43     public void init() throws Exception {
44         MockitoAnnotations.initMocks(this);
45         this.schemaContext = TestRestconfUtils.loadSchemaContext("/modules");
46         this.schemaContextHandler = new SchemaContextHandler();
47         this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
48         this.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService);
49         listOfRpcsNames.add("module2:dummy-rpc2-module2");
50         listOfRpcsNames.add("module2:dummy-rpc1-module2");
51         listOfRpcsNames.add("module1:dummy-rpc2-module1");
52         listOfRpcsNames.add("module1:dummy-rpc1-module1");
53     }
54
55     @Test
56     public void getOperationsTest() {
57         final RestconfOperationsServiceImpl oper = new RestconfOperationsServiceImpl(this.schemaContextHandler, this.domMountPointServiceHandler);
58         final NormalizedNodeContext operations = oper.getOperations(this.uriInfo);
59         final ContainerNode data = (ContainerNode) operations.getData();
60         Assert.assertTrue(
61                 data.getNodeType().getNamespace().toString().equals("urn:ietf:params:xml:ns:yang:ietf-restconf"));
62         Assert.assertTrue(data.getNodeType().getLocalName().equals("operations"));
63         for (final DataContainerChild<? extends PathArgument, ?> dataContainerChild : data.getValue()) {
64             Assert.assertTrue(dataContainerChild.getNodeType().getNamespace().toString()
65                     .equals("urn:ietf:params:xml:ns:yang:ietf-restconf"));
66             Assert.assertTrue(listOfRpcsNames.contains(dataContainerChild.getNodeType().getLocalName()));
67             Assert.assertTrue(dataContainerChild.getValue() == null);
68         }
69
70     }
71 }