2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.restconf.rest.services.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
12 import static org.junit.Assert.assertTrue;
14 import com.google.common.collect.ImmutableSet;
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;
34 public class RestconfOperationsServiceTest {
37 private DOMMountPointService domMountPointService;
40 private UriInfo uriInfo;
42 private SchemaContext schemaContext;
43 private SchemaContextHandler schemaContextHandler;
44 private DOMMountPointServiceHandler domMountPointServiceHandler;
46 private Set<QName> listOfRpcsNames;
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);
56 final QNameModule module1 = QNameModule.create(new URI("module:1"), null);
57 final QNameModule module2 = QNameModule.create(new URI("module:2"), null);
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"));
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());
73 assertEquals(4, data.getValue().size());
75 for (final DataContainerChild<? extends PathArgument, ?> child : data.getValue()) {
76 assertNull(child.getValue());
78 final QName qname = child.getNodeType().withoutRevision();
79 assertTrue(listOfRpcsNames.contains(qname));