use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.
the class CreateStreamUtilTest method createStreamTest.
@Test
public void createStreamTest() {
payload = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getInput, "toaster", "path");
final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
assertEquals(result.getErrors(), Collections.emptyList());
final NormalizedNode testedNn = result.getResult();
assertNotNull(testedNn);
final NormalizedNodePayload contextRef = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getOutput, "data-change-event-subscription/toaster:toaster/datastore=CONFIGURATION/scope=BASE", "stream-name");
assertEquals(contextRef.getData(), testedNn);
}
use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.
the class RestconfDataServiceImplTest method testReadDataMountPoint.
/**
* Test read data from mount point when both {@link LogicalDatastoreType#CONFIGURATION} and
* {@link LogicalDatastoreType#OPERATIONAL} contains the same data and some additional data to be merged.
*/
@Test
public void testReadDataMountPoint() {
doReturn(new MultivaluedHashMap<String, String>()).when(uriInfo).getQueryParameters();
doReturn(immediateFluentFuture(Optional.of(buildBaseContConfig))).when(read).read(LogicalDatastoreType.CONFIGURATION, iidBase);
doReturn(immediateFluentFuture(Optional.of(buildBaseContOperational))).when(read).read(LogicalDatastoreType.OPERATIONAL, iidBase);
final Response response = dataService.readData("example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox", uriInfo);
assertNotNull(response);
assertEquals(200, response.getStatus());
// response must contain all child nodes from config and operational containers merged in one container
final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
assertTrue(data instanceof ContainerNode);
assertEquals(3, ((ContainerNode) data).size());
assertTrue(((ContainerNode) data).findChildByArg(buildPlayerCont.getIdentifier()).isPresent());
assertTrue(((ContainerNode) data).findChildByArg(buildLibraryCont.getIdentifier()).isPresent());
assertTrue(((ContainerNode) data).findChildByArg(buildPlaylistList.getIdentifier()).isPresent());
}
use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.
the class RestconfDataServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
doReturn(Set.of()).when(queryParamenters).entrySet();
doReturn(queryParamenters).when(uriInfo).getQueryParameters();
baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
containerPlayerQname = QName.create(baseQName, "player");
leafQname = QName.create(baseQName, "gap");
final QName containerLibraryQName = QName.create(baseQName, "library");
final QName listPlaylistQName = QName.create(baseQName, "playlist");
final LeafNode<?> buildLeaf = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(leafQname)).withValue(0.2).build();
buildPlayerCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(containerPlayerQname)).withChild(buildLeaf).build();
buildLibraryCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(containerLibraryQName)).build();
buildPlaylistList = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(listPlaylistQName)).build();
buildBaseCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildPlayerCont).build();
// config contains one child the same as in operational and one additional
buildBaseContConfig = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildPlayerCont).withChild(buildLibraryCont).build();
// operational contains one child the same as in config and one additional
buildBaseContOperational = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildPlayerCont).withChild(buildPlaylistList).build();
iidBase = YangInstanceIdentifier.builder().node(baseQName).build();
contextRef = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
schemaNode = DataSchemaContextTree.from(contextRef).findChild(iidBase).orElseThrow().getDataSchemaNode();
doReturn(CommitInfo.emptyFluentFuture()).when(write).commit();
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
DOMDataBroker mockDataBroker = mock(DOMDataBroker.class);
doReturn(read).when(mockDataBroker).newReadOnlyTransaction();
doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
doReturn(write).when(mockDataBroker).newWriteOnlyTransaction();
final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(mockDataBroker, mock(DOMSchemaService.class));
schemaContextHandler.onModelContextUpdated(contextRef);
dataService = new RestconfDataServiceImpl(schemaContextHandler, mockDataBroker, mountPointService, delegRestconfSubscrService, actionService, configuration);
doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
doReturn(Optional.of(FixedDOMSchemaService.of(contextRef))).when(mountPoint).getService(DOMSchemaService.class);
doReturn(Optional.of(mountDataBroker)).when(mountPoint).getService(DOMDataBroker.class);
doReturn(Optional.empty()).when(mountPoint).getService(NetconfDataTreeService.class);
doReturn(read).when(mountDataBroker).newReadOnlyTransaction();
doReturn(readWrite).when(mountDataBroker).newReadWriteTransaction();
}
use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.
the class RestconfStreamsSubscriptionServiceImplTest method setUp.
@Before
public void setUp() throws FileNotFoundException, URISyntaxException {
final DOMDataTreeWriteTransaction wTx = mock(DOMDataTreeWriteTransaction.class);
doReturn(wTx).when(dataBroker).newWriteOnlyTransaction();
doReturn(CommitInfo.emptyFluentFuture()).when(wTx).commit();
schemaHandler = new SchemaContextHandler(dataBroker, mock(DOMSchemaService.class));
DOMDataTreeChangeService dataTreeChangeService = mock(DOMDataTreeChangeService.class);
doReturn(mock(ListenerRegistration.class)).when(dataTreeChangeService).registerDataTreeChangeListener(any(), any());
doReturn(ImmutableClassToInstanceMap.of(DOMDataTreeChangeService.class, dataTreeChangeService)).when(dataBroker).getExtensions();
doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
doReturn(new LocalUriInfo().getBaseUriBuilder()).when(uriInfo).getBaseUriBuilder();
doReturn(new URI("http://127.0.0.1/" + URI)).when(uriInfo).getAbsolutePath();
schemaHandler.onModelContextUpdated(YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications")));
configurationWs = new Configuration(0, 100, 10, false);
configurationSse = new Configuration(0, 100, 10, true);
}
use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.
the class PlainPatchDataTransactionUtil method patchData.
/**
* Prepare variables for put data to DS. Close {@link DOMTransactionChain} if any inside of object
* {@link RestconfStrategy} provided as a parameter if any.
*
* @param payload data to put
* @param schemaContext reference to {@link EffectiveModelContext}
* @param strategy object that perform the actual DS operations
* @return {@link Response}
*/
public static Response patchData(final NormalizedNodePayload payload, final RestconfStrategy strategy, final EffectiveModelContext schemaContext) {
final RestconfTransaction transaction = strategy.prepareWriteExecution();
YangInstanceIdentifier path = payload.getInstanceIdentifierContext().getInstanceIdentifier();
NormalizedNode data = payload.getData();
try {
LOG.trace("Merge CONFIGURATION within Restconf Patch: {} with payload {}", path, data);
TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
transaction.merge(path, data);
} catch (final RestconfDocumentedException e) {
transaction.cancel();
throw new IllegalArgumentException(e);
}
final FluentFuture<? extends CommitInfo> future = transaction.commit();
final ResponseFactory response = new ResponseFactory(Status.OK);
// closes transactionChain if any, may throw
FutureCallbackTx.addCallback(future, PatchDataTransactionUtil.PATCH_TX_TYPE, response, path);
return response.build();
}
Aggregations