* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.restconf.nb.rfc8040.utils.parser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
+import com.google.common.collect.ImmutableSet;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@Before
public void init() throws Exception {
this.schemaContext =
- YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/parser/serializer"));
+ YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/parser/serializer"));
}
/**
final YangInstanceIdentifier data = YangInstanceIdentifier.builder()
.node(QName.create("serializer:test", "2016-06-06", "contA"))
.node(list)
- .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
- list, QName.create(list, "list-key"), 100))
+ .node(NodeIdentifierWithPredicates.of(list, QName.create(list, "list-key"), 100))
.node(leafList)
.node(new NodeWithValue<>(leafList, "instance"))
.build();
public void serializeListWithNoKeysTest() {
final YangInstanceIdentifier data = YangInstanceIdentifier.builder()
.node(QName.create("serializer:test", "2016-06-06", "list-no-key"))
- .nodeWithKey(QName.create("serializer:test", "2016-06-06", "list-no-key"), Maps.newHashMap())
+ .nodeWithKey(QName.create("serializer:test", "2016-06-06", "list-no-key"), new HashMap<>())
.build();
final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
@Test
public void serializeNullSchemaContextNegativeTest() {
this.thrown.expect(NullPointerException.class);
- YangInstanceIdentifierSerializer.create(null, YangInstanceIdentifier.EMPTY);
+ YangInstanceIdentifierSerializer.create(null, YangInstanceIdentifier.empty());
}
/**
*/
@Test
public void serializeEmptyDataTest() {
- final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, YangInstanceIdentifier.EMPTY);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext,
+ YangInstanceIdentifier.empty());
assertTrue("Empty identifier is expected", result.isEmpty());
}
/**
* Negative test when it is not possible to find child node of current node. Test is expected to fail with
- * <code>IllegalArgumentException</code> and error message is compared to expected error message.
+ * <code>RestconfDocumentedException</code> and error message is compared to expected error message.
*/
@Test
public void serializeChildNodeNotFoundNegativeTest() {
.node(QName.create("serializer:test", "2016-06-06", "not-existing-leaf"))
.build();
- this.thrown.expect(IllegalArgumentException.class);
+ this.thrown.expect(RestconfDocumentedException.class);
YangInstanceIdentifierSerializer.create(this.schemaContext, data);
}
final YangInstanceIdentifier data = YangInstanceIdentifier.builder()
.node(list)
- .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
- list, QName.create(list, "list-key"), 100))
- .node(new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(child)))
+ .node(NodeIdentifierWithPredicates.of(list, QName.create(list, "list-key"), 100))
+ .node(new AugmentationIdentifier(ImmutableSet.of(child)))
.node(child)
.build();
/**
* Test of serialization when nodes in input <code>YangInstanceIdentifier</code> are defined in two different
* modules by using augmentation. Augmented node in data supplied for serialization has wrong namespace.
- * <code>IllegalArgumentException</code> is expected because augmented node is defined in other module than its
+ * <code>RestconfDocumentedException</code> is expected because augmented node is defined in other module than its
* parent and will not be found.
*/
@Test
final YangInstanceIdentifier data = YangInstanceIdentifier.builder()
.node(list)
- .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
- list, QName.create(list, "list-key"), 100))
- .node(new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(child)))
+ .node(NodeIdentifierWithPredicates.of(list, QName.create(list, "list-key"), 100))
+ .node(new AugmentationIdentifier(ImmutableSet.of(child)))
.node(child)
.build();
- this.thrown.expect(IllegalArgumentException.class);
+ this.thrown.expect(RestconfDocumentedException.class);
YangInstanceIdentifierSerializer.create(this.schemaContext, data);
}
}