use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class RestGetOperationTest method getDataWithSlashesBehindMountPoint.
/**
* MountPoint test. URI represents mount point.
* Slashes in URI behind mount point. lst1 element with key GigabitEthernet0%2F0%2F0%2F0 (GigabitEthernet0/0/0/0) is
* requested via GET HTTP operation. It is tested whether %2F character is replaced with simple / in
* InstanceIdentifier parameter in method
* {@link BrokerFacade#readConfigurationData(DOMMountPoint, YangInstanceIdentifier)} which is called in
* method {@link RestconfImpl#readConfigurationData}
*/
@Test
public void getDataWithSlashesBehindMountPoint() throws Exception {
final YangInstanceIdentifier awaitedInstanceIdentifier = prepareInstanceIdentifierForList();
when(brokerFacade.readConfigurationData(any(DOMMountPoint.class), eq(awaitedInstanceIdentifier), isNull())).thenReturn(prepareCnDataForSlashesBehindMountPointTest());
when(mountInstance.getService(DOMSchemaService.class)).thenReturn(Optional.of(FixedDOMSchemaService.of(schemaContextTestModule)));
final String uri = "/config/ietf-interfaces:interfaces/interface/0/yang-ext:mount/" + "test-module:cont/lst1/GigabitEthernet0%2F0%2F0%2F0";
assertEquals(200, get(uri, MediaType.APPLICATION_XML));
}
use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class ApiDocServiceImplTest method setUp.
@Before
public void setUp() {
final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/yang");
final DOMSchemaService schemaService = DocGenTestHelper.createMockSchemaService(context);
final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(schemaService));
final DOMMountPointService service = mock(DOMMountPointService.class);
when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
final MountPointSwaggerGeneratorDraft02 mountPointDraft02 = new MountPointSwaggerGeneratorDraft02(schemaService, service);
final MountPointSwaggerGeneratorRFC8040 mountPointRFC8040 = new MountPointSwaggerGeneratorRFC8040(schemaService, service);
final ApiDocGeneratorDraftO2 apiDocGeneratorDraftO2 = new ApiDocGeneratorDraftO2(schemaService);
final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040 = new ApiDocGeneratorRFC8040(schemaService);
mountPointDraft02.getMountPointSwagger().onMountPointCreated(INSTANCE_ID);
final AllModulesDocGenerator allModulesDocGenerator = new AllModulesDocGenerator(apiDocGeneratorDraftO2, apiDocGeneratorRFC8040);
apiDocService = new ApiDocServiceImpl(mountPointDraft02, mountPointRFC8040, apiDocGeneratorDraftO2, apiDocGeneratorRFC8040, allModulesDocGenerator);
}
use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class MountPointSwaggerTest method setUp.
@Before
public void setUp() {
// We are sharing the global schema service and the mount schema service
// in our test.
// OK for testing - real thing would have separate instances.
final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/yang");
final DOMSchemaService schemaService = DocGenTestHelper.createMockSchemaService(context);
final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(schemaService));
final DOMMountPointService service = mock(DOMMountPointService.class);
when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
final MountPointSwaggerGeneratorDraft02 generator = new MountPointSwaggerGeneratorDraft02(schemaService, service);
swagger = generator.getMountPointSwagger();
}
use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class RestconfDataServiceImpl method putData.
@Override
public Response putData(final String identifier, final NormalizedNodePayload payload, final UriInfo uriInfo) {
requireNonNull(payload);
final WriteDataParams params = QueryParams.newWriteDataParams(uriInfo);
final InstanceIdentifierContext<? extends SchemaNode> iid = payload.getInstanceIdentifierContext();
validInputData(iid.getSchemaNode(), payload);
validTopLevelNodeName(iid.getInstanceIdentifier(), payload);
validateListKeysEqualityInPayloadAndUri(payload);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
final EffectiveModelContext ref = mountPoint == null ? schemaContextHandler.get() : modelContext(mountPoint);
final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
return PutDataTransactionUtil.putData(payload, ref, strategy, params);
}
use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class RestconfDataServiceImpl method invokeAction.
/**
* Invoke Action operation.
*
* @param payload {@link NormalizedNodePayload} - the body of the operation
* @return {@link NormalizedNodePayload} wrapped in {@link Response}
*/
public Response invokeAction(final NormalizedNodePayload payload) {
final InstanceIdentifierContext<?> context = payload.getInstanceIdentifierContext();
final DOMMountPoint mountPoint = context.getMountPoint();
final YangInstanceIdentifier yangIIdContext = context.getInstanceIdentifier();
final NormalizedNode data = payload.getData();
if (yangIIdContext.isEmpty() && !NETCONF_BASE_QNAME.equals(data.getIdentifier().getNodeType())) {
throw new RestconfDocumentedException("Instance identifier need to contain at least one path argument", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
}
final List<QName> qNames = yangIIdContext.getPathArguments().stream().filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates)).filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier)).map(PathArgument::getNodeType).collect(Collectors.toList());
qNames.add(context.getSchemaNode().getQName());
final Absolute schemaPath = Absolute.of(qNames);
final DOMActionResult response;
final EffectiveModelContext schemaContextRef;
if (mountPoint != null) {
response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, mountPoint);
schemaContextRef = modelContext(mountPoint);
} else {
response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, actionService);
schemaContextRef = schemaContextHandler.get();
}
final DOMActionResult result = checkActionResponse(response);
ActionDefinition resultNodeSchema = null;
ContainerNode resultData = null;
if (result != null) {
final Optional<ContainerNode> optOutput = result.getOutput();
if (optOutput.isPresent()) {
resultData = optOutput.get();
resultNodeSchema = (ActionDefinition) context.getSchemaNode();
}
}
if (resultData != null && resultData.isEmpty()) {
return Response.status(Status.NO_CONTENT).build();
}
return Response.status(Status.OK).entity(NormalizedNodePayload.ofNullable(new InstanceIdentifierContext<>(yangIIdContext, resultNodeSchema, mountPoint, schemaContextRef), resultData)).build();
}
Aggregations