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.base.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;
15 import com.google.common.util.concurrent.Futures;
18 import javax.ws.rs.core.UriInfo;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.Mockito;
23 import org.mockito.MockitoAnnotations;
24 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
25 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
26 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
27 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
28 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
29 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
30 import org.opendaylight.restconf.handlers.SchemaContextHandler;
31 import org.opendaylight.restconf.handlers.TransactionChainHandler;
32 import org.opendaylight.yangtools.yang.common.QName;
33 import org.opendaylight.yangtools.yang.common.QNameModule;
34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
35 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
36 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
37 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
38 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
40 public class RestconfOperationsServiceTest {
43 private DOMMountPointService domMountPointService;
46 private UriInfo uriInfo;
48 private SchemaContext schemaContext;
49 private SchemaContextHandler schemaContextHandler;
50 private DOMMountPointServiceHandler domMountPointServiceHandler;
52 private Set<QName> listOfRpcsNames;
55 public void init() throws Exception {
56 MockitoAnnotations.initMocks(this);
57 this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules"));
59 final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
60 final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
61 Mockito.when(txHandler.get()).thenReturn(domTx);
62 final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class);
63 Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx);
64 Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
65 this.schemaContextHandler = new SchemaContextHandler(txHandler);
66 this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
68 this.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService);
70 final QNameModule module1 = QNameModule.create(new URI("module:1"), null);
71 final QNameModule module2 = QNameModule.create(new URI("module:2"), null);
73 this.listOfRpcsNames = ImmutableSet.of(QName.create(module1, "dummy-rpc1-module1"),
74 QName.create(module1, "dummy-rpc2-module1"), QName.create(module2, "dummy-rpc1-module2"),
75 QName.create(module2, "dummy-rpc2-module2"));
79 public void getOperationsTest() {
80 final RestconfOperationsServiceImpl oper =
81 new RestconfOperationsServiceImpl(this.schemaContextHandler, this.domMountPointServiceHandler);
82 final NormalizedNodeContext operations = oper.getOperations(this.uriInfo);
83 final ContainerNode data = (ContainerNode) operations.getData();
84 assertEquals("urn:ietf:params:xml:ns:yang:ietf-restconf", data.getNodeType().getNamespace().toString());
85 assertEquals("operations", data.getNodeType().getLocalName());
87 assertEquals(4, data.getValue().size());
89 for (final DataContainerChild<? extends PathArgument, ?> child : data.getValue()) {
90 assertNull(child.getValue());
92 final QName qname = child.getNodeType().withoutRevision();
93 assertTrue(this.listOfRpcsNames.contains(qname));