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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations