|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
5 | 5 | * use this file except in compliance with the License. You may obtain a copy of
|
|
16 | 16 |
|
17 | 17 | package io.spring.gradle.convention;
|
18 | 18 |
|
| 19 | +import java.io.File; |
| 20 | +import java.util.Arrays; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.Map; |
| 23 | + |
19 | 24 | import io.spring.gradle.IncludeRepoTask;
|
20 | 25 | import org.apache.commons.io.FileUtils;
|
21 | 26 | import org.gradle.api.Project;
|
|
24 | 29 | import org.junit.jupiter.api.AfterEach;
|
25 | 30 | import org.junit.jupiter.api.Test;
|
26 | 31 |
|
27 |
| -import java.util.Arrays; |
28 |
| - |
29 | 32 | import static org.assertj.core.api.Assertions.assertThat;
|
30 | 33 |
|
31 | 34 | class IncludeCheckRemotePluginTest {
|
@@ -68,6 +71,40 @@ void applyWhenExtensionPropertiesTasksThenCreateCheckRemoteWithProvidedTasks() {
|
68 | 71 | assertThat(checkRemote.getTasks()).containsExactly("clean", "build", "test");
|
69 | 72 | }
|
70 | 73 |
|
| 74 | + @Test |
| 75 | + void applyWhenExtensionPropertiesInitScriptsThenCreateCheckRemoteWithProvidedTasks() { |
| 76 | + this.rootProject = ProjectBuilder.builder().build(); |
| 77 | + this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); |
| 78 | + this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, |
| 79 | + (includeCheckRemoteExtension) -> { |
| 80 | + includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); |
| 81 | + includeCheckRemoteExtension.setProperty("ref", "main"); |
| 82 | + includeCheckRemoteExtension.setProperty("initScripts", Arrays.asList("spring-security-ci.gradle")); |
| 83 | + }); |
| 84 | + |
| 85 | + GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); |
| 86 | + assertThat(checkRemote.getStartParameter().getAllInitScripts()).extracting(File::getName).containsExactly("spring-security-ci.gradle"); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + void applyWhenExtensionPropertiesBuildPropertiesThenCreateCheckRemoteWithProvidedTasks() { |
| 91 | + Map<String, String> projectProperties = new HashMap<>(); |
| 92 | + projectProperties.put("localRepositoryPath", "~/local/repository"); |
| 93 | + projectProperties.put("anotherProperty", "some_value"); |
| 94 | + this.rootProject = ProjectBuilder.builder().build(); |
| 95 | + this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); |
| 96 | + this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, |
| 97 | + (includeCheckRemoteExtension) -> { |
| 98 | + includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); |
| 99 | + includeCheckRemoteExtension.setProperty("ref", "main"); |
| 100 | + includeCheckRemoteExtension.setProperty("projectProperties", projectProperties); |
| 101 | + }); |
| 102 | + |
| 103 | + GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); |
| 104 | + assertThat(checkRemote.getStartParameter().getProjectProperties()).containsEntry("localRepositoryPath", "~/local/repository") |
| 105 | + .containsEntry("anotherProperty", "some_value"); |
| 106 | + } |
| 107 | + |
71 | 108 | @Test
|
72 | 109 | void applyWhenExtensionPropertiesThenRegisterIncludeRepoTaskWithExtensionProperties() {
|
73 | 110 | this.rootProject = ProjectBuilder.builder().build();
|
|
0 commit comments