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.nb.rfc8040.services.simple.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import com.google.common.collect.ImmutableSet;
16 import javax.ws.rs.core.UriInfo;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
23 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
24 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
25 import org.opendaylight.restconf.nb.rfc8040.TestUtils;
26 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
27 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
28 import org.opendaylight.yangtools.yang.common.Empty;
29 import org.opendaylight.yangtools.yang.common.QName;
30 import org.opendaylight.yangtools.yang.common.QNameModule;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
32 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
34 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
35 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
37 @RunWith(MockitoJUnitRunner.StrictStubs.class)
38 public class RestconfOperationsServiceTest {
41 private DOMMountPointService domMountPointService;
44 private UriInfo uriInfo;
46 private EffectiveModelContext schemaContext;
47 private SchemaContextHandler schemaContextHandler;
48 private DOMMountPointServiceHandler domMountPointServiceHandler;
50 private Set<QName> listOfRpcsNames;
53 public void init() throws Exception {
54 this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules"));
55 this.schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
57 this.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService);
59 final QNameModule module1 = QNameModule.create(URI.create("module:1"));
60 final QNameModule module2 = QNameModule.create(URI.create("module:2"));
62 this.listOfRpcsNames = ImmutableSet.of(QName.create(module1, "dummy-rpc1-module1"),
63 QName.create(module1, "dummy-rpc2-module1"), QName.create(module2, "dummy-rpc1-module2"),
64 QName.create(module2, "dummy-rpc2-module2"));
68 public void getOperationsTest() {
69 final RestconfOperationsServiceImpl oper =
70 new RestconfOperationsServiceImpl(this.schemaContextHandler, this.domMountPointServiceHandler);
71 final NormalizedNodeContext operations = oper.getOperations(this.uriInfo);
72 final ContainerNode data = (ContainerNode) operations.getData();
73 assertEquals("urn:ietf:params:xml:ns:yang:ietf-restconf", data.getNodeType().getNamespace().toString());
74 assertEquals("operations", data.getNodeType().getLocalName());
76 assertEquals(4, data.getValue().size());
78 for (final DataContainerChild<? extends PathArgument, ?> child : data.getValue()) {
79 assertEquals(Empty.getInstance(), child.getValue());
81 final QName qname = child.getNodeType().withoutRevision();
82 assertTrue(this.listOfRpcsNames.contains(qname));