*/
package org.opendaylight.netconf.mdsal.connector.ops;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
-import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
-import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
import com.google.common.base.Preconditions;
import com.google.common.io.ByteSource;
-import com.google.common.util.concurrent.FluentFuture;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
-import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
+import org.opendaylight.netconf.server.api.operations.HandlingPriority;
+import org.opendaylight.netconf.server.api.operations.NetconfOperationChainedExecution;
import org.opendaylight.netconf.util.test.XmlFileLoader;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.NoOpListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
private static final DOMRpcService RPC_SERVICE_VOID_INVOKER = new DOMRpcService() {
@Override
- public FluentFuture<DOMRpcResult> invokeRpc(final QName type, final NormalizedNode input) {
- return immediateFluentFuture(new DefaultDOMRpcResult(null, List.of()));
+ public ListenableFuture<DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
+ return Futures.immediateFuture(new DefaultDOMRpcResult(null, List.of()));
}
@Override
private static final DOMRpcService RPC_SERVICE_FAILED_INVOCATION = new DOMRpcService() {
@Override
- public FluentFuture<DOMRpcResult> invokeRpc(final QName type, final NormalizedNode input) {
- return immediateFailedFluentFuture(new DOMRpcException("rpc invocation not implemented yet") {
+ public ListenableFuture<DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
+ return Futures.immediateFailedFuture(new DOMRpcException("rpc invocation not implemented yet") {
private static final long serialVersionUID = 1L;
});
}
private final DOMRpcService rpcServiceSuccessfulInvocation = new DOMRpcService() {
@Override
- public FluentFuture<DOMRpcResult> invokeRpc(final QName type, final NormalizedNode input) {
- final Collection<DataContainerChild> children = ((ContainerNode) input).body();
+ public ListenableFuture<DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
+ final Collection<DataContainerChild> children = input.body();
final Module module = SCHEMA_CONTEXT.findModules(type.getNamespace()).stream()
.findFirst().orElse(null);
final RpcDefinition rpcDefinition = getRpcDefinitionFromModule(module, module.getNamespace(),
type.getLocalName());
- final OutputSchemaNode outputSchemaNode = rpcDefinition.getOutput();
- final ContainerNode node = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(outputSchemaNode.getQName()))
- .withValue(children).build();
+ final ContainerNode node = Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(rpcDefinition.getOutput().getQName()))
+ .withValue(children)
+ .build();
- return immediateFluentFuture(new DefaultDOMRpcResult(node));
+ return Futures.immediateFuture(new DefaultDOMRpcResult(node));
}
@Override
final SourceIdentifier sId = (SourceIdentifier) invocationOnMock.getArguments()[0];
final YangTextSchemaSource yangTextSchemaSource =
YangTextSchemaSource.delegateForByteSource(sId, ByteSource.wrap("module test".getBytes()));
- return immediateFluentFuture(yangTextSchemaSource);
+ return Futures.immediateFuture(yangTextSchemaSource);
}).when(sourceProvider).getSource(any(SourceIdentifier.class));
- this.currentSchemaContext = new CurrentSchemaContext(schemaService, sourceProvider);
+ currentSchemaContext = CurrentSchemaContext.create(schemaService, sourceProvider);
}
@After
@Test
public void testFailedInvocation() throws Exception {
final RuntimeRpc rpc = new RuntimeRpc(
- SESSION_ID_FOR_REPORTING, currentSchemaContext, RPC_SERVICE_FAILED_INVOCATION);
+ SESSION_ID_FOR_REPORTING, currentSchemaContext, RPC_SERVICE_FAILED_INVOCATION);
final Document rpcDocument = XmlFileLoader.xmlFileToDocument("messages/mapping/rpcs/rpc-nonvoid.xml");
final HandlingPriority priority = rpc.canHandle(rpcDocument);
Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
- try {
- rpc.handle(rpcDocument, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT);
- fail("should have failed with rpc invocation not implemented yet");
- } catch (final DocumentedException e) {
- assertTrue(e.getErrorType() == ErrorType.APPLICATION);
- assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
- assertTrue(e.getErrorTag() == ErrorTag.OPERATION_FAILED);
- }
+ final DocumentedException e = assertThrows(DocumentedException.class,
+ () -> rpc.handle(rpcDocument, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT));
+
+ assertEquals(e.getErrorSeverity(), ErrorSeverity.ERROR);
+ assertEquals(e.getErrorTag(), ErrorTag.OPERATION_FAILED);
+ assertEquals(e.getErrorType(), ErrorType.APPLICATION);
}
@Test
final RuntimeRpc rpc = new RuntimeRpc(SESSION_ID_FOR_REPORTING, currentSchemaContext, RPC_SERVICE_VOID_INVOKER);
final Document rpcDocument = XmlFileLoader.xmlFileToDocument("messages/mapping/rpcs/rpc-bad-namespace.xml");
- try {
- rpc.handle(rpcDocument, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT);
- fail("Should have failed, rpc has bad namespace");
- } catch (final DocumentedException e) {
- assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
- assertTrue(e.getErrorTag() == ErrorTag.BAD_ELEMENT);
- assertTrue(e.getErrorType() == ErrorType.APPLICATION);
- }
+ final DocumentedException e = assertThrows(DocumentedException.class,
+ () -> rpc.handle(rpcDocument, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT));
+
+ assertEquals(e.getErrorSeverity(), ErrorSeverity.ERROR);
+ assertEquals(e.getErrorTag(), ErrorTag.BAD_ELEMENT);
+ assertEquals(e.getErrorType(), ErrorType.APPLICATION);
}
private static void verifyResponse(final Document response, final Document template) {