|
| 1 | +package org.wildfly.prospero.it.cli; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.wildfly.prospero.test.TestLocalRepository.GALLEON_PLUGINS_VERSION; |
| 5 | + |
| 6 | +import java.io.IOException; |
| 7 | +import java.net.URL; |
| 8 | +import java.nio.file.Path; |
| 9 | +import java.util.Collections; |
| 10 | +import java.util.List; |
| 11 | +import java.util.regex.Matcher; |
| 12 | +import java.util.regex.Pattern; |
| 13 | + |
| 14 | +import org.apache.commons.lang3.tuple.Pair; |
| 15 | +import org.eclipse.aether.artifact.Artifact; |
| 16 | +import org.eclipse.aether.artifact.DefaultArtifact; |
| 17 | +import org.junit.Before; |
| 18 | +import org.junit.Test; |
| 19 | +import org.wildfly.channel.Channel; |
| 20 | +import org.wildfly.channel.ChannelManifest; |
| 21 | +import org.wildfly.channel.Stream; |
| 22 | +import org.wildfly.prospero.cli.CliMessages; |
| 23 | +import org.wildfly.prospero.cli.ReturnCodes; |
| 24 | +import org.wildfly.prospero.cli.commands.CliConstants; |
| 25 | +import org.wildfly.prospero.it.ExecutionUtils; |
| 26 | +import org.wildfly.prospero.test.BuildProperties; |
| 27 | +import org.wildfly.prospero.test.TestInstallation; |
| 28 | +import org.wildfly.prospero.test.TestLocalRepository; |
| 29 | + |
| 30 | +public class UpdateToVersionTest extends CliTestBase { |
| 31 | + protected static final String COMMONS_IO_VERSION = BuildProperties.getProperty("version.commons-io"); |
| 32 | + |
| 33 | + private TestLocalRepository testLocalRepository; |
| 34 | + private TestInstallation testInstallation; |
| 35 | + private Channel testChannel; |
| 36 | + |
| 37 | + @Before |
| 38 | + public void setUp() throws Exception { |
| 39 | + testLocalRepository = new TestLocalRepository(temp.newFolder("local-repo").toPath(), |
| 40 | + List.of(new URL("https://repo1.maven.org/maven2"))); |
| 41 | + |
| 42 | + prepareRequiredArtifacts(testLocalRepository); |
| 43 | + |
| 44 | + testInstallation = new TestInstallation(temp.newFolder("server").toPath()); |
| 45 | + |
| 46 | + testLocalRepository.deploy(TestInstallation.fpBuilder("org.test:pack-one:1.0.0") |
| 47 | + .addModule("commons-io", "commons-io", COMMONS_IO_VERSION) |
| 48 | + .build()); |
| 49 | + |
| 50 | + testChannel = new Channel.Builder() |
| 51 | + .setName("test-channel") |
| 52 | + .addRepository("local-repo", testLocalRepository.getUri().toString()) |
| 53 | + .setManifestCoordinate("org.test", "test-channel") |
| 54 | + .build(); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void installSpecificVersionOfManifest() throws Exception { |
| 59 | + testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), CliConstants.VERSION, "test-channel::1.0.0"); |
| 60 | + |
| 61 | + testInstallation.verifyModuleJar("commons-io", "commons-io", COMMONS_IO_VERSION); |
| 62 | + testInstallation.verifyInstallationMetadataPresent(); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void updateServerToNonLatestVersion() throws Exception { |
| 67 | + testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), CliConstants.VERSION, "test-channel::1.0.0"); |
| 68 | + |
| 69 | + testInstallation.update(CliConstants.VERSION, "test-channel::1.0.1"); |
| 70 | + |
| 71 | + testInstallation.verifyModuleJar("commons-io", "commons-io", bump(COMMONS_IO_VERSION)); |
| 72 | + testInstallation.verifyInstallationMetadataPresent(); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void downgradeServerToNonLatestVersion() throws Exception { |
| 77 | + testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1"); |
| 78 | + |
| 79 | + testInstallation.update(Collections.emptyList(), "--version=test-channel::1.0.0", CliConstants.YES); |
| 80 | + |
| 81 | + testInstallation.verifyModuleJar("commons-io", "commons-io", COMMONS_IO_VERSION); |
| 82 | + testInstallation.verifyInstallationMetadataPresent(); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + public void updateWithPrepareApplyServerToNonLatestVersion() throws Exception { |
| 87 | + testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), CliConstants.VERSION, "test-channel::1.0.0"); |
| 88 | + |
| 89 | + final Path candidatePath = temp.newFolder("candidate").toPath(); |
| 90 | + testInstallation.prepareUpdate(candidatePath, CliConstants.VERSION, "test-channel::1.0.1"); |
| 91 | + testInstallation.apply(candidatePath); |
| 92 | + |
| 93 | + testInstallation.verifyModuleJar("commons-io", "commons-io", bump(COMMONS_IO_VERSION)); |
| 94 | + testInstallation.verifyInstallationMetadataPresent(); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void warnIfDowngradeServerToNonLatestVersion() throws Exception { |
| 99 | + testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1", "-vv"); |
| 100 | + |
| 101 | + testInstallation.updateWithCheck( |
| 102 | + List.of( |
| 103 | + Pair.of(CliMessages.MESSAGES.continueWithUpdate(), "y"), |
| 104 | + Pair.of(CliMessages.MESSAGES.continueWithUpdate(), "y") |
| 105 | + ), |
| 106 | + (ExecutionUtils.ExecutionResult e)-> { |
| 107 | + try { |
| 108 | + e.assertReturnCode(ReturnCodes.SUCCESS); |
| 109 | + assertThat(e.getCommandOutput()) |
| 110 | + .contains("The update will downgrade following channels:") |
| 111 | + .contains(" * test-channel: 1.0.1 -> 1.0.0"); |
| 112 | + } catch (IOException ex) { |
| 113 | + throw new RuntimeException(ex); |
| 114 | + } |
| 115 | + }, |
| 116 | + "--version=test-channel::1.0.0", "-vv"); |
| 117 | + |
| 118 | + testInstallation.verifyModuleJar("commons-io", "commons-io", COMMONS_IO_VERSION); |
| 119 | + testInstallation.verifyInstallationMetadataPresent(); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + public void rejectDowngradeServerIfVersionNotSpecified() throws Exception { |
| 124 | + testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1", "-vv"); |
| 125 | + |
| 126 | + final TestLocalRepository newRepo = new TestLocalRepository(temp.newFolder("downgrade-repo").toPath(), List.of(new URL("https://repo1.maven.org/maven2"))); |
| 127 | + |
| 128 | + newRepo.deploy( |
| 129 | + new DefaultArtifact("org.test", "test-channel", "manifest", "yaml","1.0.0"), |
| 130 | + new ChannelManifest("test-manifest", null, null, List.of( |
| 131 | + new Stream("org.wildfly.galleon-plugins", "wildfly-config-gen", GALLEON_PLUGINS_VERSION), |
| 132 | + new Stream("org.wildfly.galleon-plugins", "wildfly-galleon-plugins", GALLEON_PLUGINS_VERSION), |
| 133 | + new Stream("commons-io", "commons-io", COMMONS_IO_VERSION), |
| 134 | + new Stream("org.test", "pack-one", "1.0.0") |
| 135 | + ))); |
| 136 | + |
| 137 | + testInstallation.updateWithCheck( |
| 138 | + Collections.emptyList(), |
| 139 | + (ExecutionUtils.ExecutionResult e)-> { |
| 140 | + try { |
| 141 | + e.assertReturnCode(ReturnCodes.PROCESSING_ERROR); |
| 142 | + assertThat(e.getCommandOutput()) |
| 143 | + .contains("The update will downgrade following channels:") |
| 144 | + .contains(" * test-channel: 1.0.1 -> 1.0.0"); |
| 145 | + } catch (IOException ex) { |
| 146 | + throw new RuntimeException(ex); |
| 147 | + } |
| 148 | + |
| 149 | + }, |
| 150 | + "--repositories", newRepo.getUri().toString()); |
| 151 | + |
| 152 | + testInstallation.verifyModuleJar("commons-io", "commons-io", COMMONS_IO_VERSION + ".CP-01"); |
| 153 | + testInstallation.verifyInstallationMetadataPresent(); |
| 154 | + } |
| 155 | + |
| 156 | + @Test |
| 157 | + public void listChannelVersionUpdates() throws Exception { |
| 158 | + testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1", "-vv"); |
| 159 | + |
| 160 | + assertThat(testInstallation.listChannelManifestUpdates(false).split("available versions")[1]) |
| 161 | + .contains("1.0.2") |
| 162 | + .doesNotContain("1.0.0", "1.0.1"); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void listAllChannelVersion() throws Exception { |
| 167 | + testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1", "-vv"); |
| 168 | + |
| 169 | + assertThat(testInstallation.listChannelManifestUpdates(true).split("available versions")[1]) |
| 170 | + .contains("1.0.0", "1.0.1", "1.0.2"); |
| 171 | + } |
| 172 | + |
| 173 | + @Test |
| 174 | + public void listUpdatesToSpecificVersion() throws Exception { |
| 175 | + testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.0", "-vv"); |
| 176 | + |
| 177 | + assertThat(testInstallation.listUpdates(CliConstants.VERSION, "test-channel::1.0.1")) |
| 178 | + .containsPattern("commons-io:commons-io\\s+2.18.0\\s+==>\\s+2.18.0.CP-01"); |
| 179 | + } |
| 180 | + |
| 181 | + private void prepareRequiredArtifacts(TestLocalRepository localRepository) throws Exception { |
| 182 | + localRepository.deployGalleonPlugins(); |
| 183 | + |
| 184 | + Artifact resolved = localRepository.resolveAndDeploy(new DefaultArtifact("commons-io", "commons-io", "jar", COMMONS_IO_VERSION)); |
| 185 | + resolved = resolved.setVersion(bump(resolved.getVersion())); |
| 186 | + localRepository.deploy(resolved); |
| 187 | + localRepository.deploy(resolved.setVersion(bump(resolved.getVersion()))); |
| 188 | + |
| 189 | + // deploy test manifests updating the commons-io in each |
| 190 | + localRepository.deploy( |
| 191 | + new DefaultArtifact("org.test", "test-channel", "manifest", "yaml","1.0.0"), |
| 192 | + new ChannelManifest("test-manifest", null, null, List.of( |
| 193 | + new Stream("org.wildfly.galleon-plugins", "wildfly-config-gen", GALLEON_PLUGINS_VERSION), |
| 194 | + new Stream("org.wildfly.galleon-plugins", "wildfly-galleon-plugins", GALLEON_PLUGINS_VERSION), |
| 195 | + new Stream("commons-io", "commons-io", COMMONS_IO_VERSION), |
| 196 | + new Stream("org.test", "pack-one", "1.0.0") |
| 197 | + ))); |
| 198 | + |
| 199 | + testLocalRepository.deploy( |
| 200 | + new DefaultArtifact("org.test", "test-channel", "manifest", "yaml","1.0.1"), |
| 201 | + new ChannelManifest("test-manifest", null, null, List.of( |
| 202 | + new Stream("org.wildfly.galleon-plugins", "wildfly-config-gen", GALLEON_PLUGINS_VERSION), |
| 203 | + new Stream("org.wildfly.galleon-plugins", "wildfly-galleon-plugins", GALLEON_PLUGINS_VERSION), |
| 204 | + new Stream("commons-io", "commons-io", bump(COMMONS_IO_VERSION)), |
| 205 | + new Stream("org.test", "pack-one", "1.0.0") |
| 206 | + ))); |
| 207 | + |
| 208 | + testLocalRepository.deploy( |
| 209 | + new DefaultArtifact("org.test", "test-channel", "manifest", "yaml","1.0.2"), |
| 210 | + new ChannelManifest("test-manifest", null, null, List.of( |
| 211 | + new Stream("org.wildfly.galleon-plugins", "wildfly-config-gen", GALLEON_PLUGINS_VERSION), |
| 212 | + new Stream("org.wildfly.galleon-plugins", "wildfly-galleon-plugins", GALLEON_PLUGINS_VERSION), |
| 213 | + new Stream("commons-io", "commons-io", bump(bump(COMMONS_IO_VERSION))), |
| 214 | + new Stream("org.test", "pack-one", "1.0.0") |
| 215 | + ))); |
| 216 | + } |
| 217 | + |
| 218 | + private String bump(String version) { |
| 219 | + final Pattern pattern = Pattern.compile(".*\\.CP-(\\d{2})"); |
| 220 | + final Matcher matcher = pattern.matcher(version); |
| 221 | + if (matcher.matches()) { |
| 222 | + final String suffixVersion = matcher.group(1); |
| 223 | + final int ver = Integer.parseInt(suffixVersion) + 1; |
| 224 | + final String replaced = version.replace(".CP-" + suffixVersion, String.format(".CP-%02d", ver)); |
| 225 | + return replaced; |
| 226 | + } else { |
| 227 | + return version + ".CP-01"; |
| 228 | + } |
| 229 | + } |
| 230 | +} |
0 commit comments