diff --git a/afs-cassandra/src/main/java/com/powsybl/afs/cassandra/CassandraAppStorage.java b/afs-cassandra/src/main/java/com/powsybl/afs/cassandra/CassandraAppStorage.java index 8157f88c..658f1fc9 100644 --- a/afs-cassandra/src/main/java/com/powsybl/afs/cassandra/CassandraAppStorage.java +++ b/afs-cassandra/src/main/java/com/powsybl/afs/cassandra/CassandraAppStorage.java @@ -589,6 +589,7 @@ public void renameNode(String nodeId, String name) { getSession().execute(deleteFrom(CHILDREN_BY_NAME_AND_CLASS) .whereColumn(ID).isEqualTo(literal(parentNodeUuid)) .whereColumn(CHILD_NAME).isEqualTo(literal(nodeInfo.getName())) + .whereColumn(CHILD_PSEUDO_CLASS).isEqualTo(literal(nodeInfo.getPseudoClass())) .build()); getSession().execute(insertInto(CHILDREN_BY_NAME_AND_CLASS) diff --git a/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraAppStorageTest.java b/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraAppStorageTest.java index 141380a7..23f867c0 100644 --- a/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraAppStorageTest.java +++ b/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraAppStorageTest.java @@ -101,6 +101,9 @@ protected void nextDependentTests() { new CassandraRenameIssueTest().test(storage); clear(); + new CassandraRenameIssueTest().testRenameChildWithSameName(storage); + clear(); + new TimeSeriesIssueTest().testEmptyChunks(storage); clear(); new TimeSeriesIssueTest().testNullString(storage); diff --git a/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraRenameIssueTest.java b/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraRenameIssueTest.java index 309bd0fe..761207bf 100644 --- a/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraRenameIssueTest.java +++ b/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraRenameIssueTest.java @@ -10,7 +10,11 @@ import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; +import java.util.List; +import java.util.Optional; + import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author Geoffroy Jamgotchian @@ -32,4 +36,27 @@ public void test(AppStorage storage) { assertEquals(2, storage.getChildNodes(test1NodeInfo.getId()).size()); assertEquals("newtest1", storage.getNodeInfo(test1NodeInfo.getId()).getName()); } + + public void testRenameChildWithSameName(AppStorage storage) { + NodeInfo rootNodeId = storage.createRootNodeIfNotExists("test", "folder"); + NodeInfo test1NodeInfo = storage.createNode(rootNodeId.getId(), "test1", "folder", "", 0, new NodeGenericMetadata()); + storage.flush(); + NodeInfo test2Project = storage.createNode(test1NodeInfo.getId(), "test2", "project", "", 0, new NodeGenericMetadata()); + storage.setConsistent(test2Project.getId()); + NodeInfo test2Folder = storage.createNode(test1NodeInfo.getId(), "test2", "folder", "", 0, new NodeGenericMetadata()); + storage.setConsistent(test2Folder.getId()); + storage.flush(); + storage.renameNode(test2Project.getId(), "newTest2"); + storage.flush(); + List childNodes = storage.getChildNodes(test1NodeInfo.getId()); + assertEquals(2, childNodes.size()); + Optional first = childNodes.stream().filter(nodeInfo -> nodeInfo.getId().equals(test2Project.getId())).findFirst(); + assertTrue(first.isPresent()); + assertEquals("newTest2", first.get().getName()); + Optional second = childNodes.stream().filter(nodeInfo -> nodeInfo.getId().equals(test2Folder.getId())).findFirst(); + assertTrue(second.isPresent()); + assertEquals("test2", second.get().getName()); + assertEquals("test2", storage.getNodeInfo(test2Folder.getId()).getName()); + assertEquals("newTest2", storage.getNodeInfo(test2Project.getId()).getName()); + } }