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.base.services.impl.RestconfOperationsServiceImpl;
26 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
27 import org.opendaylight.restconf.handlers.SchemaContextHandler;
28 import org.opendaylight.yangtools.yang.common.QName;
29 import org.opendaylight.yangtools.yang.common.QNameModule;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
31 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
33 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
35 public class RestconfOperationsServiceTest {
38 private DOMMountPointService domMountPointService;
41 private UriInfo uriInfo;
43 private SchemaContext schemaContext;
44 private SchemaContextHandler schemaContextHandler;
45 private DOMMountPointServiceHandler domMountPointServiceHandler;
47 private Set<QName> listOfRpcsNames;
50 public void init() throws Exception {
51 MockitoAnnotations.initMocks(this);
52 this.schemaContext = TestRestconfUtils.loadSchemaContext("/modules");
53 this.schemaContextHandler = new SchemaContextHandler();
54 this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
55 this.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService);
57 final QNameModule module1 = QNameModule.create(new URI("module:1"), null);
58 final QNameModule module2 = QNameModule.create(new URI("module:2"), null);
60 listOfRpcsNames = ImmutableSet.of(
61 QName.create(module1, "dummy-rpc1-module1"), QName.create(module1, "dummy-rpc2-module1"),
62 QName.create(module2, "dummy-rpc1-module2"), QName.create(module2, "dummy-rpc2-module2"));
66 public void getOperationsTest() {
67 final RestconfOperationsServiceImpl oper = new RestconfOperationsServiceImpl(this.schemaContextHandler,
68 this.domMountPointServiceHandler);
69 final NormalizedNodeContext operations = oper.getOperations(this.uriInfo);
70 final ContainerNode data = (ContainerNode) operations.getData();
71 assertEquals("urn:ietf:params:xml:ns:yang:ietf-restconf", data.getNodeType().getNamespace().toString());
72 assertEquals("operations", data.getNodeType().getLocalName());
74 assertEquals(4, data.getValue().size());
76 for (final DataContainerChild<? extends PathArgument, ?> child : data.getValue()) {
77 assertNull(child.getValue());
79 final QName qname = child.getNodeType().withoutRevision();
80 assertTrue(listOfRpcsNames.contains(qname));