@SuppressWarnings( "unchecked" )
@Test
public void shouldFindAdjustChildIndexesAfterRemovalOfFirstSibling() {
Long workspaceId = 1L;
UUID parentUuid = UUID.randomUUID();
NamespaceEntity ns = NamespaceEntity.findByUri(manager, "http://www.example.com");
ChildId[] ids = createMixtureOfChildren(workspaceId, parentUuid, ns);
assertThat(ids.length, is(23));
// Look up the objects ...
manager.getTransaction().begin();
try {
Query query = manager.createNamedQuery("ChildEntity.findAllUnderParent");
query.setParameter("parentUuidString", parentUuid.toString());
query.setParameter("workspaceId", workspaceId);
List<ChildEntity> children = query.getResultList();
int index = 1;
assertThat(children.size(), is(23));
for (ChildEntity child : children) {
assertThat(child.getIndexInParent(), is(index++));
}
// Remove the first child ...
ChildEntity child = getChild(workspaceId, ids[0].getChildUuidString());
assertThat(child, is(notNullValue()));
String childName = child.getChildName();
manager.remove(child);
ChildEntity.adjustSnsIndexesAndIndexesAfterRemoving(manager,
workspaceId,
parentUuid.toString(),
childName,
ns.getId(),
0);
assertChildren(workspaceId, parentUuid.toString(),
// "child1",
"child2",