Remove RestconfError.ErrorType
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / rests / utils / ReadDataTransactionUtilTest.java
index 15e2a00e748c0cb00b467ee322beb88b9da8fdf3..be1e939baea3b6f051869b7bc9e6bd96dd99b3b6 100644 (file)
@@ -42,14 +42,15 @@ import org.opendaylight.restconf.common.context.WriterParameters;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.ReadData;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.ReadData.WithDefaults;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
@@ -65,8 +66,8 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 public class ReadDataTransactionUtilTest {
 
     private static final TestData DATA = new TestData();
-    private static final YangInstanceIdentifier.NodeIdentifier NODE_IDENTIFIER = new YangInstanceIdentifier
-            .NodeIdentifier(QName.create("ns", "2016-02-28", "container"));
+    private static final NodeIdentifier NODE_IDENTIFIER =
+        new NodeIdentifier(QName.create("ns", "2016-02-28", "container"));
 
     private RestconfStrategy mdsalStrategy;
     private RestconfStrategy netconfStrategy;
@@ -106,7 +107,7 @@ public class ReadDataTransactionUtilTest {
                 .read(LogicalDatastoreType.CONFIGURATION, DATA.path);
         doReturn(immediateFluentFuture(Optional.of(DATA.data3))).when(this.netconfService).getConfig(DATA.path);
         final String valueOfContent = RestconfDataServiceConstant.ReadData.CONFIG;
-        NormalizedNode<?, ?> normalizedNode = readData(valueOfContent, DATA.path, mdsalStrategy);
+        NormalizedNode normalizedNode = readData(valueOfContent, DATA.path, mdsalStrategy);
         assertEquals(DATA.data3, normalizedNode);
 
         normalizedNode = readData(valueOfContent, DATA.path, netconfStrategy);
@@ -122,7 +123,7 @@ public class ReadDataTransactionUtilTest {
         doReturn(immediateFluentFuture(Optional.of(DATA.data3))).when(this.netconfService).getConfig(DATA.path);
         doReturn(immediateFluentFuture(Optional.empty())).when(this.netconfService).get(DATA.path);
         final String valueOfContent = RestconfDataServiceConstant.ReadData.ALL;
-        NormalizedNode<?, ?> normalizedNode = readData(valueOfContent, DATA.path, mdsalStrategy);
+        NormalizedNode normalizedNode = readData(valueOfContent, DATA.path, mdsalStrategy);
         assertEquals(DATA.data3, normalizedNode);
 
         normalizedNode = readData(valueOfContent, DATA.path, netconfStrategy);
@@ -138,7 +139,7 @@ public class ReadDataTransactionUtilTest {
         doReturn(immediateFluentFuture(Optional.of(DATA.data2))).when(this.netconfService).get(DATA.path2);
         doReturn(immediateFluentFuture(Optional.empty())).when(this.netconfService).getConfig(DATA.path2);
         final String valueOfContent = RestconfDataServiceConstant.ReadData.ALL;
-        NormalizedNode<?, ?> normalizedNode = readData(valueOfContent, DATA.path2, mdsalStrategy);
+        NormalizedNode normalizedNode = readData(valueOfContent, DATA.path2, mdsalStrategy);
         assertEquals(DATA.data2, normalizedNode);
 
         normalizedNode = readData(valueOfContent, DATA.path2, netconfStrategy);
@@ -151,7 +152,7 @@ public class ReadDataTransactionUtilTest {
                 .read(LogicalDatastoreType.OPERATIONAL, DATA.path2);
         doReturn(immediateFluentFuture(Optional.of(DATA.data2))).when(this.netconfService).get(DATA.path2);
         final String valueOfContent = RestconfDataServiceConstant.ReadData.NONCONFIG;
-        NormalizedNode<?, ?> normalizedNode = readData(valueOfContent, DATA.path2, mdsalStrategy);
+        NormalizedNode normalizedNode = readData(valueOfContent, DATA.path2, mdsalStrategy);
         assertEquals(DATA.data2, normalizedNode);
 
         normalizedNode = readData(valueOfContent, DATA.path2, netconfStrategy);
@@ -173,7 +174,7 @@ public class ReadDataTransactionUtilTest {
                 .withChild(DATA.contentLeaf)
                 .withChild(DATA.contentLeaf2)
                 .build();
-        NormalizedNode<?, ?> normalizedNode = readData(valueOfContent, DATA.path, mdsalStrategy);
+        NormalizedNode normalizedNode = readData(valueOfContent, DATA.path, mdsalStrategy);
         assertEquals(checkingData, normalizedNode);
 
         normalizedNode = readData(valueOfContent, DATA.path, netconfStrategy);
@@ -194,8 +195,7 @@ public class ReadDataTransactionUtilTest {
                 .withChild(DATA.contentLeaf)
                 .withChild(DATA.contentLeaf2)
                 .build();
-        NormalizedNode<?, ?> normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.path,
-                mdsalStrategy);
+        NormalizedNode normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.path, mdsalStrategy);
         assertEquals(checkingData, normalizedNode);
 
         normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.path, netconfStrategy);
@@ -213,10 +213,10 @@ public class ReadDataTransactionUtilTest {
         final String valueOfContent = RestconfDataServiceConstant.ReadData.ALL;
         final MapNode checkingData = Builders
                 .mapBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("ns", "2016-02-28", "list")))
+                .withNodeIdentifier(new NodeIdentifier(QName.create("ns", "2016-02-28", "list")))
                 .withChild(DATA.checkData)
                 .build();
-        NormalizedNode<?, ?> normalizedNode = readData(valueOfContent, DATA.path3, mdsalStrategy);
+        NormalizedNode normalizedNode = readData(valueOfContent, DATA.path3, mdsalStrategy);
         assertEquals(checkingData, normalizedNode);
 
         normalizedNode = readData(valueOfContent, DATA.path3, netconfStrategy);
@@ -233,9 +233,10 @@ public class ReadDataTransactionUtilTest {
         doReturn(immediateFluentFuture(Optional.of(DATA.orderedMapNode2))).when(this.netconfService)
                 .getConfig(DATA.path3);
         final MapNode expectedData = Builders.orderedMapBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(DATA.listQname)).withChild(DATA.checkData)
+                .withNodeIdentifier(new NodeIdentifier(DATA.listQname))
+                .withChild(DATA.checkData)
                 .build();
-        NormalizedNode<?, ?> normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.path3,
+        NormalizedNode normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.path3,
                 mdsalStrategy);
         assertEquals(expectedData, normalizedNode);
 
@@ -253,13 +254,12 @@ public class ReadDataTransactionUtilTest {
         doReturn(immediateFluentFuture(Optional.of(DATA.unkeyedListNode2))).when(this.netconfService)
                 .getConfig(DATA.path3);
         final UnkeyedListNode expectedData = Builders.unkeyedListBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(DATA.listQname))
-                .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(
-                        new YangInstanceIdentifier.NodeIdentifier(DATA.listQname))
-                        .withChild(DATA.unkeyedListEntryNode1.getValue().iterator().next())
-                        .withChild(DATA.unkeyedListEntryNode2.getValue().iterator().next()).build()).build();
-        NormalizedNode<?, ?> normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL,
-                DATA.path3, mdsalStrategy);
+                .withNodeIdentifier(new NodeIdentifier(DATA.listQname))
+                .withChild(Builders.unkeyedListEntryBuilder()
+                        .withNodeIdentifier(new NodeIdentifier(DATA.listQname))
+                        .withChild(DATA.unkeyedListEntryNode1.body().iterator().next())
+                        .withChild(DATA.unkeyedListEntryNode2.body().iterator().next()).build()).build();
+        NormalizedNode normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.path3, mdsalStrategy);
         assertEquals(expectedData, normalizedNode);
 
         normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.path3, netconfStrategy);
@@ -276,11 +276,14 @@ public class ReadDataTransactionUtilTest {
                 .get(DATA.leafSetNodePath);
         doReturn(immediateFluentFuture(Optional.of(DATA.leafSetNode2))).when(this.netconfService)
                 .getConfig(DATA.leafSetNodePath);
-        final LeafSetNode<String> expectedData = Builders.<String>leafSetBuilder().withNodeIdentifier(
-                new YangInstanceIdentifier.NodeIdentifier(DATA.leafListQname)).withValue(
-                        ImmutableList.<LeafSetEntryNode<String>>builder().addAll(DATA.leafSetNode1.getValue())
-                        .addAll(DATA.leafSetNode2.getValue()).build()).build();
-        NormalizedNode<?, ?> normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.leafSetNodePath,
+        final LeafSetNode<String> expectedData = Builders.<String>leafSetBuilder()
+                .withNodeIdentifier(new NodeIdentifier(DATA.leafListQname))
+                .withValue(ImmutableList.<LeafSetEntryNode<String>>builder()
+                        .addAll(DATA.leafSetNode1.body())
+                        .addAll(DATA.leafSetNode2.body())
+                        .build())
+                .build();
+        NormalizedNode normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.leafSetNodePath,
                 mdsalStrategy);
         assertEquals(expectedData, normalizedNode);
 
@@ -298,11 +301,14 @@ public class ReadDataTransactionUtilTest {
                 .get(DATA.leafSetNodePath);
         doReturn(immediateFluentFuture(Optional.of(DATA.orderedLeafSetNode2))).when(this.netconfService)
                 .getConfig(DATA.leafSetNodePath);
-        final LeafSetNode<String> expectedData = Builders.<String>orderedLeafSetBuilder().withNodeIdentifier(
-                new YangInstanceIdentifier.NodeIdentifier(DATA.leafListQname)).withValue(
-                        ImmutableList.<LeafSetEntryNode<String>>builder().addAll(DATA.orderedLeafSetNode1.getValue())
-                        .addAll(DATA.orderedLeafSetNode2.getValue()).build()).build();
-        NormalizedNode<?, ?> normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.leafSetNodePath,
+        final LeafSetNode<String> expectedData = Builders.<String>orderedLeafSetBuilder()
+                .withNodeIdentifier(new NodeIdentifier(DATA.leafListQname))
+                .withValue(ImmutableList.<LeafSetEntryNode<String>>builder()
+                        .addAll(DATA.orderedLeafSetNode1.body())
+                        .addAll(DATA.orderedLeafSetNode2.body())
+                        .build())
+                .build();
+        NormalizedNode normalizedNode = readData(RestconfDataServiceConstant.ReadData.ALL, DATA.leafSetNodePath,
                 mdsalStrategy);
         assertEquals(expectedData, normalizedNode);
 
@@ -316,7 +322,7 @@ public class ReadDataTransactionUtilTest {
                 .read(LogicalDatastoreType.CONFIGURATION, DATA.path2);
         doReturn(immediateFluentFuture(Optional.empty())).when(this.netconfService).getConfig(DATA.path2);
         final String valueOfContent = RestconfDataServiceConstant.ReadData.CONFIG;
-        NormalizedNode<?, ?> normalizedNode = readData(valueOfContent, DATA.path2, mdsalStrategy);
+        NormalizedNode normalizedNode = readData(valueOfContent, DATA.path2, mdsalStrategy);
         assertNull(normalizedNode);
 
         normalizedNode = readData(valueOfContent, DATA.path2, netconfStrategy);
@@ -326,7 +332,7 @@ public class ReadDataTransactionUtilTest {
     @Test(expected = RestconfDocumentedException.class)
     public void readDataFailTest() {
         final String valueOfContent = "nonsense";
-        NormalizedNode<?, ?> normalizedNode = readData(valueOfContent, null, mdsalStrategy);
+        NormalizedNode normalizedNode = readData(valueOfContent, null, mdsalStrategy);
         assertNull(normalizedNode);
 
         normalizedNode = readData(valueOfContent, null, netconfStrategy);
@@ -575,9 +581,13 @@ public class ReadDataTransactionUtilTest {
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ReadDataTransactionUtil.checkParameterCount(List.of("config", "nonconfig", "all"),
                     RestconfDataServiceConstant.ReadData.CONTENT));
-        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
-        assertEquals("Error status code is not correct", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        final List<RestconfError> errors = ex.getErrors();
+        assertEquals(1, errors.size());
+
+        final RestconfError error = errors.get(0);
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, error.getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, error.getErrorTag());
+        assertEquals("Error status code is not correct", 400, error.getErrorTag().getStatusCode());
     }
 
 
@@ -587,7 +597,7 @@ public class ReadDataTransactionUtilTest {
     @Test
     public void checkParametersTypesTest() {
         ReadDataTransactionUtil.checkParametersTypes(Set.of("content"),
-                RestconfDataServiceConstant.ReadData.CONTENT, RestconfDataServiceConstant.ReadData.DEPTH);
+            Set.of(RestconfDataServiceConstant.ReadData.CONTENT, RestconfDataServiceConstant.ReadData.DEPTH));
     }
 
     /**
@@ -597,10 +607,14 @@ public class ReadDataTransactionUtilTest {
     public void checkParametersTypesNegativeTest() {
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ReadDataTransactionUtil.checkParametersTypes(Set.of("not-allowed-parameter"),
-                    RestconfDataServiceConstant.ReadData.CONTENT, RestconfDataServiceConstant.ReadData.DEPTH));
-        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
-        assertEquals("Error status code is not correct", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+                Set.of(RestconfDataServiceConstant.ReadData.CONTENT, RestconfDataServiceConstant.ReadData.DEPTH)));
+        final List<RestconfError> errors = ex.getErrors();
+        assertEquals(1, errors.size());
+
+        final RestconfError error = errors.get(0);
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, error.getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, error.getErrorTag());
+        assertEquals("Error status code is not correct", 400, error.getErrorTag().getStatusCode());
     }
 
     /**
@@ -610,7 +624,7 @@ public class ReadDataTransactionUtilTest {
      * @param strategy       {@link RestconfStrategy} - wrapper for variables
      * @return {@link NormalizedNode}
      */
-    private @Nullable NormalizedNode<?, ?> readData(final @NonNull String valueOfContent,
+    private @Nullable NormalizedNode readData(final @NonNull String valueOfContent,
             final YangInstanceIdentifier path, final @NonNull RestconfStrategy strategy) {
         return ReadDataTransactionUtil.readData(valueOfContent, path, strategy, null, schemaContext);
     }