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%2FRestPutOperationTest.java;h=5d7eb20c42e648a9b319329ed27792e111ae74ab;hb=405ea7ce68d22bd3d2501857c5253793b581b086;hp=2df68af62f71e1aa89e0654fe1184c67ede23795;hpb=d71e327e51db32e967f7ebcb186e148f37f28117;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java index 2df68af62f..5d7eb20c42 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java @@ -1,3 +1,10 @@ +/* + * 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.junit.Assert.assertEquals; @@ -22,6 +29,7 @@ import javax.ws.rs.core.Response; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.sal.core.api.mount.MountInstance; @@ -42,6 +50,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class RestPutOperationTest extends JerseyTest { private static String xmlData; + private static String xmlData2; + private static String xmlData3; private static BrokerFacade brokerFacade; private static RestconfImpl restconfImpl; @@ -64,15 +74,19 @@ public class RestPutOperationTest extends JerseyTest { private static void loadData() throws IOException { InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml"); xmlData = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream)); + InputStream xmlStream2 = RestconfImplTest.class.getResourceAsStream("/full-versions/test-data2/data2.xml"); + xmlData2 = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream2)); + InputStream xmlStream3 = RestconfImplTest.class.getResourceAsStream("/full-versions/test-data2/data7.xml"); + xmlData3 = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream3)); } @Override protected Application configure() { /* enable/disable Jersey logs to console */ -// enable(TestProperties.LOG_TRAFFIC); -// enable(TestProperties.DUMP_ENTITY); -// enable(TestProperties.RECORD_LOG_LEVEL); -// set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); + // enable(TestProperties.LOG_TRAFFIC); + // enable(TestProperties.DUMP_ENTITY); + // enable(TestProperties.RECORD_LOG_LEVEL); + // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE, StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE, @@ -88,12 +102,11 @@ public class RestPutOperationTest extends JerseyTest { String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0"); mockCommitConfigurationDataPutMethod(TransactionStatus.COMMITED); assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData)); - + mockCommitConfigurationDataPutMethod(TransactionStatus.FAILED); assertEquals(500, put(uri, MediaType.APPLICATION_XML, xmlData)); } - /** * Tests of status codes for "/datastore/{identifier}". */ @@ -102,7 +115,7 @@ public class RestPutOperationTest extends JerseyTest { String uri = createUri("/datastore/", "ietf-interfaces:interfaces/interface/eth0"); mockCommitConfigurationDataPutMethod(TransactionStatus.COMMITED); assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData)); - + mockCommitConfigurationDataPutMethod(TransactionStatus.FAILED); assertEquals(500, put(uri, MediaType.APPLICATION_XML, xmlData)); } @@ -111,12 +124,12 @@ public class RestPutOperationTest extends JerseyTest { public void testRpcResultCommitedToStatusCodesWithMountPoint() throws UnsupportedEncodingException, FileNotFoundException, URISyntaxException { - RpcResult rpcResult = new DummyRpcResult.Builder().result(TransactionStatus.COMMITED) - .build(); + RpcResult rpcResult = new DummyRpcResult.Builder().result( + TransactionStatus.COMMITED).build(); Future> dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build(); - when(brokerFacade.commitConfigurationDataPutBehindMountPoint(any(MountInstance.class), + when( + brokerFacade.commitConfigurationDataPutBehindMountPoint(any(MountInstance.class), any(InstanceIdentifier.class), any(CompositeNode.class))).thenReturn(dummyFuture); - InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/full-versions/test-data2/data2.xml"); String xml = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream)); @@ -130,12 +143,30 @@ public class RestPutOperationTest extends JerseyTest { ControllerContext.getInstance().setMountService(mockMountService); String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/0/yang-ext:mount/test-module:cont"); - Response response = target(uri).request(Draft02.MediaTypes.DATA + XML).put(entity); - assertEquals(200, response.getStatus()); - + assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData2)); + uri = createUri("/config/", "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont"); - response = target(uri).request(Draft02.MediaTypes.DATA + XML).put(entity); - assertEquals(200, response.getStatus()); + assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData2)); + } + + @Test + public void putDataMountPointIntoHighestElement() throws UnsupportedEncodingException, URISyntaxException { + RpcResult rpcResult = new DummyRpcResult.Builder().result( + TransactionStatus.COMMITED).build(); + Future> dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build(); + when( + brokerFacade.commitConfigurationDataPutBehindMountPoint(any(MountInstance.class), + any(InstanceIdentifier.class), any(CompositeNode.class))).thenReturn(dummyFuture); + + MountInstance mountInstance = mock(MountInstance.class); + when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule); + MountService mockMountService = mock(MountService.class); + when(mockMountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn(mountInstance); + + ControllerContext.getInstance().setMountService(mockMountService); + + String uri = createUri("/config/", "ietf-interfaces:interfaces/yang-ext:mount"); + assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData3)); } private int put(String uri, String mediaType, String data) throws UnsupportedEncodingException {