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 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.restconf.common.context.NormalizedNodeContext;
18 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
19 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
20 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
21 import org.opendaylight.restconf.nb.rfc8040.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;
26 public class RestconfImplTest {
29 public void restImplTest() throws Exception {
30 final SchemaContext schemaContext =
31 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/impl"));
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);
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());