import org.opendaylight.restconf.api.ApiPath;
import org.opendaylight.restconf.api.ApiPath.ListInstance;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.PathMixin;
-import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
public final @NonNull SchemaInferenceStack stack;
public final @NonNull SchemaNode node;
- Result(final EffectiveModelContext context) {
+ Result(final EffectiveModelContext modelContext) {
path = YangInstanceIdentifier.of();
- node = requireNonNull(context);
- stack = SchemaInferenceStack.of(context);
+ stack = SchemaInferenceStack.of(modelContext);
+ node = requireNonNull(modelContext);
}
- Result(final EffectiveModelContext context, final QName qname) {
+ Result(final EffectiveModelContext modelContext, final QName qname) {
// Legacy behavior: RPCs do not really have a YangInstanceIdentifier, but the rest of the code expects it
path = YangInstanceIdentifier.of(qname);
- stack = SchemaInferenceStack.of(context);
+ stack = SchemaInferenceStack.of(modelContext);
final var stmt = stack.enterSchemaTree(qname);
verify(stmt instanceof RpcDefinition, "Unexpected statement %s", stmt);
}
}
- private final @NonNull EffectiveModelContext schemaContext;
+ private final @NonNull DatabindContext databind;
+ private final @NonNull EffectiveModelContext modelContext;
private final @NonNull ApiPath apiPath;
- private YangInstanceIdentifierDeserializer(final EffectiveModelContext schemaContext, final ApiPath apiPath) {
- this.schemaContext = requireNonNull(schemaContext);
+ private YangInstanceIdentifierDeserializer(final DatabindContext databind, final ApiPath apiPath) {
+ this.databind = requireNonNull(databind);
this.apiPath = requireNonNull(apiPath);
+ modelContext = databind.modelContext();
}
/**
* Method to create {@link List} from {@link PathArgument} which are parsing from data by {@link SchemaContext}.
*
- * @param schemaContext for validate of parsing path arguments
+ * @param databind for validate of parsing path arguments
* @param data path to data, in URL string form
* @return {@link Iterable} of {@link PathArgument}
* @throws RestconfDocumentedException the path is not valid
*/
- public static Result create(final EffectiveModelContext schemaContext, final String data) {
+ public static Result create(final DatabindContext databind, final String data) {
final ApiPath path;
try {
path = ApiPath.parse(requireNonNull(data));
throw new RestconfDocumentedException("Invalid path '" + data + "' at offset " + e.getErrorOffset(),
ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, e);
}
- return create(schemaContext, path);
+ return create(databind, path);
}
- public static Result create(final EffectiveModelContext schemaContext, final ApiPath path) {
- return new YangInstanceIdentifierDeserializer(schemaContext, path).parse();
+ public static Result create(final DatabindContext databind, final ApiPath path) {
+ return new YangInstanceIdentifierDeserializer(databind, path).parse();
}
// FIXME: NETCONF-818: this method really needs to report an Inference and optionally a YangInstanceIdentifier
private Result parse() {
final var it = apiPath.steps().iterator();
if (!it.hasNext()) {
- return new Result(schemaContext);
+ return new Result(modelContext);
}
// First step is somewhat special:
var qname = step.identifier().bindTo(namespace);
// We go through more modern APIs here to get this special out of the way quickly
- final var optRpc = schemaContext.findModuleStatement(namespace).orElseThrow()
+ final var optRpc = modelContext.findModuleStatement(namespace).orElseThrow()
.findSchemaTreeNode(RpcEffectiveStatement.class, qname);
if (optRpc.isPresent()) {
// We have found an RPC match,
+ "therefore it must not contain key values", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
}
- return new Result(schemaContext, optRpc.orElseThrow().argument());
+ return new Result(modelContext, optRpc.orElseThrow().argument());
}
- final var stack = SchemaInferenceStack.of(schemaContext);
+ final var stack = SchemaInferenceStack.of(modelContext);
final var path = new ArrayList<PathArgument>();
final SchemaNode node;
- DataSchemaContext parentNode = DataSchemaContextTree.from(schemaContext).getRoot();
+ DataSchemaContext parentNode = databind.schemaTree().getRoot();
while (true) {
final var parentSchema = parentNode.dataSchemaNode();
if (parentSchema instanceof ActionNodeContainer actionParent) {
final @NonNull String value) {
TypeDefinition<? extends TypeDefinition<?>> typedef;
- if (schemaNode instanceof LeafListSchemaNode) {
- typedef = ((LeafListSchemaNode) schemaNode).getType();
+ if (schemaNode instanceof LeafListSchemaNode leafList) {
+ typedef = leafList.getType();
} else {
typedef = ((LeafSchemaNode) schemaNode).getType();
}
- if (typedef instanceof LeafrefTypeDefinition) {
- typedef = stack.resolveLeafref((LeafrefTypeDefinition) typedef);
+ if (typedef instanceof LeafrefTypeDefinition leafref) {
+ typedef = stack.resolveLeafref(leafref);
}
if (typedef instanceof IdentityrefTypeDefinition) {
try {
if (typedef instanceof InstanceIdentifierTypeDefinition) {
- return new StringModuleInstanceIdentifierCodec(schemaContext).deserialize(value);
+ return new StringModuleInstanceIdentifierCodec(databind).deserialize(value);
}
return verifyNotNull(TypeDefinitionAwareCodec.from(typedef),
localName = value;
}
- return schemaContext.getModuleStatement(namespace)
+ return modelContext.getModuleStatement(namespace)
.streamEffectiveSubstatements(IdentityEffectiveStatement.class)
.map(IdentityEffectiveStatement::argument)
.filter(qname -> localName.equals(qname.getLocalName()))
}
private @NonNull QNameModule resolveNamespace(final String moduleName) {
- final var it = schemaContext.findModuleStatements(moduleName).iterator();
+ final var it = modelContext.findModuleStatements(moduleName).iterator();
if (it.hasNext()) {
return it.next().localQNameModule();
}
import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
private static final QName ACTIONS_INTERFACES =
QName.create("https://example.com/ns/example-actions", "2016-07-07", "interfaces");
- // schema context
- private static EffectiveModelContext SCHEMA_CONTEXT;
-
- @BeforeClass
- public static void beforeClass() {
- SCHEMA_CONTEXT = YangParserTestUtils.parseYangResourceDirectory("/restconf/parser/deserializer");
- }
-
- @AfterClass
- public static void afterClass() {
- SCHEMA_CONTEXT = null;
- }
+ private static final DatabindContext DATABIND = DatabindContext.ofModel(
+ YangParserTestUtils.parseYangResourceDirectory("/restconf/parser/deserializer"));
/**
* Test of deserialization <code>String</code> URI with container to
*/
@Test
public void deserializeContainerTest() {
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:contA")
- .path.getPathArguments();
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:contA").path
+ .getPathArguments();
assertEquals(1, result.size());
assertEquals(NodeIdentifier.create(QName.create("deserializer:test", "2016-06-06", "contA")), result.get(0));
}
*/
@Test
public void deserializeContainerWithLeafTest() {
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:contA/leaf-A")
- .path.getPathArguments();
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:contA/leaf-A").path
+ .getPathArguments();
assertEquals(2, result.size());
assertEquals(NodeIdentifier.create(QName.create("deserializer:test", "2016-06-06", "contA")), result.get(0));
assertEquals(NodeIdentifier.create(QName.create("deserializer:test", "2016-06-06", "leaf-A")), result.get(1));
*/
@Test
public void deserializeContainerWithListWithLeafListTest() {
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND,
"deserializer-test:contA/list-A=100/leaf-list-AA=instance").path.getPathArguments();
assertEquals(5, result.size());
*/
@Test
public void deserializeContainerWithListWithActionTest() {
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND,
"example-actions:interfaces/interface=eth0/reset").path.getPathArguments();
assertEquals(4, result.size());
// container
*/
@Test
public void deserializeContainerWithChoiceSchemaNodeWithActionTest() {
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND,
"example-actions:interfaces/typeA-gigabyte/interface=eth0/reboot").path.getPathArguments();
assertEquals(6, result.size());
*/
@Test
public void deserializeContainerWithChoiceCaseSchemaNodeWithActionTest() {
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
- "example-actions:interfaces/udp/reboot").path.getPathArguments();
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND, "example-actions:interfaces/udp/reboot")
+ .path.getPathArguments();
assertEquals(4, result.size());
// container
assertEquals(NodeIdentifier.create(ACTIONS_INTERFACES), result.get(0));
*/
@Test
public void deserializeListWithNoKeysTest() {
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:list-no-key")
- .path.getPathArguments();
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:list-no-key").path
+ .getPathArguments();
assertEquals(2, result.size());
- final QName list = QName.create("deserializer:test", "2016-06-06", "list-no-key");
+ final var list = QName.create("deserializer:test", "2016-06-06", "list-no-key");
assertEquals(NodeIdentifier.create(list), result.get(0));
assertEquals(NodeIdentifier.create(list), result.get(1));
}
*/
@Test
public void deserializeListWithOneKeyTest() {
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
- "deserializer-test:list-one-key=value").path.getPathArguments();
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:list-one-key=value")
+ .path.getPathArguments();
assertEquals(2, result.size());
final QName list = QName.create("deserializer:test", "2016-06-06", "list-one-key");
assertEquals(NodeIdentifier.create(list), result.get(0));
*/
@Test
public void deserializeListWithMultipleKeysTest() {
- final QName list = QName.create("deserializer:test", "2016-06-06", "list-multiple-keys");
- final Map<QName, Object> values = ImmutableMap.of(
+ final var list = QName.create("deserializer:test", "2016-06-06", "list-multiple-keys");
+ final var values = ImmutableMap.<QName, Object>of(
QName.create(list, "name"), "value",
QName.create(list, "number"), Uint8.valueOf(100),
QName.create(list, "enabled"), false);
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND,
"deserializer-test:list-multiple-keys=value,100,false").path.getPathArguments();
assertEquals(2, result.size());
assertEquals(NodeIdentifier.create(list), result.get(0));
*/
@Test
public void deserializeLeafListTest() {
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
- "deserializer-test:leaf-list-0=true").path.getPathArguments();
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:leaf-list-0=true")
+ .path.getPathArguments();
assertEquals(2, result.size());
final QName leafList = QName.create("deserializer:test", "2016-06-06", "leaf-list-0");
*/
@Test
public void deserializeEmptyDataTest() {
- assertEquals(List.of(), YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "").path.getPathArguments());
+ assertEquals(List.of(), YangInstanceIdentifierDeserializer.create(DATABIND, "").path.getPathArguments());
}
/**
@Test
public void nullDataNegativeNegativeTest() {
assertThrows(NullPointerException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, (String) null));
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, (String) null));
}
/**
@Test
public void deserializeBadCharMissingSlashOrEqualNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:cont*leaf-A"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: malformed-message, "
- + "error-message: Invalid path 'deserializer-test:cont*leaf-A' at offset 22, "
- + "error-info: Expecting [a-zA-Z_.-], not '*']]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:cont*leaf-A"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: malformed-message, \
+ error-message: Invalid path 'deserializer-test:cont*leaf-A' at offset 22, \
+ error-info: Expecting [a-zA-Z_.-], not '*']]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void validArgIdentifierContainerEndsWithSlashNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:contA/"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: malformed-message, "
- + "error-message: Invalid path 'deserializer-test:contA/' at offset 24, "
- + "error-info: Identifier may not be empty]]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:contA/"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: malformed-message, \
+ error-message: Invalid path 'deserializer-test:contA/' at offset 24, \
+ error-info: Identifier may not be empty]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void validArgIdentifierContainerEndsWithMultipleSlashesNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:contA///"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: malformed-message, "
- + "error-message: Invalid path 'deserializer-test:contA///' at offset 24, "
- + "error-info: Identifier may not be empty]]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:contA///"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: malformed-message, \
+ error-message: Invalid path 'deserializer-test:contA///' at offset 24, \
+ error-info: Identifier may not be empty]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void validArgIdentifierListEndsWithSlashLNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:list-one-key=value/"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: malformed-message, "
- + "error-message: Invalid path 'deserializer-test:list-one-key=value/' at offset 37, "
- + "error-info: Identifier may not be empty]]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:list-one-key=value/"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: malformed-message, \
+ error-message: Invalid path 'deserializer-test:list-one-key=value/' at offset 37, \
+ error-info: Identifier may not be empty]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void validArgIdentifierListEndsWithSlashesNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:list-one-key=value//"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: malformed-message, "
- + "error-message: Invalid path 'deserializer-test:list-one-key=value//' at offset 37, "
- + "error-info: Identifier may not be empty]]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:list-one-key=value//"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: malformed-message, \
+ error-message: Invalid path 'deserializer-test:list-one-key=value//' at offset 37, \
+ error-info: Identifier may not be empty]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void prepareQnameEmptyIdentifierNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "/"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: malformed-message, "
- + "error-message: Invalid path '/' at offset 0, "
- + "error-info: Identifier may not be empty]]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "/"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: malformed-message, \
+ error-message: Invalid path '/' at offset 0, \
+ error-info: Identifier may not be empty]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void prepareQnameBuildPathNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test*contA"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: malformed-message, "
- + "error-message: Invalid path 'deserializer-test*contA' at offset 17, "
- + "error-info: Expecting [a-zA-Z_.-], not '*']]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test*contA"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: malformed-message, \
+ error-message: Invalid path 'deserializer-test*contA' at offset 17, \
+ error-info: Expecting [a-zA-Z_.-], not '*']]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void prepareQnameNotExistingPrefixNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "not-existing:contA"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: unknown-element, "
- + "error-message: Failed to lookup for module with name 'not-existing'.]]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "not-existing:contA"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: unknown-element, \
+ error-message: Failed to lookup for module with name 'not-existing'.]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void prepareQnameNotValidPrefixAndLocalNameNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class, () ->
- YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:*not-parsable-identifier"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: malformed-message, "
- + "error-message: Invalid path 'deserializer-test:*not-parsable-identifier' at offset 18, "
- + "error-info: Expecting [a-zA-Z_], not '*']]", ex.getMessage());
+ YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:*not-parsable-identifier"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: malformed-message, \
+ error-message: Invalid path 'deserializer-test:*not-parsable-identifier' at offset 18, \
+ error-info: Expecting [a-zA-Z_], not '*']]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void prepareQnameErrorParsingNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: malformed-message, "
- + "error-message: Invalid path 'deserializer-test:' at offset 18, "
- + "error-info: Identifier may not be empty]]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: malformed-message, \
+ error-message: Invalid path 'deserializer-test:' at offset 18, \
+ error-info: Identifier may not be empty]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void prepareQnameNotValidContainerNameNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:contA/leafB"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: data-missing, "
- + "error-message: Schema for '(deserializer:test?revision=2016-06-06)leafB' not found]]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:contA/leafB"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: data-missing, \
+ error-message: Schema for '(deserializer:test?revision=2016-06-06)leafB' not found]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void prepareQnameNotValidListNameNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
- "deserializer-test:list-no-key/disabled=false"));
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:list-no-key/disabled=false"));
assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
assertEquals(ErrorTag.DATA_MISSING, ex.getErrors().get(0).getErrorTag());
}
@Test
public void prepareIdentifierNotKeyedEntryNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:list-one-key"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: missing-attribute, "
- + "error-message: Entry '(deserializer:test?revision=2016-06-06)list-one-key' requires key or value "
- + "predicate to be present.]]", ex.getMessage());
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:list-one-key"));
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: missing-attribute, \
+ error-message: Entry '(deserializer:test?revision=2016-06-06)list-one-key' requires key or value \
+ predicate to be present.]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void deserializeKeysEndsWithCommaTooManyNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND,
"deserializer-test:list-multiple-keys=value,100,false,"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: unknown-attribute, "
- + "error-message: Schema for (deserializer:test?revision=2016-06-06)list-multiple-keys "
- + "requires 3 key values, 4 supplied]]", ex.getMessage());
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: unknown-attribute, \
+ error-message: Schema for (deserializer:test?revision=2016-06-06)list-multiple-keys requires 3 key values, \
+ 4 supplied]]""", ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@Test
public void deserializeKeysEndsWithCommaIllegalNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND,
"deserializer-test:list-multiple-keys=value,100,"));
- assertEquals("errors: [RestconfError [error-type: protocol, error-tag: invalid-value, "
- + "error-message: Invalid value '' for (deserializer:test?revision=2016-06-06)enabled, "
- + "error-info: Invalid value '' for boolean type. Allowed values are 'true' and 'false']]",
+ assertEquals("""
+ errors: [RestconfError [error-type: protocol, error-tag: invalid-value, \
+ error-message: Invalid value '' for (deserializer:test?revision=2016-06-06)enabled, \
+ error-info: Invalid value '' for boolean type. Allowed values are 'true' and 'false']]""",
ex.getMessage());
final var errors = ex.getErrors();
assertEquals(1, errors.size());
@Test
public void notAllListKeysEncodedPositiveTest() {
final QName list = QName.create("deserializer:test", "2016-06-06", "list-multiple-keys");
- final Map<QName, Object> values = ImmutableMap.of(
+ final var values = ImmutableMap.<QName, Object>of(
QName.create(list, "name"), ":foo",
QName.create(list, "number"), Uint8.ONE,
QName.create(list, "enabled"), false);
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND,
"deserializer-test:list-multiple-keys=%3Afoo,1,false/string-value").path.getPathArguments();
assertEquals(3, result.size());
// list
@Test
public void notAllListKeysEncodedNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND,
"deserializer-test:list-multiple-keys=%3Afoo/string-value"));
assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
assertEquals(ErrorTag.MISSING_ATTRIBUTE, ex.getErrors().get(0).getErrorTag());
@Test
public void percentEncodedKeyEndsWithNoPercentEncodedChars() {
final String URI = "deserializer-test:list-multiple-keys=%3Afoo,1,true";
- final YangInstanceIdentifier result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, URI).path;
+ final YangInstanceIdentifier result = YangInstanceIdentifierDeserializer.create(DATABIND, URI).path;
- final Iterator<Entry<QName, Object>> resultListKeys =
+ final var resultListKeys =
((NodeIdentifierWithPredicates)result.getLastPathArgument()).entrySet().iterator();
assertEquals(":foo", resultListKeys.next().getValue());
@Test
public void deserializeAllKeysEmptyTest() {
final QName list = QName.create("deserializer:test", "2016-06-06", "list-multiple-keys");
- final Map<QName, Object> values = ImmutableMap.of(
+ final var values = ImmutableMap.<QName, Object>of(
QName.create(list, "name"), "",
QName.create(list, "number"), Uint8.ZERO,
QName.create(list, "enabled"), true);
- final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND,
"deserializer-test:list-multiple-keys=,0,true").path.getPathArguments();
assertEquals(2, result.size());
assertEquals(NodeIdentifier.create(list), result.get(0));
@Test
public void leafListMissingKeyNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:leaf-list-0="));
+ () -> YangInstanceIdentifierDeserializer.create(DATABIND, "deserializer-test:leaf-list-0="));
assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
}
*/
@Test
public void deserializePartInOtherModuleTest() {
- final List<PathArgument> result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND,
"deserializer-test-included:augmented-list=100/deserializer-test:augmented-leaf")
.path.getPathArguments();
assertEquals(3, result.size());
@Test
public void deserializeListInOtherModuleTest() {
- final List<PathArgument> result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+ final var result = YangInstanceIdentifierDeserializer.create(DATABIND,
"deserializer-test-included:augmented-list=100/deserializer-test:augmenting-list=0")
.path.getPathArguments();
assertEquals(4, result.size());
}
private static void assertIdentityrefKeyValue(final String path) {
- final var pathArgs = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, path).path.getPathArguments();
+ final var pathArgs = YangInstanceIdentifierDeserializer.create(DATABIND, path).path.getPathArguments();
assertEquals(4, pathArgs.size());
assertEquals("refs", pathArgs.get(0).getNodeType().getLocalName());