Search in sources :

Example 96 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class RestconfValidationTest method validateAndGetModuleNameEmptyTest.

/**
 * Negative test of module name validation when supplied name is empty. Test fails catching
 * <code>RestconfDocumentedException</code> and checking for correct error type, error tag and error status code.
 */
@Test
public void validateAndGetModuleNameEmptyTest() {
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator("")));
    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)

Example 97 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class RestconfValidationTest method validateAndGetModuleNameNotParsableNextTest.

/**
 * Negative test of module name validation when supplied name is not parsable as module name on any of the
 * characters after the first character. Test fails catching <code>RestconfDocumentedException</code> and checking
 * for correct error type, error tag and error status code.
 */
@Test
public void validateAndGetModuleNameNotParsableNextTest() {
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator("not-parsable-as-name-after-first-char*")));
    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)

Example 98 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class InvokeRpcMethodTest method testInvokeRpcWithNoPayloadRpc_FailNoErrors.

@Test
public void testInvokeRpcWithNoPayloadRpc_FailNoErrors() {
    final QName qname = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
    doReturn(immediateFailedFluentFuture(new DOMRpcImplementationNotAvailableException("testExeption"))).when(brokerFacade).invokeRpc(eq(qname), any());
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> this.restconfImpl.invokeRpc("toaster:cancel-toast", null, uriInfo));
    verifyRestconfDocumentedException(ex, 0, ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, Optional.empty(), Optional.empty());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) QName(org.opendaylight.yangtools.yang.common.QName) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) Test(org.junit.Test)

Example 99 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class InvokeRpcMethodTest method testThrowExceptionWhenSlashInModuleName.

@Test
public void testThrowExceptionWhenSlashInModuleName() {
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> this.restconfImpl.invokeRpc("toaster/slash", null, uriInfo));
    verifyRestconfDocumentedException(ex, 0, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, Optional.empty(), Optional.empty());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) Test(org.junit.Test)

Example 100 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class QueryParamsTest method optionalParamMultipleTest.

/**
 * Test when parameter is present more than once.
 */
@Test
public void optionalParamMultipleTest() {
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> QueryParams.optionalParam(ContentParam.uriName, List.of("config", "nonconfig", "all")));
    final List<RestconfError> errors = ex.getErrors();
    assertEquals(1, errors.size());
    final RestconfError error = errors.get(0);
    assertEquals("Error type is not correct", ErrorType.PROTOCOL, error.getErrorType());
    assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, error.getErrorTag());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) 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