use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.
the class PostDataTransactionUtilTest method testPostListData.
@Test
public void testPostListData() {
final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iidList, null, null, schema);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildList);
final MapNode data = (MapNode) payload.getData();
final MapEntryNode entryNode = data.body().iterator().next();
final NodeIdentifierWithPredicates identifier = entryNode.getIdentifier();
final YangInstanceIdentifier node = iidList.node(identifier);
doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, entryNode);
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(), any(), any());
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).create(LogicalDatastoreType.CONFIGURATION, node, entryNode, Optional.empty());
Response response = PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty());
assertEquals(201, response.getStatus());
assertThat(URLDecoder.decode(response.getLocation().toString(), StandardCharsets.UTF_8), containsString(identifier.getValue(identifier.keySet().iterator().next()).toString()));
verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, entryNode);
response = PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty());
assertEquals(201, response.getStatus());
assertThat(URLDecoder.decode(response.getLocation().toString(), StandardCharsets.UTF_8), containsString(identifier.getValue(identifier.keySet().iterator().next()).toString()));
verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, node, entryNode, Optional.empty());
}
use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.
the class PostDataTransactionUtilTest method testPostContainerData.
@Test
public void testPostContainerData() {
final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, null, null, schema);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
final NodeIdentifier identifier = ((ContainerNode) ((Collection<?>) payload.getData().body()).iterator().next()).getIdentifier();
final YangInstanceIdentifier node = iid2.node(identifier);
doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node.getParent(), payload.getData());
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
Response response = PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty());
assertEquals(201, response.getStatus());
verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
response = PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty());
assertEquals(201, response.getStatus());
verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
}
use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.
the class PostDataTransactionUtilTest method testPostDataFail.
@Test
public void testPostDataFail() {
final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, null, null, schema);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
final NodeIdentifier identifier = ((ContainerNode) ((Collection<?>) payload.getData().body()).iterator().next()).getIdentifier();
final YangInstanceIdentifier node = iid2.node(identifier);
doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node.getParent(), payload.getData());
final DOMException domException = new DOMException((short) 414, "Post request failed");
doReturn(immediateFailedFluentFuture(domException)).when(readWrite).commit();
doReturn(immediateFailedFluentFuture(domException)).when(netconfService).create(any(), any(), any(), any());
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).discardChanges();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).unlock();
RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty()));
assertEquals(1, ex.getErrors().size());
assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
ex = assertThrows(RestconfDocumentedException.class, () -> PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty()));
assertEquals(1, ex.getErrors().size());
assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
}
use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.
the class PutDataTransactionUtilTest method testPutReplaceContainerData.
@Test
public void testPutReplaceContainerData() {
final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(netconfService).getConfig(iid2);
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
PutDataTransactionUtil.putData(payload, schema, new NetconfRestconfStrategy(netconfService), WriteDataParams.empty());
verify(netconfService).getConfig(iid2);
verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
}
use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.
the class ReadDataTransactionUtilTest method setUp.
@Before
public void setUp() {
// FIXME: these tests need to be parameterized somehow. The trouble is we need mocking before we invoke
// the strategy. This needs some more thought.
doReturn(read).when(mockDataBroker).newReadOnlyTransaction();
mdsalStrategy = new MdsalRestconfStrategy(mockDataBroker);
netconfStrategy = new NetconfRestconfStrategy(netconfService);
}
Aggregations