use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class XmlPatchBodyReaderTest method moduleDataValueMissingNegativeTest.
/**
* Test trying to use Patch create operation which requires value without value. Error code 400 should be returned.
*/
@Test
public void moduleDataValueMissingNegativeTest() throws Exception {
mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class AbstractBodyReaderTest method assertRangeViolation.
protected static void assertRangeViolation(final ThrowingRunnable runnable) {
final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, runnable);
assertEquals(Status.BAD_REQUEST, ex.getResponse().getStatusInfo());
final List<RestconfError> errors = ex.getErrors();
assertEquals(1, errors.size());
final RestconfError error = errors.get(0);
assertEquals(ErrorType.APPLICATION, error.getErrorType());
assertEquals(ErrorTag.INVALID_VALUE, error.getErrorTag());
assertEquals("bar error app tag", error.getErrorAppTag());
assertEquals("bar error message", error.getErrorMessage());
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class XmlBodyReaderMountPointTest method wrongRootElementTest.
/**
* Test PUT operation when message root element is not the same as the last element in request URI.
* PUT operation message should always start with schema node from URI otherwise exception should be
* thrown.
*/
@Test
public void wrongRootElementTest() throws Exception {
mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, false);
final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/bug7933.xml");
final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> xmlBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
final RestconfError restconfError = ex.getErrors().get(0);
assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfMappingNodeUtil method mapYangNotificationStreamByIetfRestconfMonitoring.
/**
* Map data of yang notification to normalized node according to ietf-restconf-monitoring.
*
* @param notifiQName qname of notification from listener
* @param notifications list of notifications for find schema of notification by notifiQName
* @param start start-time query parameter of notification
* @param outputType output type of notification
* @param uri location of registered listener for sending data of notification
* @return mapped data of notification - map entry node if parent exists,
* container streams with list and map entry node if not
*/
public static MapEntryNode mapYangNotificationStreamByIetfRestconfMonitoring(final QName notifiQName, final Collection<? extends NotificationDefinition> notifications, final Instant start, final String outputType, final URI uri) {
for (final NotificationDefinition notificationDefinition : notifications) {
if (notificationDefinition.getQName().equals(notifiQName)) {
final String streamName = notifiQName.getLocalName();
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> streamEntry = Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(Stream.QNAME, NAME_QNAME, streamName)).withChild(ImmutableNodes.leafNode(NAME_QNAME, streamName));
notificationDefinition.getDescription().ifPresent(desc -> streamEntry.withChild(ImmutableNodes.leafNode(DESCRIPTION_QNAME, desc)));
streamEntry.withChild(ImmutableNodes.leafNode(REPLAY_SUPPORT_QNAME, Boolean.TRUE));
if (start != null) {
streamEntry.withChild(ImmutableNodes.leafNode(REPLAY_LOG_CREATION_TIME, DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(OffsetDateTime.ofInstant(start, ZoneId.systemDefault()))));
}
return streamEntry.withChild(createAccessList(outputType, uri)).build();
}
}
throw new RestconfDocumentedException(notifiQName + " doesn't exist in any modul");
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfSchemaServiceTest method getSchemaWrongIdentifierMountPointTest.
/**
* Try to get schema with wrong (not valid) identifier behind mount point catching
* <code>RestconfDocumentedException</code>. Error type, error tag and error status code are compared to expected
* values.
*
* <p>
* Not valid identifier contains only revision without module name.
*/
@Test
public void getSchemaWrongIdentifierMountPointTest() {
// prepare conditions - return correct schema context with mount points
when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT_WITH_MOUNT_POINTS);
// make test and verify
final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> schemaService.getSchema(MOUNT_POINT + "2014-01-01"));
assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
}
Aggregations