Search in sources :

Example 46 with RestconfDocumentedException

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());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) InputStream(java.io.InputStream) AbstractBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest) XmlBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest) Test(org.junit.Test)

Example 47 with RestconfDocumentedException

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());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RestconfError(org.opendaylight.restconf.common.errors.RestconfError)

Example 48 with RestconfDocumentedException

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());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) InputStream(java.io.InputStream) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) XmlBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest) AbstractBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest) Test(org.junit.Test)

Example 49 with RestconfDocumentedException

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");
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 50 with RestconfDocumentedException

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());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) Test(org.junit.Test)

Aggregations

RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)136 Test (org.junit.Test)65 InputStream (java.io.InputStream)30 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)20 RestconfError (org.opendaylight.restconf.common.errors.RestconfError)20 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)19 QName (org.opendaylight.yangtools.yang.common.QName)17 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)17 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)16 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)14 List (java.util.List)13 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)13 ArrayList (java.util.ArrayList)12 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)11 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)9 IOException (java.io.IOException)8 ExecutionException (java.util.concurrent.ExecutionException)8 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)8 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)8