import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
@Test
public void wrongRootElementTest() throws Exception {
mockPutBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader);
- final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+ final var inputStream = XmlBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/xml/bug7933.xml");
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var ex = assertThrows(RestconfDocumentedException.class,
() -> xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null, inputStream));
- final RestconfError restconfError = ex.getErrors().get(0);
- assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
- assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
+ final var error = ex.getErrors().get(0);
+ assertEquals(ErrorType.PROTOCOL, error.getErrorType());
+ assertEquals(ErrorTag.MALFORMED_MESSAGE, error.getErrorTag());
+ assertEquals("Error parsing input: Not correct message root element \"cont1\", should be "
+ + "\"(urn:ietf:params:xml:ns:netconf:base:1.0)data\"", error.getErrorMessage());
}
}
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
-import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
@Test
public void wrongRootElementTest() throws Exception {
mockPutBodyReader("instance-identifier-module:cont", xmlBodyReader);
- final InputStream inputStream =
+ final var inputStream =
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/bug7933.xml");
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var ex = assertThrows(RestconfDocumentedException.class,
() -> xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null, inputStream));
-
- final RestconfError restconfError = ex.getErrors().get(0);
- assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
- assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
+ final var error = ex.getErrors().get(0);
+ assertEquals(ErrorType.PROTOCOL, error.getErrorType());
+ assertEquals(ErrorTag.MALFORMED_MESSAGE, error.getErrorTag());
+ assertEquals("Error parsing input: Not correct message root element \"cont1\", should be "
+ + "\"(instance:identifier:module?revision=2014-01-17)cont\"", error.getErrorMessage());
}
@Test
import java.util.Collections;
import java.util.List;
import org.junit.Test;
+import org.junit.function.ThrowingRunnable;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.Revision;
*/
@Test
public void validateAndGetRevisionNotSuppliedTest() {
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var error = assertInvalidValue(
() -> ParserIdentifier.validateAndGetRevision(Collections.emptyIterator()));
-
- assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
- assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
+ assertEquals("Revision date must be supplied.", error.getErrorMessage());
}
/**
*/
@Test
public void validateAndGetModulNameNotSuppliedTest() {
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var error = assertInvalidValue(
() -> ParserIdentifier.validateAndGetModulName(Collections.emptyIterator()));
- assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
- assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
+ assertEquals("Module name must be supplied.", error.getErrorMessage());
+
}
/**
*/
@Test
public void validateAndGetModuleNameNotParsableFirstTest() {
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var error = assertInvalidValue(
() -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator(
"01-not-parsable-as-name-on-firts-char")));
- assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
- assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
+ assertEquals("Identifier must start with character from set 'a-zA-Z_", error.getErrorMessage());
}
/**
*/
@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());
+ final var error = assertInvalidValue(() -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator(
+ "not-parsable-as-name-after-first-char*")));
+ assertEquals("Supplied name has not expected identifier format.", error.getErrorMessage());
}
/**
*/
@Test
public void validateAndGetModuleNameNotParsableXmlTest() {
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var error = assertInvalidValue(
() -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator("xMl-module-name")));
- assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
- assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
+ assertEquals("Identifier must NOT start with XML ignore case.", error.getErrorMessage());
}
/**
*/
@Test
public void validateAndGetModuleNameEmptyTest() {
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var error = assertInvalidValue(
() -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator("")));
- assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
- assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
+ assertEquals("Identifier must start with character from set 'a-zA-Z_", error.getErrorMessage());
+ }
+
+ private static RestconfError assertInvalidValue(final ThrowingRunnable runnable) {
+ final var ex = assertThrows(RestconfDocumentedException.class, runnable);
+ final var errors = ex.getErrors();
+ assertEquals(1, errors.size());
+ final var error = errors.get(0);
+ assertEquals(ErrorType.PROTOCOL, error.getErrorType());
+ assertEquals(ErrorTag.INVALID_VALUE, error.getErrorTag());
+ return error;
}
}