X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FRestconfImplTest.java;h=e2559f4b70ab27e2e6d990996e84bd8fbfb47045;hb=f3ba8a814797fb5d50e24e3f9144f01406121464;hp=8263c467b04aeac223edf8f676036de8faa50c13;hpb=25563418e1867be44ab8d829db30360df60ee1c9;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java index 8263c467b0..e2559f4b70 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java @@ -1,14 +1,26 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.restconf.impl.test; -import static org.mockito.Mockito.*; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; import java.io.FileNotFoundException; -import java.io.InputStream; import java.util.Set; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; import org.opendaylight.controller.sal.restconf.impl.ControllerContext; import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; @@ -17,27 +29,44 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +/** + * @See {@link InvokeRpcMethodTest} + * + */ public class RestconfImplTest { - private static final RestconfImpl restconfImpl = new RestconfImpl(); + private RestconfImpl restconfImpl = null; + private static ControllerContext controllerContext = null; @BeforeClass public static void init() throws FileNotFoundException { - Set allModules = TestUtils.loadModules(RestconfImplTest.class.getResource("/full-versions/yangs").getPath()); - assertEquals(4, allModules.size()); + Set allModules = TestUtils + .loadModulesFrom("/full-versions/yangs"); + assertNotNull(allModules); SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules); - ControllerContext controllerContext = new ControllerContext(); + controllerContext = spy( ControllerContext.getInstance() ); controllerContext.setSchemas(schemaContext); - restconfImpl.setControllerContext(controllerContext); + + } + + @Before + public void initMethod() + { + restconfImpl = RestconfImpl.getInstance(); + restconfImpl.setControllerContext( controllerContext ); } @Test public void testExample() throws FileNotFoundException { - InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml"); - CompositeNode loadedCompositeNode = TestUtils.loadCompositeNode(xmlStream); + CompositeNode loadedCompositeNode = TestUtils.readInputToCnSn( + "/parts/ietf-interfaces_interfaces.xml", + XmlToCompositeNodeProvider.INSTANCE); BrokerFacade brokerFacade = mock(BrokerFacade.class); - when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(loadedCompositeNode); - assertEquals(loadedCompositeNode, brokerFacade.readOperationalData(null)); + when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))) + .thenReturn(loadedCompositeNode); + assertEquals(loadedCompositeNode, + brokerFacade.readOperationalData(null)); } + }