@Produces({ Draft02.MediaTypes.OPERATION + JSON, Draft02.MediaTypes.OPERATION + XML,
Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_XML, MediaType.TEXT_XML })
- @Deprecated // method isn't use anywhere
public NormalizedNodeContext invokeRpc(@Encoded @PathParam("identifier") String identifier,
@DefaultValue("") String noPayload, @Context UriInfo uriInfo);
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.util.EmptyType;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
@Override
public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
+ Preconditions.checkArgument(payload.getInstanceIdentifierContext().getSchemaNode() != null);
+ Preconditions.checkArgument(payload.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
final SchemaPath type = payload.getInstanceIdentifierContext().getSchemaNode().getPath();
final URI namespace = payload.getInstanceIdentifierContext().getSchemaNode().getQName().getNamespace();
final CheckedFuture<DOMRpcResult, DOMRpcException> response;
}
final DOMRpcResult result = checkRpcResponse(response);
+ final RpcDefinition rpcSchemaNode = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
- RpcDefinition resultNodeSchema = null;
- final NormalizedNode<?, ?> resultData = result.getResult();
- if (result != null && result.getResult() != null) {
- resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
- }
-
- return new NormalizedNodeContext(new InstanceIdentifierContext<RpcDefinition>(null,
- resultNodeSchema, mountPoint, schemaContext), resultData,
- QueryParametersParser.parseWriterParameters(uriInfo));
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcSchemaNode, mountPoint,
+ schemaContext), result.getResult(), QueryParametersParser.parseWriterParameters(uriInfo));
}
- private DOMRpcResult checkRpcResponse(final CheckedFuture<DOMRpcResult, DOMRpcException> response) {
+ private static DOMRpcResult checkRpcResponse(final CheckedFuture<DOMRpcResult, DOMRpcException> response) {
if (response == null) {
return null;
}
}
if (cause instanceof IllegalArgumentException) {
- throw new RestconfDocumentedException(cause.getMessage(), ErrorType.PROTOCOL,
- ErrorTag.INVALID_VALUE);
+ throw new RestconfDocumentedException(cause.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.",cause);
- } else {
- throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.",e);
}
+ throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.", e);
} catch (final CancellationException e) {
final String errMsg = "The operation was cancelled while executing.";
LOG.debug("Cancel RpcExecution: " + errMsg, e);
}
}
- private void validateInput(final SchemaNode inputSchema, final NormalizedNodeContext payload) {
+ private static void validateInput(final SchemaNode inputSchema, final NormalizedNodeContext payload) {
if (inputSchema != null && payload.getData() == null) {
// expected a non null payload
throw new RestconfDocumentedException("Input is required.", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
- final QName outputQname = QName.create(rpcQName, "output");
+ final RpcDefinition rpcSchemaNode = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
+ RestconfValidationUtils.checkDocumentedError(rpcSchemaNode != null, ErrorType.RPC, ErrorTag.INVALID_VALUE,
+ "Create stream RPC output can not be null!");
+
+ final QName outputQname = rpcSchemaNode.getOutput().getQName();
final QName streamNameQname = QName.create(rpcQName, "stream-name");
final ContainerNode output = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(outputQname))
}
final DOMRpcResult defaultDOMRpcResult = new DefaultDOMRpcResult(output);
-
return Futures.immediateCheckedFuture(defaultDOMRpcResult);
}
final DOMRpcResult result = checkRpcResponse(response);
- DataSchemaNode resultNodeSchema = null;
- NormalizedNode<?, ?> resultData = null;
- if (result != null && result.getResult() != null) {
- resultData = result.getResult();
- final ContainerSchemaNode rpcDataSchemaNode =
- SchemaContextUtil.getRpcDataSchema(schemaContext, rpc.getOutput().getPath());
- resultNodeSchema = rpcDataSchemaNode.getDataChildByName(result.getResult().getNodeType());
- }
-
- return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, resultNodeSchema, mountPoint,
- schemaContext), resultData, QueryParametersParser.parseWriterParameters(uriInfo));
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpc, mountPoint, schemaContext),
+ result.getResult(), QueryParametersParser.parseWriterParameters(uriInfo));
}
- private RpcDefinition findRpc(final SchemaContext schemaContext, final String identifierDecoded) {
+ private static RpcDefinition findRpc(final SchemaContext schemaContext, final String identifierDecoded) {
final String[] splittedIdentifier = identifierDecoded.split(":");
if (splittedIdentifier.length != 2) {
final String errMsg = identifierDecoded + " couldn't be splitted to 2 parts (module:rpc name)";
return Response.status(Status.OK).build();
}
- private void validateTopLevelNodeName(final NormalizedNodeContext node,
+ private static void validateTopLevelNodeName(final NormalizedNodeContext node,
final YangInstanceIdentifier identifier) {
final String payloadName = node.getData().getNodeType().getLocalName();
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
import java.lang.reflect.Field;
import java.util.Collections;
-
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
-
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.controller.sal.rest.api.RestconfConstants;
import org.opendaylight.controller.sal.rest.impl.AbstractIdentifierAwareJaxRsProvider;
*/
public abstract class AbstractBodyReaderTest {
- protected final static ControllerContext controllerContext = ControllerContext
- .getInstance();
+ protected final static ControllerContext controllerContext = ControllerContext.getInstance();
protected final MediaType mediaType;
private static Field uriField;
private static Field requestField;
- public AbstractBodyReaderTest() throws NoSuchFieldException,
- SecurityException {
- uriField = AbstractIdentifierAwareJaxRsProvider.class
- .getDeclaredField("uriInfo");
+ public AbstractBodyReaderTest() throws NoSuchFieldException, SecurityException {
+ uriField = AbstractIdentifierAwareJaxRsProvider.class.getDeclaredField("uriInfo");
+ requestField = AbstractIdentifierAwareJaxRsProvider.class.getDeclaredField("request");
uriField.setAccessible(true);
- requestField = AbstractIdentifierAwareJaxRsProvider.class
- .getDeclaredField("request");
requestField.setAccessible(true);
mediaType = getMediaType();
}
protected abstract MediaType getMediaType();
- protected static SchemaContext schemaContextLoader(final String yangPath,
- final SchemaContext schemaContext) {
+ protected static SchemaContext schemaContextLoader(final String yangPath, final SchemaContext schemaContext) {
return TestRestconfUtils.loadSchemaContext(yangPath, schemaContext);
}
- protected static <T extends AbstractIdentifierAwareJaxRsProvider> void mockBodyReader(
- final String identifier, final T normalizedNodeProvider,
- final boolean isPost) throws NoSuchFieldException,
- SecurityException, IllegalArgumentException, IllegalAccessException {
+ protected static <T extends AbstractIdentifierAwareJaxRsProvider> UriInfo mockBodyReader(
+ final String identifier, final T normalizedNodeProvider, final boolean isPost) throws Exception {
final UriInfo uriInfoMock = mock(UriInfo.class);
- final MultivaluedMap<String, String> pathParm = new MultivaluedHashMap<>(
- 1);
- pathParm.put(RestconfConstants.IDENTIFIER,
- Collections.singletonList(identifier));
+ final MultivaluedMap<String, String> pathParm = new MultivaluedHashMap<>(1);
+ pathParm.put(RestconfConstants.IDENTIFIER, Collections.singletonList(identifier));
+ when(uriInfoMock.getQueryParameters()).thenReturn(pathParm);
when(uriInfoMock.getPathParameters()).thenReturn(pathParm);
when(uriInfoMock.getPathParameters(false)).thenReturn(pathParm);
+ when(uriInfoMock.getQueryParameters(false)).thenReturn(pathParm);
when(uriInfoMock.getPathParameters(true)).thenReturn(pathParm);
+ when(uriInfoMock.getQueryParameters(true)).thenReturn(pathParm);
uriField.set(normalizedNodeProvider, uriInfoMock);
final Request request = mock(Request.class);
if (isPost) {
when(request.getMethod()).thenReturn("PUT");
}
requestField.set(normalizedNodeProvider, request);
+ return uriInfoMock;
}
- protected static void checkMountPointNormalizedNodeContext(
- final NormalizedNodeContext nnContext) {
+ protected static void checkMountPointNormalizedNodeContext(final NormalizedNodeContext nnContext) {
checkNormalizedNodeContext(nnContext);
assertNotNull(nnContext.getInstanceIdentifierContext().getMountPoint());
}
- protected static void checkNormalizedNodeContext(
- final NormalizedNodeContext nnContext) {
+ protected static void checkNormalizedNodeContext(final NormalizedNodeContext nnContext) {
assertNotNull(nnContext.getData());
- assertNotNull(nnContext.getInstanceIdentifierContext()
- .getInstanceIdentifier());
- assertNotNull(nnContext.getInstanceIdentifierContext()
- .getSchemaContext());
+ assertNotNull(nnContext.getInstanceIdentifierContext().getInstanceIdentifier());
+ assertNotNull(nnContext.getInstanceIdentifierContext().getSchemaContext());
assertNotNull(nnContext.getInstanceIdentifierContext().getSchemaNode());
}
}
--- /dev/null
+package org.opendaylight.controller.sal.rest.impl.test.providers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import com.google.common.base.Optional;
+import com.google.common.base.Strings;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collections;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
+import org.opendaylight.controller.sal.rest.api.RestconfService;
+import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
+import org.opendaylight.controller.sal.rest.impl.NormalizedNodeJsonBodyWriter;
+import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
+import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+public class TestInvokeMountPointRpc extends AbstractBodyReaderTest {
+
+ private final JsonNormalizedNodeBodyReader jsonBodyReader;
+ private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
+ private final RestconfService restconfService;
+ private final BrokerFacade brokerFacade;
+ private static SchemaContext schemaContext;
+ private final DOMRpcService rpcService;
+
+ public TestInvokeMountPointRpc() throws NoSuchFieldException, SecurityException {
+ super();
+ jsonBodyReader = new JsonNormalizedNodeBodyReader();
+ jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
+ BrokerFacade.getInstance().setContext(mock(ConsumerSession.class));
+ BrokerFacade.getInstance().setDomDataBroker(mock(DOMDataBroker.class));
+ rpcService = mock(DOMRpcService.class);
+ BrokerFacade.getInstance().setRpcService(rpcService);
+ brokerFacade = BrokerFacade.getInstance();
+ RestconfImpl.getInstance().setBroker(brokerFacade);
+ RestconfImpl.getInstance().setControllerContext(controllerContext);
+ restconfService = RestconfImpl.getInstance();
+ }
+
+ @Override
+ protected MediaType getMediaType() {
+ return new MediaType(MediaType.APPLICATION_JSON, null);
+ }
+
+ /**
+ * SchemaContext for RPCs initialization
+ *
+ * @throws NoSuchFieldException
+ * @throws SecurityException
+ */
+ @Before
+ public void initialization() throws NoSuchFieldException, SecurityException {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+ schemaContext = schemaContextLoader("/modules", schemaContext);
+ schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
+ final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
+ when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
+ when(mountInstance.getService(DOMRpcService.class)).thenReturn(Optional.<DOMRpcService> of(rpcService));
+ final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
+ when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
+
+ ControllerContext.getInstance().setMountService(mockMountService);
+ controllerContext.setSchemas(schemaContext);
+ }
+
+ /**
+ * Test RPC with Input and Output schemaNode definitions
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleInputOutputTest() throws Exception {
+ final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-test";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+
+ final NormalizedNodeContext inputCx = parseRpcInput("/invoke-rpc/json/rpc-input.json");
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+ final NormalizedNode<?, ?> outNormNode = parseRpcOutput("/invoke-rpc/json/rpc-output.json");
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(outNormNode);
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, inputCx, uriInfo);
+ assertNotNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(), rpcResultCx.getInstanceIdentifierContext()
+ .getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(output.toString().contains("lf-test"));
+ }
+
+ /**
+ * Test RPC without Input but with Output schemaNode definitions
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleNoInputOutputTest() throws Exception {
+ final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-output-only-test";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput(null);
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+ final NormalizedNode<?, ?> outNormNode = parseRpcOutput("/invoke-rpc/json/rpc-output.json");
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(outNormNode);
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, inputCx, uriInfo);
+ assertNotNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(), rpcResultCx.getInstanceIdentifierContext()
+ .getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(output.toString().contains("lf-test"));
+ }
+
+ /**
+ * Test RPC without Input but with Output schemaNode definitions post without ContentType
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleNoInputOutputWithoutContentTypeTest() throws Exception {
+ final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-output-only-test";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput(null);
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+ final NormalizedNode<?, ?> outNormNode = parseRpcOutput("/invoke-rpc/json/rpc-output.json");
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(outNormNode);
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, "", uriInfo);
+ assertNotNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(), rpcResultCx.getInstanceIdentifierContext()
+ .getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(output.toString().contains("lf-test"));
+ }
+
+ /**
+ * Test RPC with Input but without Output schemaNode definitions
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleInputNoOutputTest() throws Exception {
+ final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-input-only-test";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput("/invoke-rpc/json/rpc-input.json");
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(null, Collections.<RpcError> emptyList());
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, inputCx, uriInfo);
+ assertNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(), rpcResultCx.getInstanceIdentifierContext()
+ .getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(Strings.isNullOrEmpty(output.toString()));
+ }
+
+ /**
+ * Test RPC without Input and Output schemaNode definitions
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleNoInputNoOutputTest() throws Exception {
+ final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-noop";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput(null);
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(null, Collections.<RpcError> emptyList());
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, inputCx, uriInfo);
+ assertNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(), rpcResultCx.getInstanceIdentifierContext()
+ .getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(Strings.isNullOrEmpty(output.toString()));
+ }
+
+ /**
+ * Test RPC without Input but with Output schemaNode definitions post without ContentType
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleNoInputNoOutputWithoutContentTypeTest() throws Exception {
+ final String uri = "invoke-rpc-module:rpc-noop";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput(null);
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(null, Collections.<RpcError> emptyList());
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, "", uriInfo);
+ assertNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(), rpcResultCx.getInstanceIdentifierContext()
+ .getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(Strings.isNullOrEmpty(output.toString()));
+ }
+
+ private NormalizedNodeContext parseRpcInput(final String filePath) throws WebApplicationException, IOException {
+ final InputStream inStrem;
+ if (Strings.isNullOrEmpty(filePath)) {
+ inStrem = new ByteArrayInputStream("".getBytes());
+ } else {
+ inStrem = TestInvokeRpc.class.getResourceAsStream(filePath);
+ }
+ return jsonBodyReader.readFrom(null, null, null, mediaType, null, inStrem);
+ }
+
+ private NormalizedNode<?, ?> parseRpcOutput(final String filePath) throws WebApplicationException, IOException {
+ final InputStream inStrem = TestInvokeRpc.class.getResourceAsStream(filePath);
+ return jsonBodyReader.readFrom(null, null, null, mediaType, null, inStrem).getData();
+ }
+}
--- /dev/null
+package org.opendaylight.controller.sal.rest.impl.test.providers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import com.google.common.base.Strings;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collections;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
+import org.opendaylight.controller.sal.rest.api.RestconfService;
+import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
+import org.opendaylight.controller.sal.rest.impl.NormalizedNodeJsonBodyWriter;
+import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+public class TestInvokeRpc extends AbstractBodyReaderTest {
+
+ private final JsonNormalizedNodeBodyReader jsonBodyReader;
+ private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
+ private final RestconfService restconfService;
+ private final BrokerFacade brokerFacade;
+ private static SchemaContext schemaContext;
+ private final DOMRpcService rpcService;
+
+ public TestInvokeRpc() throws NoSuchFieldException, SecurityException {
+ super();
+ jsonBodyReader = new JsonNormalizedNodeBodyReader();
+ jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
+ BrokerFacade.getInstance().setContext(mock(ConsumerSession.class));
+ BrokerFacade.getInstance().setDomDataBroker(mock(DOMDataBroker.class));
+ rpcService = mock(DOMRpcService.class);
+ BrokerFacade.getInstance().setRpcService(rpcService);
+ brokerFacade = BrokerFacade.getInstance();
+ RestconfImpl.getInstance().setBroker(brokerFacade);
+ RestconfImpl.getInstance().setControllerContext(controllerContext);
+ restconfService = RestconfImpl.getInstance();
+ }
+
+ @Override
+ protected MediaType getMediaType() {
+ return new MediaType(MediaType.APPLICATION_JSON, null);
+ }
+
+ /**
+ * SchemaContext for RPCs initialization
+ *
+ * @throws NoSuchFieldException
+ * @throws SecurityException
+ */
+ @BeforeClass
+ public static void initialization() throws NoSuchFieldException, SecurityException {
+ schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
+ controllerContext.setSchemas(schemaContext);
+ }
+
+ /**
+ * Test RPC with Input and Output schemaNode definitions
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleInputOutputTest() throws Exception {
+ final String uri = "invoke-rpc-module:rpc-test";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+
+ final NormalizedNodeContext inputCx = parseRpcInput("/invoke-rpc/json/rpc-input.json");
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+ final NormalizedNode<?, ?> outNormNode = parseRpcOutput("/invoke-rpc/json/rpc-output.json");
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(outNormNode);
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, inputCx, uriInfo);
+ assertNotNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(),
+ rpcResultCx.getInstanceIdentifierContext().getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(output.toString().contains("lf-test"));
+ }
+
+ /**
+ * Test RPC without Input but with Output schemaNode definitions
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleNoInputOutputTest() throws Exception {
+ final String uri = "invoke-rpc-module:rpc-output-only-test";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput(null);
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+ final NormalizedNode<?, ?> outNormNode = parseRpcOutput("/invoke-rpc/json/rpc-output.json");
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(outNormNode);
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, inputCx, uriInfo);
+ assertNotNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(),
+ rpcResultCx.getInstanceIdentifierContext().getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(output.toString().contains("lf-test"));
+ }
+
+ /**
+ * Test RPC without Input but with Output schemaNode definitions post without ContentType
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleNoInputOutputWithoutContentTypeTest() throws Exception {
+ final String uri = "invoke-rpc-module:rpc-output-only-test";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput(null);
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+ final NormalizedNode<?, ?> outNormNode = parseRpcOutput("/invoke-rpc/json/rpc-output.json");
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(outNormNode);
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, "", uriInfo);
+ assertNotNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(),
+ rpcResultCx.getInstanceIdentifierContext().getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(output.toString().contains("lf-test"));
+ }
+
+ /**
+ * Test RPC with Input but without Output schemaNode definitions
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleInputNoOutputTest() throws Exception {
+ final String uri = "invoke-rpc-module:rpc-input-only-test";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput("/invoke-rpc/json/rpc-input.json");
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(null, Collections.<RpcError> emptyList());
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, inputCx, uriInfo);
+ assertNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(),
+ rpcResultCx.getInstanceIdentifierContext().getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(Strings.isNullOrEmpty(output.toString()));
+ }
+
+ /**
+ * Test RPC without Input and Output schemaNode definitions
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleNoInputNoOutputTest() throws Exception {
+ final String uri = "invoke-rpc-module:rpc-noop";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput(null);
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(null, Collections.<RpcError> emptyList());
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, inputCx, uriInfo);
+ assertNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(), rpcResultCx.getInstanceIdentifierContext()
+ .getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(Strings.isNullOrEmpty(output.toString()));
+ }
+
+ /**
+ * Test RPC without Input but with Output schemaNode definitions post without ContentType
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rpcModuleNoInputNoOutputWithoutContentTypeTest() throws Exception {
+ final String uri = "invoke-rpc-module:rpc-noop";
+ final UriInfo uriInfo = mockBodyReader(uri, jsonBodyReader, true);
+ final NormalizedNodeContext inputCx = parseRpcInput(null);
+ final SchemaPath schemaNodePath = inputCx.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final NormalizedNode<?, ?> inNormNode = inputCx.getData();
+
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(null, Collections.<RpcError> emptyList());
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcReturn = Futures.immediateCheckedFuture(rpcResult);
+ when(rpcService.invokeRpc(schemaNodePath, inNormNode)).thenReturn(rpcReturn);
+
+ final NormalizedNodeContext rpcResultCx = restconfService.invokeRpc(uri, "", uriInfo);
+ assertNull(rpcResultCx.getData());
+ assertTrue(rpcResultCx.getInstanceIdentifierContext().getSchemaNode() instanceof RpcDefinition);
+ assertEquals(inputCx.getInstanceIdentifierContext().getSchemaNode(), rpcResultCx.getInstanceIdentifierContext()
+ .getSchemaNode());
+ final OutputStream output = new ByteArrayOutputStream();
+ jsonBodyWriter.writeTo(rpcResultCx, null, null, null, mediaType, null, output);
+ assertTrue(Strings.isNullOrEmpty(output.toString()));
+ }
+
+ private NormalizedNodeContext parseRpcInput(final String filePath) throws WebApplicationException, IOException {
+ final InputStream inStrem;
+ if (Strings.isNullOrEmpty(filePath)) {
+ inStrem = new ByteArrayInputStream("".getBytes());
+ } else {
+ inStrem = TestInvokeRpc.class.getResourceAsStream(filePath);
+ }
+ return jsonBodyReader.readFrom(null, null, null, mediaType, null, inStrem);
+ }
+
+ private NormalizedNode<?, ?> parseRpcOutput(final String filePath) throws WebApplicationException, IOException {
+ final InputStream inStrem = TestInvokeRpc.class.getResourceAsStream(filePath);
+ return jsonBodyReader.readFrom(null, null, null, mediaType, null, inStrem).getData();
+ }
+}
@Override
protected MediaType getMediaType() {
- return new MediaType(MediaType.APPLICATION_XML, null);
+ return new MediaType(MediaType.APPLICATION_JSON, null);
}
@BeforeClass
@Test
public void moduleSubContainerDataPutTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
- QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
final String uri = "instance-identifier-module:cont/cont1";
@Test
public void moduleSubContainerDataPostTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
- QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, true);
public void moduleSubContainerAugmentDataPostTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
- QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
- YangInstanceIdentifier.AugmentationIdentifier augII = new YangInstanceIdentifier.AugmentationIdentifier(
+ final QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
+ final YangInstanceIdentifier.AugmentationIdentifier augII = new YangInstanceIdentifier.AugmentationIdentifier(
Sets.newHashSet(contAugmentQName));
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
.node(augII).node(contAugmentQName);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
- //FIXME: Uncomment this when JsonParserStream works correctly with case augmentation with choice
- //@Test
+ @Test
public void moduleSubContainerChoiceAugmentDataPostTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
- QName augmentChoice1QName = QName.create(augmentModule.getQNameModule(), "augment-choice1");
- QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
+ final QName augmentChoice1QName = QName.create(augmentModule.getQNameModule(), "augment-choice1");
+ final QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
final QName containerQName = QName.create(augmentChoice1QName, "case-choice-case-container1");
- YangInstanceIdentifier.AugmentationIdentifier augChoice1II = new YangInstanceIdentifier.AugmentationIdentifier(
+ final YangInstanceIdentifier.AugmentationIdentifier augChoice1II = new YangInstanceIdentifier.AugmentationIdentifier(
Sets.newHashSet(augmentChoice1QName));
- YangInstanceIdentifier.AugmentationIdentifier augChoice2II = new YangInstanceIdentifier.AugmentationIdentifier(
+ final YangInstanceIdentifier.AugmentationIdentifier augChoice2II = new YangInstanceIdentifier.AugmentationIdentifier(
Sets.newHashSet(augmentChoice2QName));
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
.node(augChoice1II).node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName)
package org.opendaylight.controller.sal.rest.impl.test.providers;
import static org.junit.Assert.assertTrue;
-
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
-
import javax.ws.rs.core.MediaType;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
@Override
protected MediaType getMediaType() {
- return new MediaType(MediaType.APPLICATION_XML, null);
+ return new MediaType(MediaType.APPLICATION_JSON, null);
}
@BeforeClass
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
import java.io.InputStream;
-
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
}
@Test
- public void jsonIdentityrefToNn() throws NoSuchFieldException,
- SecurityException, IllegalArgumentException,
- IllegalAccessException, WebApplicationException, IOException {
+ public void jsonIdentityrefToNn() throws Exception {
- String uri = "identityref-module:cont";
+ final String uri = "identityref-module:cont";
mockBodyReader(uri, jsonBodyReader, false);
- InputStream inputStream = this.getClass().getResourceAsStream(
+ final InputStream inputStream = this.getClass().getResourceAsStream(
"/json-to-nn/identityref/json/data.json");
- NormalizedNodeContext normalizedNodeContext = jsonBodyReader.readFrom(
+ final NormalizedNodeContext normalizedNodeContext = jsonBodyReader.readFrom(
null, null, null, mediaType, null, inputStream);
assertEquals("cont", normalizedNodeContext.getData().getNodeType()
.getLocalName());
- String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
+ final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
.getData());
assertTrue(dataTree.contains("cont1"));
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
import java.io.InputStream;
-
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
}
@Test
- public void jsonIdentityrefToNormalizeNode() throws NoSuchFieldException,
- SecurityException, IllegalArgumentException,
- IllegalAccessException, WebApplicationException, IOException {
+ public void jsonIdentityrefToNormalizeNode() throws Exception {
- String uri = "leafref-module:cont";
+ final String uri = "leafref-module:cont";
mockBodyReader(uri, jsonBodyReader, false);
- InputStream inputStream = this.getClass().getResourceAsStream(
+ final InputStream inputStream = this.getClass().getResourceAsStream(
"/json-to-nn/leafref/json/data.json");
- NormalizedNodeContext normalizedNodeContext = jsonBodyReader.readFrom(
+ final NormalizedNodeContext normalizedNodeContext = jsonBodyReader.readFrom(
null, null, null, mediaType, null, inputStream);
assertEquals("cont", normalizedNodeContext.getData().getNodeType()
.getLocalName());
- String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
+ final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
.getData());
assertTrue(dataTree.contains("lf2 121"));
}
super();
}
- public static void initialize(String path, SchemaContext schemaContext) {
+ public static void initialize(final String path, SchemaContext schemaContext) {
schemaContext = schemaContextLoader(path, schemaContext);
controllerContext.setSchemas(schemaContext);
}
@Test
- public void simpleListTest() {
+ public void simpleListTest() throws Exception {
simpleTest("/json-to-nn/simple-list.json",
"/json-to-nn/simple-list-yang/1", "lst", "simple-list-yang1");
}
@Test
- public void simpleContainerTest() {
+ public void simpleContainerTest() throws Exception {
simpleTest("/json-to-nn/simple-container.json",
"/json-to-nn/simple-container-yang", "cont",
"simple-container-yang");
}
@Test
- public void multipleItemsInLeafListTest() {
+ public void multipleItemsInLeafListTest() throws Exception {
initialize("/json-to-nn/simple-list-yang/1", schemaContext);
- NormalizedNodeContext normalizedNodeContext = prepareNNC(
+ final NormalizedNodeContext normalizedNodeContext = prepareNNC(
"/json-to-nn/multiple-leaflist-items.json",
"simple-list-yang1:lst");
assertNotNull(normalizedNodeContext);
- String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
+ final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
.getData());
assertTrue(dataTree.contains("45"));
assertTrue(dataTree.contains("55"));
}
@Test
- public void multipleItemsInListTest() {
+ public void multipleItemsInListTest() throws Exception {
initialize("/json-to-nn/simple-list-yang/3", schemaContext);
- NormalizedNodeContext normalizedNodeContext = prepareNNC(
+ final NormalizedNodeContext normalizedNodeContext = prepareNNC(
"/json-to-nn/multiple-items-in-list.json",
"multiple-items-yang:lst");
assertNotNull(normalizedNodeContext);
}
@Test
- public void nullArrayToSimpleNodeWithNullValueTest() {
+ public void nullArrayToSimpleNodeWithNullValueTest() throws Exception {
initialize("/json-to-nn/simple-list-yang/4", schemaContext);
- NormalizedNodeContext normalizedNodeContext = prepareNNC(
+ final NormalizedNodeContext normalizedNodeContext = prepareNNC(
"/json-to-nn/array-with-null.json", "array-with-null-yang:cont");
assertNotNull(normalizedNodeContext);
assertEquals("cont", normalizedNodeContext.getData().getNodeType()
.getLocalName());
- String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
+ final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
.getData());
assertTrue(dataTree.contains("lf"));
assertTrue(dataTree.contains("null"));
}
@Test
- public void incorrectTopLevelElementsTest() throws WebApplicationException,
- IOException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException {
+ public void incorrectTopLevelElementsTest() throws Exception {
jsonBodyReader = new JsonNormalizedNodeBodyReader();
initialize("/json-to-nn/simple-list-yang/1", schemaContext);
try {
jsonBodyReader.readFrom(null, null, null, mediaType, null,
inputStream);
- } catch (RestconfDocumentedException e) {
+ } catch (final RestconfDocumentedException e) {
exception = e;
countExceptions++;
}
try {
jsonBodyReader.readFrom(null, null, null, mediaType, null,
inputStream);
- } catch (RestconfDocumentedException e) {
+ } catch (final RestconfDocumentedException e) {
exception = e;
countExceptions++;
}
try {
jsonBodyReader.readFrom(null, null, null, mediaType, null,
inputStream);
- } catch (RestconfDocumentedException e) {
+ } catch (final RestconfDocumentedException e) {
exception = e;
countExceptions++;
}
}
@Test
- public void emptyDataReadTest() throws WebApplicationException,
- IOException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException {
+ public void emptyDataReadTest() throws Exception {
initialize("/json-to-nn/simple-list-yang/4", schemaContext);
- NormalizedNodeContext normalizedNodeContext = prepareNNC(
+ final NormalizedNodeContext normalizedNodeContext = prepareNNC(
"/json-to-nn/empty-data.json", "array-with-null-yang:cont");
assertNotNull(normalizedNodeContext);
assertEquals("cont", normalizedNodeContext.getData().getNodeType()
.getLocalName());
- String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
+ final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
.getData());
assertTrue(dataTree.contains("lflst1"));
jsonBodyReader = new JsonNormalizedNodeBodyReader();
RestconfDocumentedException exception = null;
mockBodyReader("array-with-null-yang:cont", jsonBodyReader, false);
- InputStream inputStream = this.getClass().getResourceAsStream(
+ final InputStream inputStream = this.getClass().getResourceAsStream(
"/json-to-nn/empty-data.json1");
try {
jsonBodyReader.readFrom(null, null, null, mediaType, null,
inputStream);
- } catch (RestconfDocumentedException e) {
+ } catch (final RestconfDocumentedException e) {
exception = e;
}
assertNotNull(exception);
}
@Test
- public void testJsonBlankInput() throws NoSuchFieldException,
- SecurityException, IllegalArgumentException,
- IllegalAccessException, WebApplicationException, IOException {
+ public void testJsonBlankInput() throws Exception {
initialize("/json-to-nn/simple-list-yang/4", schemaContext);
- NormalizedNodeContext normalizedNodeContext = prepareNNC("",
+ final NormalizedNodeContext normalizedNodeContext = prepareNNC("",
"array-with-null-yang:cont");
assertNull(normalizedNodeContext);
}
@Test
- public void notSupplyNamespaceIfAlreadySupplied()
- throws WebApplicationException, IOException, NoSuchFieldException,
- SecurityException, IllegalArgumentException, IllegalAccessException {
+ public void notSupplyNamespaceIfAlreadySupplied() throws Exception {
initialize("/json-to-nn/simple-list-yang/1", schemaContext);
- String uri = "simple-list-yang1" + ":" + "lst";
+ final String uri = "simple-list-yang1" + ":" + "lst";
- NormalizedNodeContext normalizedNodeContext = prepareNNC(
+ final NormalizedNodeContext normalizedNodeContext = prepareNNC(
"/json-to-nn/simple-list.json", uri);
assertNotNull(normalizedNodeContext);
verifyNormaluizedNodeContext(normalizedNodeContext, "lst");
mockBodyReader("simple-list-yang2:lst", jsonBodyReader, false);
- InputStream inputStream = this.getClass().getResourceAsStream(
+ final InputStream inputStream = this.getClass().getResourceAsStream(
"/json-to-nn/simple-list.json");
try {
jsonBodyReader.readFrom(null, null, null, mediaType, null,
inputStream);
fail("NormalizedNodeContext should not be create because of different namespace");
- } catch (RestconfDocumentedException e) {
+ } catch (final RestconfDocumentedException e) {
}
verifyNormaluizedNodeContext(normalizedNodeContext, "lst");
}
@Test
- public void dataAugmentedTest() {
+ public void dataAugmentedTest() throws Exception {
initialize("/common/augment/yang", schemaContext);
}
private void simpleTest(final String jsonPath, final String yangPath,
- final String topLevelElementName, final String moduleName) {
+ final String topLevelElementName,
+ final String moduleName) throws Exception {
initialize(yangPath, schemaContext);
- String uri = moduleName + ":" + topLevelElementName;
+ final String uri = moduleName + ":" + topLevelElementName;
- NormalizedNodeContext normalizedNodeContext = prepareNNC(jsonPath, uri);
+ final NormalizedNodeContext normalizedNodeContext = prepareNNC(jsonPath, uri);
assertNotNull(normalizedNodeContext);
verifyNormaluizedNodeContext(normalizedNodeContext, topLevelElementName);
}
- private NormalizedNodeContext prepareNNC(String jsonPath, String uri) {
+ private NormalizedNodeContext prepareNNC(final String jsonPath, final String uri) throws Exception {
jsonBodyReader = new JsonNormalizedNodeBodyReader();
try {
mockBodyReader(uri, jsonBodyReader, false);
// TODO Auto-generated catch block
e.printStackTrace();
}
- InputStream inputStream = this.getClass().getResourceAsStream(jsonPath);
+ final InputStream inputStream = this.getClass().getResourceAsStream(jsonPath);
NormalizedNodeContext normalizedNodeContext = null;
}
private void verifyNormaluizedNodeContext(
- NormalizedNodeContext normalizedNodeContext,
- String topLevelElementName) {
+ final NormalizedNodeContext normalizedNodeContext,
+ final String topLevelElementName) {
assertEquals(topLevelElementName, normalizedNodeContext.getData()
.getNodeType().getLocalName());
- String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
+ final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
.getData());
assertTrue(dataTree.contains("cont1"));
assertTrue(dataTree.contains("lst1"));
private void verityMultipleItemsInList(
final NormalizedNodeContext normalizedNodeContext) {
- String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
+ final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
.getData());
assertTrue(dataTree.contains("lf11"));
assertTrue(dataTree.contains("lf11_1"));
}
@Test
- public void unsupportedDataFormatTest() throws NoSuchFieldException,
- SecurityException, IllegalArgumentException,
- IllegalAccessException, WebApplicationException, IOException {
+ public void unsupportedDataFormatTest() throws Exception {
jsonBodyReader = new JsonNormalizedNodeBodyReader();
initialize("/json-to-nn/simple-list-yang/1", schemaContext);
mockBodyReader("simple-list-yang1:lst", jsonBodyReader, false);
- InputStream inputStream = this.getClass().getResourceAsStream(
+ final InputStream inputStream = this.getClass().getResourceAsStream(
"/json-to-nn/unsupported-json-format.json");
RestconfDocumentedException exception = null;
try {
jsonBodyReader.readFrom(null, null, null, mediaType, null,
inputStream);
- } catch (RestconfDocumentedException e) {
+ } catch (final RestconfDocumentedException e) {
exception = e;
}
System.out.println(exception.getErrors().get(0).getErrorMessage());
}
@Test
- public void invalidUriCharacterInValue() throws NoSuchFieldException,
- SecurityException, IllegalArgumentException,
- IllegalAccessException, WebApplicationException, IOException {
+ public void invalidUriCharacterInValue() throws Exception {
jsonBodyReader = new JsonNormalizedNodeBodyReader();
initialize("/json-to-nn/simple-list-yang/4", schemaContext);
mockBodyReader("array-with-null-yang:cont", jsonBodyReader, false);
- InputStream inputStream = this.getClass().getResourceAsStream(
+ final InputStream inputStream = this.getClass().getResourceAsStream(
"/json-to-nn/invalid-uri-character-in-value.json");
- NormalizedNodeContext normalizedNodeContext = jsonBodyReader.readFrom(
+ final NormalizedNodeContext normalizedNodeContext = jsonBodyReader.readFrom(
null, null, null, mediaType, null, inputStream);
assertNotNull(normalizedNodeContext);
assertEquals("cont", normalizedNodeContext.getData().getNodeType()
.getLocalName());
- String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
+ final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
.getData());
assertTrue(dataTree.contains("lf1 module<Name:value lf1"));
assertTrue(dataTree.contains("lf2 module>Name:value lf2"));
final NormalizedNodeContext output = restconfImpl.invokeRpc("toaster:make-toast", payload, uriInfo);
assertNotNull(output);
assertEquals(null, output.getData());
+ assertEquals(rpcDef, output.getInstanceIdentifierContext().getSchemaNode());
// additional validation in the fact that the restconfImpl does not
// throw an exception.
}
assertNotNull(output);
assertNotNull(output.getData());
assertSame(container, output.getData());
+ assertEquals(rpcDef, output.getInstanceIdentifierContext().getSchemaNode());
assertNotNull(output.getInstanceIdentifierContext());
assertNotNull(output.getInstanceIdentifierContext().getSchemaContext());
}
namespace "invoke:rpc:module";
prefix "inrpcmod";
-
+
revision 2013-12-3 {
-
+
}
rpc rpc-test {
rpc rpc-noop {
}
+ rpc rpc-input-only-test {
+ input {
+ container cont {
+ leaf lf {
+ type string;
+ }
+ }
+ }
+ }
+
+ rpc rpc-output-only-test {
+ output {
+ container cont-out {
+ leaf lf-out {
+ type string;
+ }
+ }
+ }
+ }
}
\ No newline at end of file