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;
24 public class RestconfImplTest {
27 public void RestImplTest() throws Exception {
28 final SchemaContext schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/impl");
30 final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
31 final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
32 Mockito.when(txHandler.get()).thenReturn(domTx);
33 final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class);
34 Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx);
35 final CheckedFuture checked = Mockito.mock(CheckedFuture.class);
36 Mockito.when(wTx.submit()).thenReturn(checked);
37 final Object valueObj = null;
38 Mockito.when(checked.checkedGet()).thenReturn(valueObj);
39 final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler);
40 schemaContextHandler.onGlobalContextUpdated(schemaContext);
42 final RestconfImpl restconfImpl = new RestconfImpl(schemaContextHandler);
43 final NormalizedNodeContext libraryVersion = restconfImpl.getLibraryVersion();
44 final LeafNode value = (LeafNode) libraryVersion.getData();
45 Assert.assertEquals(IetfYangLibrary.REVISION, value.getValue());