Search in sources :

Example 86 with RestconfDocumentedException

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

the class RestconfSchemaServiceTest method getSchemaWithNotParsableIdentifierMountPointTest.

/**
 * Try to get schema behind mount point with not-parsable identifier catching
 * <code>RestconfDocumentedException</code>. Error type, error tag and error status code are compared to expected
 * values.
 */
@Test
public void getSchemaWithNotParsableIdentifierMountPointTest() {
    // 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 + "01_module/2016-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)

Example 87 with RestconfDocumentedException

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

the class PostDataTransactionUtilTest method testPostDataFail.

@Test
public void testPostDataFail() {
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, null, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
    doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    final NodeIdentifier identifier = ((ContainerNode) ((Collection<?>) payload.getData().body()).iterator().next()).getIdentifier();
    final YangInstanceIdentifier node = iid2.node(identifier);
    doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node.getParent(), payload.getData());
    final DOMException domException = new DOMException((short) 414, "Post request failed");
    doReturn(immediateFailedFluentFuture(domException)).when(readWrite).commit();
    doReturn(immediateFailedFluentFuture(domException)).when(netconfService).create(any(), any(), any(), any());
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).discardChanges();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).unlock();
    RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty()));
    assertEquals(1, ex.getErrors().size());
    assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
    verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
    ex = assertThrows(RestconfDocumentedException.class, () -> PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty()));
    assertEquals(1, ex.getErrors().size());
    assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
    verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
}
Also used : DOMException(org.w3c.dom.DOMException) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 88 with RestconfDocumentedException

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

the class RestconfSchemaServiceTest method getSchemaWithEmptyIdentifierTest.

/**
 * Try to get schema with empty (not valid) identifier catching <code>RestconfDocumentedException</code>. Error
 * type, error tag and error status code are compared to expected values.
 */
@Test
public void getSchemaWithEmptyIdentifierTest() {
    // prepare conditions - return correct schema context
    when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
    // make test and verify
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> schemaService.getSchema(""));
    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 89 with RestconfDocumentedException

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

the class RestconfSchemaServiceTest method getSchemaWrongIdentifierTest.

/**
 * Try to get schema with wrong (not valid) identifier 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 getSchemaWrongIdentifierTest() {
    // prepare conditions - return correct schema context without mount points
    when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
    // make test and verify
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> schemaService.getSchema("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)

Example 90 with RestconfDocumentedException

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

the class RestconfSchemaServiceTest method getSchemaWithEmptyIdentifierMountPointTest.

/**
 * Try to get schema with empty (not valid) identifier behind mount point catching
 * <code>RestconfDocumentedException</code>. Error type, error tag and error status code are compared to expected
 * values.
 */
@Test
public void getSchemaWithEmptyIdentifierMountPointTest() {
    // 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 + ""));
    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