|
| 1 | +package org.labkey.test.params; |
| 2 | + |
| 3 | +import org.jetbrains.annotations.NotNull; |
| 4 | +import org.labkey.test.TestProperties; |
| 5 | +import org.labkey.test.util.AbstractContainerHelper; |
| 6 | +import org.labkey.test.util.TestDataGenerator; |
| 7 | + |
| 8 | +import java.util.Collections; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Objects; |
| 11 | + |
| 12 | +import static org.labkey.test.util.TestDataGenerator.ALL_CHARS_PLACEHOLDER; |
| 13 | +import static org.labkey.test.util.TestDataGenerator.WIDE_PLACEHOLDER; |
| 14 | +import static org.labkey.test.util.TextUtils.containerPath; |
| 15 | + |
| 16 | +public class ContainerInfo |
| 17 | +{ |
| 18 | + public static final String TRICKY_CHARACTERS = "\u2603~!@$&()_+{}-=[],.#\u00E4\u00F6\u00FC\u00C5" + WIDE_PLACEHOLDER + ALL_CHARS_PLACEHOLDER; // No slash or space |
| 19 | + |
| 20 | + private final @NotNull String _name; |
| 21 | + private final String _parentContainerPath; |
| 22 | + private final @NotNull String _containerPath; |
| 23 | + private final String _folderType; |
| 24 | + private final @NotNull List<String> _enableModules; |
| 25 | + |
| 26 | + protected ContainerInfo(String name, ContainerInfo parentContainer, String folderType, List<String> enableModules) |
| 27 | + { |
| 28 | + _parentContainerPath = parentContainer == null ? null : parentContainer.getContainerPath(); |
| 29 | + _name = Objects.requireNonNull(containerPath(name)); |
| 30 | + _containerPath = containerPath(_parentContainerPath, name); |
| 31 | + _folderType = folderType; |
| 32 | + _enableModules = enableModules == null || enableModules.isEmpty() ? Collections.emptyList() : List.copyOf(enableModules); |
| 33 | + } |
| 34 | + |
| 35 | + private static @NotNull String getRandomName(String folderName) |
| 36 | + { |
| 37 | + if (TestProperties.isTestRunningOnTeamCity()) |
| 38 | + return TestDataGenerator.randomName(folderName, TestDataGenerator.randomInt(0, 5), 5, TRICKY_CHARACTERS, null); |
| 39 | + else |
| 40 | + return folderName + TRICKY_CHARACTERS; |
| 41 | + } |
| 42 | + |
| 43 | + public static ContainerInfo folder(String folderName, ContainerInfo parentContainer, String folderType, List<String> enableModules) |
| 44 | + { |
| 45 | + return new ContainerInfo(getRandomName(folderName), parentContainer, folderType, enableModules); |
| 46 | + } |
| 47 | + |
| 48 | + public static ContainerInfo folder(String folderName, ContainerInfo parentContainer, String folderType) |
| 49 | + { |
| 50 | + return folder(folderName, parentContainer, folderType, null); |
| 51 | + } |
| 52 | + |
| 53 | + public static ContainerInfo folder(String folderName, ContainerInfo parentContainer) |
| 54 | + { |
| 55 | + return folder(folderName, parentContainer, null, null); |
| 56 | + } |
| 57 | + |
| 58 | + public static ContainerInfo project(String projectName, String folderType, List<String> enableModules) |
| 59 | + { |
| 60 | + return folder(projectName, null, folderType, enableModules); |
| 61 | + } |
| 62 | + |
| 63 | + public static ContainerInfo project(String projectName, String folderType) |
| 64 | + { |
| 65 | + return project(projectName, folderType, null); |
| 66 | + } |
| 67 | + |
| 68 | + public static ContainerInfo project(String projectName) |
| 69 | + { |
| 70 | + return project(projectName, null, null); |
| 71 | + } |
| 72 | + |
| 73 | + public void create(AbstractContainerHelper containerHelper) |
| 74 | + { |
| 75 | + create(containerHelper, _folderType); |
| 76 | + } |
| 77 | + |
| 78 | + public void create(AbstractContainerHelper containerHelper, String folderType) |
| 79 | + { |
| 80 | + if (isProject()) |
| 81 | + containerHelper.createProject(_name, folderType); |
| 82 | + else |
| 83 | + containerHelper.createSubfolder(_parentContainerPath, _name, folderType); |
| 84 | + if (!_enableModules.isEmpty()) |
| 85 | + { |
| 86 | + containerHelper.enableModules(_containerPath, _enableModules); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + public @NotNull String getName() |
| 91 | + { |
| 92 | + return _name; |
| 93 | + } |
| 94 | + |
| 95 | + public @NotNull String getContainerPath() |
| 96 | + { |
| 97 | + return _containerPath; |
| 98 | + } |
| 99 | + |
| 100 | + public boolean isProject() |
| 101 | + { |
| 102 | + return _parentContainerPath == null; |
| 103 | + } |
| 104 | + |
| 105 | +} |
0 commit comments