Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22131 from famod/maven-ci-friendly-illegal-placeh…
…older Reject illegal placeholder in Maven CI friendly version property
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/workspace/ModelUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.quarkus.bootstrap.resolver.maven.workspace; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import org.apache.maven.model.Model; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
public class ModelUtilsTest { | ||
|
||
@Test | ||
void resolveVersion_literal() { | ||
assertThat(ModelUtils.resolveVersion("1.0.0", new Model())).isEqualTo("1.0.0"); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { "${revision}", "${sha1}", "${changelist}" }) | ||
void resolveVersion_notResolvable(String rawVersion) { | ||
assertThat(ModelUtils.resolveVersion(rawVersion, new Model())).isNull(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { "revision", "sha1", "changelist" }) | ||
void resolveVersion_resolvable(String ciFriendlyPropertyName) { | ||
var model = new Model(); | ||
model.getProperties().put(ciFriendlyPropertyName, "1.0.0"); | ||
|
||
assertThat(ModelUtils.resolveVersion("${" + ciFriendlyPropertyName + "}", model)).isEqualTo("1.0.0"); | ||
} | ||
|
||
@Test | ||
void resolveVersion_allCiFriendlyPropertyNames() { | ||
var model = new Model(); | ||
model.getProperties().put("revision", "1"); | ||
model.getProperties().put("sha1", "2"); | ||
model.getProperties().put("changelist", "3"); | ||
|
||
assertThat(ModelUtils.resolveVersion("${revision}.${sha1}.${changelist}", model)).isEqualTo("1.2.3"); | ||
} | ||
|
||
@Test | ||
void resolveVersion_illegalPlaceholder() { | ||
var model = new Model(); | ||
model.getProperties().put("revision", "${main.project.version}"); | ||
model.getProperties().put("main.project.version", "1.6.0-SNAPSHOT"); | ||
|
||
assertThatThrownBy(() -> ModelUtils.resolveVersion("${revision}", model)) | ||
.isExactlyInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContainingAll("revision", "main.project.version"); | ||
} | ||
} |