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=bb731a32d099955edf4a93a7b51d5afc3dab3b67;hp=1ac71bdec9331e000941bc3fefb19503fd4b5a6a;hb=2727bea09c83646b6cbd2ef9672d0b7f6cf3b22f;hpb=c846dae5f92a60ea0df0af05e298d02d613275e8 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 1ac71bdec9..bb731a32d0 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 @@ -9,13 +9,12 @@ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; 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 com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.CheckedFuture; @@ -23,13 +22,8 @@ import com.google.common.util.concurrent.Futures; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.net.URI; import java.net.URISyntaxException; import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; import java.util.Set; import javax.ws.rs.client.Entity; import javax.ws.rs.core.Application; @@ -51,15 +45,9 @@ import org.opendaylight.controller.sal.rest.impl.NormalizedNodeXmlBodyWriter; import org.opendaylight.controller.sal.rest.impl.RestconfDocumentedExceptionMapper; import org.opendaylight.controller.sal.rest.impl.XmlNormalizedNodeBodyReader; import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; -import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; import org.opendaylight.controller.sal.restconf.impl.ControllerContext; -import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcError.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.Module; @@ -72,7 +60,6 @@ public class RestPostOperationTest extends JerseyTest { private static String xmlDataRpcInput; private static String xmlBlockData; private static String xmlTestInterface; - private static CompositeNodeWrapper cnSnDataOutput; private static String xmlData3; private static String xmlData4; @@ -118,71 +105,7 @@ public class RestPostOperationTest extends JerseyTest { restconfImpl.setControllerContext(context); } -// @Test -// public void postRpcNoPayload() throws Exception { -// setSchemaControllerContext(schemaContextTestModule); -// final String uri = "/operations/test-module:no-payload-rpc-test"; -// final String mediaType = MediaType.APPLICATION_XML; -// final Response response = target(uri).request(mediaType).post(Entity.entity("", mediaType)); -// assertNotNull(response); -// -// } - - @Test - @Ignore //FIXME we don't wish to mock CompositeNode as result - public void postOperationsStatusCodes() throws IOException { - setSchemaControllerContext(schemaContextTestModule); - mockInvokeRpc(cnSnDataOutput, true); - String uri = "/operations/test-module:rpc-test"; - assertEquals(200, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); - - mockInvokeRpc(null, true); - assertEquals(204, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); - - mockInvokeRpc(null, false); - assertEquals(500, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); - - final List rpcErrors = new ArrayList<>(); - rpcErrors.add(RpcResultBuilder.newError(ErrorType.RPC, "tag1", "message1", "applicationTag1", "info1", null)); - rpcErrors.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "tag2", "message2", "applicationTag2", "info2", - null)); - mockInvokeRpc(null, false, rpcErrors); - assertEquals(500, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); - - uri = "/operations/test-module:rpc-wrongtest"; - assertEquals(400, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); - } - - @Test - @Ignore // TODO RestconfDocumentedExceptionMapper needs be fixed before - public void postConfigOnlyStatusCodes() throws UnsupportedEncodingException { - setSchemaControllerContext(schemaContextYangsIetf); - final String uri = "/config"; - mockCommitConfigurationDataPostMethod(true); - assertEquals(204, post(uri, MediaType.APPLICATION_XML, xmlDataAbsolutePath)); - - mockCommitConfigurationDataPostMethod(false); - assertEquals(500, post(uri, MediaType.APPLICATION_XML, xmlDataAbsolutePath)); - - assertEquals(400, post(uri, MediaType.APPLICATION_XML, "")); - } - - @Test - @Ignore //jenkins has problem with JerseyTest - we expecting problems with singletons ControllerContext as schemaContext holder - public void postConfigStatusCodes() throws UnsupportedEncodingException { - setSchemaControllerContext(schemaContextYangsIetf); - final String uri = "/config/ietf-interfaces:interfaces"; - - mockCommitConfigurationDataPostMethod(true); - assertEquals(204, post(uri, MediaType.APPLICATION_XML, xmlDataInterfaceAbsolutePath)); - - mockCommitConfigurationDataPostMethod(false); - assertEquals(500, post(uri, MediaType.APPLICATION_XML, xmlDataInterfaceAbsolutePath)); - - // FIXME : empty json input post value return NullPointerException by parsing -> err. code 500 -// assertEquals(400, post(uri, MediaType.APPLICATION_JSON, "")); - } - + @SuppressWarnings("unchecked") @Test @Ignore /// xmlData* need netconf-yang public void postDataViaUrlMountPoint() throws UnsupportedEncodingException { @@ -206,35 +129,7 @@ public class RestPostOperationTest extends JerseyTest { assertEquals(400, post(uri, MediaType.APPLICATION_JSON, "")); } - private void mockInvokeRpc(final CompositeNode result, final boolean sucessful, final Collection errors) { - - final DummyRpcResult.Builder builder = new DummyRpcResult.Builder().result(result) - .isSuccessful(sucessful); - if (!errors.isEmpty()) { - builder.errors(errors); - } - final RpcResult rpcResult = builder.build(); -// when(brokerFacade.invokeRpc(any(QName.class), any(CompositeNode.class))).thenReturn( -// Futures.> immediateFuture(rpcResult)); - } - - /** - * @deprecated has to be removed for lithium release - */ - @Deprecated - private void mockInvokeRpc(final CompositeNode result, final boolean sucessful) { - mockInvokeRpc(result, sucessful, Collections. emptyList()); - } - - private void mockCommitConfigurationDataPostMethod(final boolean succesfulComit) { - if (succesfulComit) { - doReturn(mock(CheckedFuture.class)).when(brokerFacade).commitConfigurationDataPost(any(YangInstanceIdentifier.class), any(NormalizedNode.class)); - } else { - doThrow(RestconfDocumentedException.class).when(brokerFacade).commitConfigurationDataPost( - any(YangInstanceIdentifier.class), any(NormalizedNode.class)); - } - } - + @SuppressWarnings("unchecked") @Test @Ignore //jenkins has problem with JerseyTest - we expecting problems with singletons ControllerContext as schemaContext holder public void createConfigurationDataTest() throws UnsupportedEncodingException, ParseException { @@ -242,10 +137,11 @@ public class RestPostOperationTest extends JerseyTest { final RpcResult rpcResult = new DummyRpcResult.Builder().result( TransactionStatus.COMMITED).build(); - when(brokerFacade.commitConfigurationDataPost(any(YangInstanceIdentifier.class), any(NormalizedNode.class))) + when(brokerFacade.commitConfigurationDataPost((SchemaContext)null, any(YangInstanceIdentifier.class), any(NormalizedNode.class))) .thenReturn(mock(CheckedFuture.class)); final ArgumentCaptor instanceIdCaptor = ArgumentCaptor.forClass(YangInstanceIdentifier.class); + @SuppressWarnings("rawtypes") final ArgumentCaptor compNodeCaptor = ArgumentCaptor.forClass(NormalizedNode.class); @@ -261,7 +157,7 @@ public class RestPostOperationTest extends JerseyTest { // FIXME : NEVER test a nr. of call some service in complex test suite // verify(brokerFacade, times(2)) verify(brokerFacade, times(1)) - .commitConfigurationDataPost(instanceIdCaptor.capture(), compNodeCaptor.capture()); + .commitConfigurationDataPost((SchemaContext)null, instanceIdCaptor.capture(), compNodeCaptor.capture()); // identifier = "[(urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)interfaces, (urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)block]"; assertEquals(identifier, ImmutableList.copyOf(instanceIdCaptor.getValue().getPathArguments()).toString()); } @@ -270,7 +166,7 @@ public class RestPostOperationTest extends JerseyTest { public void createConfigurationDataNullTest() throws UnsupportedEncodingException { initMocking(); - when(brokerFacade.commitConfigurationDataPost(any(YangInstanceIdentifier.class),any(NormalizedNode.class))) + when(brokerFacade.commitConfigurationDataPost(any(SchemaContext.class), any(YangInstanceIdentifier.class),any(NormalizedNode.class))) .thenReturn(Futures.immediateCheckedFuture(null)); //FIXME : find who is set schemaContext @@ -311,18 +207,11 @@ public class RestPostOperationTest extends JerseyTest { final String xmlPathTestInterface = RestconfImplTest.class.getResource("/test-config-data/xml/test-interface.xml") .getPath(); xmlTestInterface = TestUtils.loadTextFile(xmlPathTestInterface); - cnSnDataOutput = prepareCnSnRpcOutput(); +// cnSnDataOutput = prepareCnSnRpcOutput(); final String data3Input = RestconfImplTest.class.getResource("/full-versions/test-data2/data3.xml").getPath(); xmlData3 = TestUtils.loadTextFile(data3Input); final String data4Input = RestconfImplTest.class.getResource("/full-versions/test-data2/data7.xml").getPath(); xmlData4 = TestUtils.loadTextFile(data4Input); } - private static CompositeNodeWrapper prepareCnSnRpcOutput() throws URISyntaxException { - final CompositeNodeWrapper cnSnDataOutput = new CompositeNodeWrapper(new URI("test:module"), "output"); - final CompositeNodeWrapper cont = new CompositeNodeWrapper(new URI("test:module"), "cont-output"); - cnSnDataOutput.addValue(cont); - cnSnDataOutput.unwrap(); - return cnSnDataOutput; - } }