f32182e07207fc7192398762a1f73d565a05afaf
[netconf.git] / restconf / restconf-nb-bierman02 / 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.common.api.data.TransactionCommitFailedException;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
16 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
17 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
18 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
19 import org.opendaylight.restconf.Rfc8040.IetfYangLibrary;
20 import org.opendaylight.restconf.handlers.SchemaContextHandler;
21 import org.opendaylight.restconf.handlers.TransactionChainHandler;
22 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25
26 public class RestconfImplTest {
27
28     @Test
29     public void restImplTest() throws Exception {
30         final SchemaContext schemaContext =
31                 YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/impl"));
32
33         final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
34         final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
35         Mockito.when(txHandler.get()).thenReturn(domTx);
36         final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class);
37         Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx);
38         final CheckedFuture<Void, TransactionCommitFailedException> checked = Mockito.mock(CheckedFuture.class);
39         Mockito.when(wTx.submit()).thenReturn(checked);
40         Mockito.when(checked.checkedGet()).thenReturn(null);
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 }