Bug 953 - Enable mounted RPC calls via RestConf
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / RestconfImplTest.java
1 /*
2  * Copyright (c) 2014 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.controller.sal.restconf.impl.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.spy;
15 import static org.mockito.Mockito.when;
16
17 import java.io.FileNotFoundException;
18 import java.util.Set;
19
20 import org.junit.Before;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
24 import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
25 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
26 import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
27 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
28 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.model.api.Module;
30 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
31
32 /**
33  * @See {@link InvokeRpcMethodTest}
34  *
35  */
36 public class RestconfImplTest {
37
38     private RestconfImpl restconfImpl = null;
39     private static ControllerContext controllerContext = null;
40
41     @BeforeClass
42     public static void init() throws FileNotFoundException {
43         Set<Module> allModules = TestUtils
44                 .loadModulesFrom("/full-versions/yangs");
45         assertNotNull(allModules);
46         SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
47         controllerContext = spy( ControllerContext.getInstance() );
48         controllerContext.setSchemas(schemaContext);
49
50     }
51
52     @Before
53     public void initMethod()
54     {
55         restconfImpl = RestconfImpl.getInstance();
56         restconfImpl.setControllerContext( controllerContext );
57     }
58
59     @Test
60     public void testExample() throws FileNotFoundException {
61         CompositeNode loadedCompositeNode = TestUtils.readInputToCnSn(
62                 "/parts/ietf-interfaces_interfaces.xml",
63                 XmlToCompositeNodeProvider.INSTANCE);
64         BrokerFacade brokerFacade = mock(BrokerFacade.class);
65         when(brokerFacade.readOperationalData(any(InstanceIdentifier.class)))
66                 .thenReturn(loadedCompositeNode);
67         assertEquals(loadedCompositeNode,
68                 brokerFacade.readOperationalData(null));
69     }
70
71
72 }