assertThat(savedGroup).containsExactlyInAnyOrderElementsOf(expectedGroups);
}
+ @Test
+ public void deleteByGroupUuid_deletesTheGroup() {
+ List<ExternalGroupDto> insertedGroups = createAndInsertExternalGroupDtos("provider1", 3);
+
+ ExternalGroupDto toRemove = insertedGroups.remove(0);
+ underTest.deleteByGroupUuid(dbSession, toRemove.groupUuid());
+ List<ExternalGroupDto> remainingGroups = underTest.selectByIdentityProvider(dbSession, "provider1");
+ assertThat(remainingGroups).containsExactlyInAnyOrderElementsOf(insertedGroups);
+ }
+
private List<ExternalGroupDto> createAndInsertExternalGroupDtos(String provider, int numberOfGroups) {
List<ExternalGroupDto> expectedExternalGroupDtos = new ArrayList<>();
for (int i = 1; i <= numberOfGroups; i++) {
return mapper(dbSession).selectByIdentityProvider(identityProvider);
}
+ public void deleteByGroupUuid(DbSession dbSession, String groupUuid) {
+ mapper(dbSession).deleteByGroupUuid(groupUuid);
+ }
+
private static ExternalGroupMapper mapper(DbSession session) {
return session.getMapper(ExternalGroupMapper.class);
}
package org.sonar.db.user;
import java.util.List;
+import org.apache.ibatis.annotations.Param;
public interface ExternalGroupMapper {
List<ExternalGroupDto> selectByIdentityProvider(String identityProvider);
+ void deleteByGroupUuid(@Param("groupUuid") String groupUuid);
+
+
}
WHERE eg.external_identity_provider=#{identityProvider,jdbcType=VARCHAR}
</select>
+ <delete id="deleteByGroupUuid" parameterType="String">
+ delete from external_groups where group_uuid = #{groupUuid, jdbcType=VARCHAR}
+ </delete>
+
</mapper>
removeGroupFromQualityProfileEdit(dbSession, group);
removeGroupFromQualityGateEdit(dbSession, group);
removeGroupScimLink(dbSession, group);
+ removeExternalGroupMapping(dbSession, group);
removeGroup(dbSession, group);
}
dbClient.scimGroupDao().deleteByGroupUuid(dbSession, group.getUuid());
}
+ private void removeExternalGroupMapping(DbSession dbSession, GroupDto group) {
+ dbClient.externalGroupDao().deleteByGroupUuid(dbSession, group.getUuid());
+ }
+
private void removeGroup(DbSession dbSession, GroupDto group) {
dbClient.groupDao().deleteByUuid(dbSession, group.getUuid(), group.getName());
}
import org.sonar.db.qualitygate.QualityGateGroupPermissionsDao;
import org.sonar.db.qualityprofile.QProfileEditGroupsDao;
import org.sonar.db.scim.ScimGroupDao;
+import org.sonar.db.user.ExternalGroupDao;
import org.sonar.db.user.GroupDao;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.RoleDao;
when(dbClient.qProfileEditGroupsDao()).thenReturn(mock(QProfileEditGroupsDao.class));
when(dbClient.qualityGateGroupPermissionsDao()).thenReturn(mock(QualityGateGroupPermissionsDao.class));
when(dbClient.scimGroupDao()).thenReturn(mock(ScimGroupDao.class));
+ when(dbClient.externalGroupDao()).thenReturn(mock(ExternalGroupDao.class));
when(dbClient.groupDao()).thenReturn(mock(GroupDao.class));
}
verify(dbClient.qProfileEditGroupsDao()).deleteByGroup(dbSession, groupDto);
verify(dbClient.qualityGateGroupPermissionsDao()).deleteByGroup(dbSession, groupDto);
verify(dbClient.scimGroupDao()).deleteByGroupUuid(dbSession, groupDto.getUuid());
+ verify(dbClient.externalGroupDao()).deleteByGroupUuid(dbSession, groupDto.getUuid());
verify(dbClient.groupDao()).deleteByUuid(dbSession, groupDto.getUuid(), groupDto.getName());
}
}