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 com.google.common.util.concurrent.CheckedFuture;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.mockito.Mockito;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
15 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
16 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
17 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
18 import org.opendaylight.restconf.Draft18.IetfYangLibrary;
19 import org.opendaylight.restconf.handlers.SchemaContextHandler;
20 import org.opendaylight.restconf.handlers.TransactionChainHandler;
21 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class RestconfImplTest {
28 public void RestImplTest() throws Exception {
29 final SchemaContext schemaContext =
30 YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/impl"));
32 final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
33 final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
34 Mockito.when(txHandler.get()).thenReturn(domTx);
35 final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class);
36 Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx);
37 final CheckedFuture checked = Mockito.mock(CheckedFuture.class);
38 Mockito.when(wTx.submit()).thenReturn(checked);
39 final Object valueObj = null;
40 Mockito.when(checked.checkedGet()).thenReturn(valueObj);
41 final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler);
42 schemaContextHandler.onGlobalContextUpdated(schemaContext);
44 final RestconfImpl restconfImpl = new RestconfImpl(schemaContextHandler);
45 final NormalizedNodeContext libraryVersion = restconfImpl.getLibraryVersion();
46 final LeafNode value = (LeafNode) libraryVersion.getData();
47 Assert.assertEquals(IetfYangLibrary.REVISION, value.getValue());