X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FRestPostOperationTest.java;h=11264e7f860dcdd9c2820f7a8a89b056add4fca8;hp=5f8262ae7023e58a1380236fd8f58024717157cc;hb=4063669aa69554b0513aac11c7a4e20fa066fa06;hpb=d5b22f2866ab224fe23d01f7163b9b60080c437f diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java index 5f8262ae70..11264e7f86 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.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; @@ -7,7 +14,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML; -import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.createUri; import java.io.IOException; import java.io.InputStream; @@ -22,7 +28,6 @@ import java.util.concurrent.Future; import javax.ws.rs.client.Entity; import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; @@ -36,7 +41,6 @@ import org.opendaylight.controller.sal.rest.api.Draft02; import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider; import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider; import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; -import org.opendaylight.controller.sal.rest.impl.XmlMapper; import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; @@ -105,7 +109,7 @@ public class RestPostOperationTest extends JerseyTest { public void postOperationsStatusCodes() throws UnsupportedEncodingException { controllerContext.setSchemas(schemaContextTestModule); mockInvokeRpc(cnSnDataOutput, true); - String uri = createUri("/operations/", "test-module:rpc-test"); + String uri = "/operations/test-module:rpc-test"; assertEquals(200, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); mockInvokeRpc(null, true); @@ -114,7 +118,7 @@ public class RestPostOperationTest extends JerseyTest { mockInvokeRpc(null, false); assertEquals(500, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); - uri = createUri("/operations/", "test-module:rpc-wrongtest"); + uri = "/operations/test-module:rpc-wrongtest"; assertEquals(404, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); } @@ -122,7 +126,7 @@ public class RestPostOperationTest extends JerseyTest { public void postConfigOnlyStatusCodes() throws UnsupportedEncodingException { controllerContext.setSchemas(schemaContextYangsIetf); mockCommitConfigurationDataPostMethod(TransactionStatus.COMMITED); - String uri = createUri("/config", ""); + String uri = "/config"; assertEquals(204, post(uri, MediaType.APPLICATION_XML, xmlDataAbsolutePath)); mockCommitConfigurationDataPostMethod(null); @@ -136,21 +140,7 @@ public class RestPostOperationTest extends JerseyTest { public void postConfigStatusCodes() throws UnsupportedEncodingException { controllerContext.setSchemas(schemaContextYangsIetf); mockCommitConfigurationDataPostMethod(TransactionStatus.COMMITED); - String uri = createUri("/config/", "ietf-interfaces:interfaces"); - assertEquals(204, post(uri, MediaType.APPLICATION_XML, xmlDataInterfaceAbsolutePath)); - - mockCommitConfigurationDataPostMethod(null); - assertEquals(202, post(uri, MediaType.APPLICATION_XML, xmlDataInterfaceAbsolutePath)); - - mockCommitConfigurationDataPostMethod(TransactionStatus.FAILED); - assertEquals(500, post(uri, MediaType.APPLICATION_XML, xmlDataInterfaceAbsolutePath)); - } - - @Test - public void postDatastoreStatusCodes() throws UnsupportedEncodingException { - controllerContext.setSchemas(schemaContextYangsIetf); - mockCommitConfigurationDataPostMethod(TransactionStatus.COMMITED); - String uri = createUri("/datastore/", "ietf-interfaces:interfaces"); + String uri = "/config/ietf-interfaces:interfaces"; assertEquals(204, post(uri, MediaType.APPLICATION_XML, xmlDataInterfaceAbsolutePath)); mockCommitConfigurationDataPostMethod(null); @@ -177,9 +167,9 @@ public class RestPostOperationTest extends JerseyTest { ControllerContext.getInstance().setMountService(mockMountService); - String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/0/"); + String uri = "/config/ietf-interfaces:interfaces/interface/0/"; assertEquals(204, post(uri, Draft02.MediaTypes.DATA + XML, xmlData4)); - uri = createUri("/config/", "ietf-interfaces:interfaces/interface/0/yang-ext:mount/test-module:cont"); + uri = "/config/ietf-interfaces:interfaces/interface/0/yang-ext:mount/test-module:cont"; assertEquals(204, post(uri, Draft02.MediaTypes.DATA + XML, xmlData3)); } @@ -216,13 +206,13 @@ public class RestPostOperationTest extends JerseyTest { ArgumentCaptor instanceIdCaptor = ArgumentCaptor.forClass(InstanceIdentifier.class); ArgumentCaptor compNodeCaptor = ArgumentCaptor.forClass(CompositeNode.class); - String URI_1 = createUri("/config", ""); + String URI_1 = "/config"; assertEquals(204, post(URI_1, Draft02.MediaTypes.DATA + XML, xmlTestInterface)); verify(brokerFacade).commitConfigurationDataPost(instanceIdCaptor.capture(), compNodeCaptor.capture()); String identifier = "[(urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)interfaces]"; assertEquals(identifier, instanceIdCaptor.getValue().getPath().toString()); - String URI_2 = createUri("/config/", "test-interface:interfaces"); + String URI_2 = "/config/test-interface:interfaces"; assertEquals(204, post(URI_2, Draft02.MediaTypes.DATA + XML, xmlBlockData)); verify(brokerFacade, times(2)) .commitConfigurationDataPost(instanceIdCaptor.capture(), compNodeCaptor.capture()); @@ -237,17 +227,13 @@ public class RestPostOperationTest extends JerseyTest { when(brokerFacade.commitConfigurationDataPost(any(InstanceIdentifier.class), any(CompositeNode.class))) .thenReturn(null); - String URI_1 = createUri("/config", ""); + String URI_1 = "/config"; assertEquals(202, post(URI_1, Draft02.MediaTypes.DATA + XML, xmlTestInterface)); - String URI_2 = createUri("/config/", "test-interface:interfaces"); + String URI_2 = "/config/test-interface:interfaces"; assertEquals(202, post(URI_2, Draft02.MediaTypes.DATA + XML, xmlBlockData)); } - private String createUri(String prefix, String encodedPart) throws UnsupportedEncodingException { - return URI.create(prefix + URLEncoder.encode(encodedPart, Charsets.US_ASCII.name()).toString()).toASCIIString(); - } - private static void initMocking() { controllerContext = ControllerContext.getInstance(); controllerContext.setSchemas(schemaContext);