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;
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;
.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);
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);
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);
.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);
.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);
.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);
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);
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);
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);
.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);
.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);
.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);
@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);
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());
}
@Test
public void checkParametersTypesTest() {
ReadDataTransactionUtil.checkParametersTypes(Set.of("content"),
- RestconfDataServiceConstant.ReadData.CONTENT, RestconfDataServiceConstant.ReadData.DEPTH);
+ Set.of(RestconfDataServiceConstant.ReadData.CONTENT, RestconfDataServiceConstant.ReadData.DEPTH));
}
/**
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());
}
/**
* @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);
}