Search in sources :

Example 11 with RestconfError

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

the class BrokerFacadeTest method testCommitConfigurationDataDeleteNoData.

/**
 * Negative test of delete operation when data to delete does not exist. Error DATA_MISSING should be returned.
 */
@Test
public void testCommitConfigurationDataDeleteNoData() throws Exception {
    // assume that data to delete does not exist
    prepareDataForDelete(false);
    // try to delete and expect DATA_MISSING error
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> brokerFacade.commitConfigurationDataDelete(this.instanceID));
    final List<RestconfError> errors = ex.getErrors();
    assertEquals(1, errors.size());
    assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
    assertEquals(ErrorTag.DATA_MISSING, errors.get(0).getErrorTag());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) Test(org.junit.Test)

Example 12 with RestconfError

use of org.opendaylight.restconf.common.errors.RestconfError 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 13 with RestconfError

use of org.opendaylight.restconf.common.errors.RestconfError 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 14 with RestconfError

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

the class XmlBodyReaderTest 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", 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) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) Test(org.junit.Test)

Example 15 with RestconfError

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

the class ParserIdentifierTest method toInstanceIdentifierMissingMountPointNegativeTest.

/**
 * Negative test when <code>DOMMountPoint</code> cannot be found. Test is expected to fail with
 * <code>RestconfDocumentedException</code> error type, error tag and error status code are
 * compared to expected values.
 */
@Test
public void toInstanceIdentifierMissingMountPointNegativeTest() {
    RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> ParserIdentifier.toInstanceIdentifier("/yang-ext:mount", SCHEMA_CONTEXT, Optional.of(this.mountPointService)));
    final List<RestconfError> errors = ex.getErrors();
    assertEquals(1, errors.size());
    assertEquals("Not expected error type", ErrorType.PROTOCOL, errors.get(0).getErrorType());
    assertEquals("Not expected error tag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) Test(org.junit.Test)

Aggregations

RestconfError (org.opendaylight.restconf.common.errors.RestconfError)30 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)19 Test (org.junit.Test)16 InputStream (java.io.InputStream)6 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 ErrorTag (org.opendaylight.yangtools.yang.common.ErrorTag)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Response (javax.ws.rs.core.Response)3 ErrorType (org.opendaylight.yangtools.yang.common.ErrorType)3 MediaType (javax.ws.rs.core.MediaType)2 Status (javax.ws.rs.core.Response.Status)2 Ignore (org.junit.Ignore)2 PatchEntity (org.opendaylight.restconf.common.patch.PatchEntity)2 PatchStatusContext (org.opendaylight.restconf.common.patch.PatchStatusContext)2 PatchStatusEntity (org.opendaylight.restconf.common.patch.PatchStatusEntity)2 RpcError (org.opendaylight.yangtools.yang.common.RpcError)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1