import com.google.common.base.Throwables;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
// FIXME: this method should only be invoked if we are crossing an implicit list.
@Override
void ensureParentsByMerge(final YangInstanceIdentifier path) {
- final var normalizedPathWithoutChildArgs = new ArrayList<YangInstanceIdentifier.PathArgument>();
- YangInstanceIdentifier rootNormalizedPath = null;
-
- final var it = path.getPathArguments().iterator();
-
- while (it.hasNext()) {
- final var pathArgument = it.next();
- if (rootNormalizedPath == null) {
- rootNormalizedPath = YangInstanceIdentifier.of(pathArgument);
- }
-
- if (it.hasNext()) {
- normalizedPathWithoutChildArgs.add(pathArgument);
- }
- }
-
- if (normalizedPathWithoutChildArgs.isEmpty()) {
- return;
+ final var parent = path.getParent();
+ if (parent != null) {
+ final var rootNormalizedPath = path.getAncestor(1);
+ merge(rootNormalizedPath, fromInstanceId(databind.modelContext(), parent));
}
-
- merge(rootNormalizedPath,
- fromInstanceId(databind.modelContext(), YangInstanceIdentifier.of(normalizedPathWithoutChildArgs)));
}
@Override
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
assertNotNull(dataPutRequest.getResult());
}
+ @Test
+ void testEnsureParentsByMerge() throws Exception {
+ doReturn(readWrite).when(dataBroker).newReadWriteTransaction();
+ doReturn(read).when(dataBroker).newReadOnlyTransaction();
+ doReturn(immediateFalseFluentFuture()).when(read).exists(LogicalDatastoreType.CONFIGURATION, GAP_IID);
+ doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, GAP_IID, GAP_LEAF);
+ doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
+ final var strategy = spy(jukeboxDataOperations());
+ final var tx = spy(jukeboxDataOperations().prepareWriteExecution());
+ doReturn(tx).when(strategy).prepareWriteExecution();
+
+ strategy.putData(dataPutRequest, GAP_PATH, GAP_LEAF);
+ verify(tx).merge(eq(GAP_IID.getAncestor(1)), any());
+ assertNotNull(dataPutRequest.getResult());
+ }
+
@Test
void testPutListData() throws Exception {
doReturn(readWrite).when(dataBroker).newReadWriteTransaction();