3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.db.permission.template;
22 import java.util.Date;
23 import java.util.function.Consumer;
24 import org.apache.commons.lang.math.RandomUtils;
25 import org.sonar.core.util.Uuids;
26 import org.sonar.db.permission.PermissionsTestHelper;
28 import static java.util.Arrays.stream;
29 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
30 import static org.apache.commons.lang.RandomStringUtils.randomAscii;
32 public class PermissionTemplateTesting {
34 public static PermissionTemplateDto newPermissionTemplateDto(Consumer<PermissionTemplateDto>... populators) {
35 PermissionTemplateDto dto = new PermissionTemplateDto()
36 .setName(randomAlphanumeric(60))
37 .setDescription(randomAscii(500))
38 .setUuid(Uuids.create())
39 .setCreatedAt(new Date())
40 .setUpdatedAt(new Date());
41 stream(populators).forEach(p -> p.accept(dto));
45 public static PermissionTemplateUserDto newPermissionTemplateUserDto() {
46 return new PermissionTemplateUserDto()
47 .setPermission(PermissionsTestHelper.ALL_PERMISSIONS.toArray(new String[0])[RandomUtils.nextInt(PermissionsTestHelper.ALL_PERMISSIONS.size())])
48 .setCreatedAt(new Date())
49 .setUpdatedAt(new Date());
52 public static PermissionTemplateGroupDto newPermissionTemplateGroupDto() {
53 return new PermissionTemplateGroupDto()
54 .setUuid(Uuids.createFast())
55 .setPermission(PermissionsTestHelper.ALL_PERMISSIONS.toArray(new String[0])[RandomUtils.nextInt(PermissionsTestHelper.ALL_PERMISSIONS.size())])
56 .setCreatedAt(new Date())
57 .setUpdatedAt(new Date());
60 public static PermissionTemplateCharacteristicDto newPermissionTemplateCharacteristicDto() {
61 return new PermissionTemplateCharacteristicDto()
62 .setUuid(Uuids.createFast())
63 .setPermission(PermissionsTestHelper.ALL_PERMISSIONS.toArray(new String[0])[RandomUtils.nextInt(PermissionsTestHelper.ALL_PERMISSIONS.size())])
64 .setWithProjectCreator(RandomUtils.nextBoolean())
65 .setCreatedAt(System.currentTimeMillis())
66 .setUpdatedAt(System.currentTimeMillis());