Correct links used in upgrade issues
Update BOMR so that the `Upgrade` type now contains a copy of the library we're upgrading to complete with an updated version number. This allows the correct links to be generated. Closes gh-43545
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2024-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.bom.bomr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.api.internal.tasks.userinput.UserInputHandler;
|
||||
import org.gradle.api.provider.Provider;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.build.bom.Library;
|
||||
import org.springframework.boot.build.bom.Library.LibraryVersion;
|
||||
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link InteractiveUpgradeResolver}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class InteractiveUpgradeResolverTests {
|
||||
|
||||
@Test
|
||||
void resolveUpgradeUpdateVersionNumberInLibrary() {
|
||||
UserInputHandler userInputHandler = mock(UserInputHandler.class);
|
||||
LibraryUpdateResolver libaryUpdateResolver = mock(LibraryUpdateResolver.class);
|
||||
InteractiveUpgradeResolver upgradeResolver = new InteractiveUpgradeResolver(userInputHandler,
|
||||
libaryUpdateResolver);
|
||||
List<Library> libraries = new ArrayList<>();
|
||||
DependencyVersion version = DependencyVersion.parse("1.0.0");
|
||||
LibraryVersion libraryVersion = new LibraryVersion(version);
|
||||
Library library = new Library("test", null, libraryVersion, null, null, false, null, null, null, null);
|
||||
libraries.add(library);
|
||||
List<Library> librariesToUpgrade = new ArrayList<>();
|
||||
librariesToUpgrade.add(library);
|
||||
List<LibraryWithVersionOptions> updates = new ArrayList<>();
|
||||
DependencyVersion updateVersion = DependencyVersion.parse("1.0.1");
|
||||
VersionOption versionOption = new VersionOption(updateVersion);
|
||||
updates.add(new LibraryWithVersionOptions(library, List.of(versionOption)));
|
||||
given(libaryUpdateResolver.findLibraryUpdates(any(), any())).willReturn(updates);
|
||||
Provider<Object> providerOfVersionOption = providerOf(versionOption);
|
||||
given(userInputHandler.askUser(any())).willReturn(providerOfVersionOption);
|
||||
List<Upgrade> upgrades = upgradeResolver.resolveUpgrades(librariesToUpgrade, libraries);
|
||||
assertThat(upgrades.get(0).to().getVersion().getVersion()).isEqualTo(updateVersion);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private <T> Provider<T> providerOf(VersionOption versionOption) {
|
||||
Provider provider = mock(Provider.class);
|
||||
given(provider.get()).willReturn(versionOption);
|
||||
return provider;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2024-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.bom.bomr;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.build.bom.Library;
|
||||
import org.springframework.boot.build.bom.Library.LibraryVersion;
|
||||
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link Upgrade}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class UpgradeTests {
|
||||
|
||||
@Test
|
||||
void createToRelease() {
|
||||
Library from = new Library("Test", null, new LibraryVersion(DependencyVersion.parse("1.0.0")), null, null,
|
||||
false, null, null, null, null);
|
||||
Upgrade upgrade = new Upgrade(from, DependencyVersion.parse("1.0.1"));
|
||||
assertThat(upgrade.from().getNameAndVersion()).isEqualTo("Test 1.0.0");
|
||||
assertThat(upgrade.to().getNameAndVersion()).isEqualTo("Test 1.0.1");
|
||||
assertThat(upgrade.toRelease().getNameAndVersion()).isEqualTo("Test 1.0.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createToSnapshot() {
|
||||
Library from = new Library("Test", null, new LibraryVersion(DependencyVersion.parse("1.0.0")), null, null,
|
||||
false, null, null, null, null);
|
||||
Upgrade upgrade = new Upgrade(from, DependencyVersion.parse("1.0.1-SNAPSHOT"));
|
||||
assertThat(upgrade.from().getNameAndVersion()).isEqualTo("Test 1.0.0");
|
||||
assertThat(upgrade.to().getNameAndVersion()).isEqualTo("Test 1.0.1-SNAPSHOT");
|
||||
assertThat(upgrade.toRelease().getNameAndVersion()).isEqualTo("Test 1.0.1");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user