Fixed wrong exception types
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / utils / parser / YangInstanceIdentifierSerializerTest.java
index b508f2048e01b0ee26545ef744896319ecc17998..36ee08edc3daea01a230bf4cf2c88094c9707d3c 100644 (file)
@@ -5,13 +5,12 @@
  * 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.Sets;
+import com.google.common.collect.ImmutableSet;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -19,10 +18,13 @@ 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;
@@ -86,8 +88,7 @@ public class YangInstanceIdentifierSerializerTest {
         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();
@@ -190,7 +191,7 @@ public class YangInstanceIdentifierSerializerTest {
     @Test
     public void serializeNullSchemaContextNegativeTest() {
         this.thrown.expect(NullPointerException.class);
-        YangInstanceIdentifierSerializer.create(null, YangInstanceIdentifier.EMPTY);
+        YangInstanceIdentifierSerializer.create(null, YangInstanceIdentifier.empty());
     }
 
     /**
@@ -211,13 +212,14 @@ public class YangInstanceIdentifierSerializerTest {
      */
     @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() {
@@ -226,7 +228,7 @@ public class YangInstanceIdentifierSerializerTest {
                 .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);
     }
 
@@ -296,9 +298,8 @@ public class YangInstanceIdentifierSerializerTest {
 
         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();
 
@@ -311,7 +312,7 @@ public class YangInstanceIdentifierSerializerTest {
     /**
      * 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
@@ -322,13 +323,12 @@ public class YangInstanceIdentifierSerializerTest {
 
         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);
     }
 }