a9d4fdec67e9fadc80de9d5c917a3e599db27ca4
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / restconf / base / services / impl / RestconfImplTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.restconf.base.services.impl;
9
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;
24
25 public class RestconfImplTest {
26
27     @Test
28     public void RestImplTest() throws Exception {
29         final SchemaContext schemaContext =
30                 YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/impl"));
31
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);
43
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());
48     }
49 }