import static org.mockito.Mockito.mock;
import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
public class SnapshotBackedReadTransactionTest {
@Test
public void basicTest() throws Exception {
- final NormalizedNode testNode = mock(NormalizedNode.class);
- final Optional<NormalizedNode> optional = Optional.of(testNode);
+ final var testNode = mock(ContainerNode.class);
+ final var optional = Optional.of(testNode);
doReturn("testNode").when(testNode).toString();
- doReturn(Optional.of(testNode)).when(DATA_TREE_SNAPSHOT).readNode(YangInstanceIdentifier.empty());
- assertTrue(snapshotBackedReadTransaction.exists(YangInstanceIdentifier.empty()).get());
+ doReturn(Optional.of(testNode)).when(DATA_TREE_SNAPSHOT).readNode(YangInstanceIdentifier.of());
+ assertTrue(snapshotBackedReadTransaction.exists(YangInstanceIdentifier.of()).get());
- assertEquals(optional, snapshotBackedReadTransaction.read(YangInstanceIdentifier.empty()).get());
- final Field stableSnapshotField = SnapshotBackedReadTransaction.class.getDeclaredField("stableSnapshot");
+ assertEquals(optional, snapshotBackedReadTransaction.read(YangInstanceIdentifier.of()).get());
+ final var stableSnapshotField = SnapshotBackedReadTransaction.class.getDeclaredField("stableSnapshot");
stableSnapshotField.setAccessible(true);
DataTreeSnapshot stableSnapshot = (DataTreeSnapshot) stableSnapshotField.get(snapshotBackedReadTransaction);
@Test
public void readTestWithException() {
snapshotBackedReadTransaction.close();
- final var future = snapshotBackedReadTransaction.read(YangInstanceIdentifier.empty());
+ final var future = snapshotBackedReadTransaction.read(YangInstanceIdentifier.of());
final var cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
assertThat(cause, instanceOf(ReadFailedException.class));
assertEquals("Transaction is closed", cause.getMessage());
snapshotBackedReadTransaction = new SnapshotBackedReadTransaction<>(new Object(), false, DATA_TREE_SNAPSHOT,
null);
- final var future = snapshotBackedReadTransaction.read(YangInstanceIdentifier.empty());
+ final var future = snapshotBackedReadTransaction.read(YangInstanceIdentifier.of());
final var cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
assertThat(cause, instanceOf(ReadFailedException.class));
assertEquals("Read failed", cause.getMessage());
final var thrown = new NullPointerException("no Node");
doThrow(thrown).when(DATA_TREE_SNAPSHOT).readNode(any());
- final var future = snapshotBackedReadTransaction.exists(YangInstanceIdentifier.empty());
+ final var future = snapshotBackedReadTransaction.exists(YangInstanceIdentifier.of());
final var cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
assertThat(cause, instanceOf(ReadFailedException.class));
assertEquals("Read failed", cause.getMessage());