View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.execution;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Properties;
24  
25  import org.apache.maven.model.Build;
26  import org.apache.maven.project.MavenProject;
27  import org.junit.jupiter.api.Test;
28  
29  import static java.util.Collections.singleton;
30  import static org.hamcrest.MatcherAssert.assertThat;
31  import static org.hamcrest.Matchers.containsInAnyOrder;
32  import static org.hamcrest.Matchers.empty;
33  import static org.hamcrest.Matchers.is;
34  
35  class DefaultBuildResumptionDataRepositoryTest {
36      private final DefaultBuildResumptionDataRepository repository = new DefaultBuildResumptionDataRepository();
37  
38      @Test
39      void resumeFromPropertyGetsApplied() {
40          MavenExecutionRequest request = new DefaultMavenExecutionRequest();
41          Properties properties = new Properties();
42          properties.setProperty("remainingProjects", ":module-a");
43  
44          repository.applyResumptionProperties(request, properties);
45  
46          assertThat(request.getProjectActivation().getOptionalActiveProjectSelectors(), is(singleton(":module-a")));
47      }
48  
49      @Test
50      void resumeFromPropertyDoesNotOverrideExistingRequestParameters() {
51          MavenExecutionRequest request = new DefaultMavenExecutionRequest();
52          request.setResumeFrom(":module-b");
53          Properties properties = new Properties();
54          properties.setProperty("remainingProjects", ":module-a");
55  
56          repository.applyResumptionProperties(request, properties);
57  
58          assertThat(request.getResumeFrom(), is(":module-b"));
59      }
60  
61      @Test
62      void projectsFromPropertyGetsAddedToExistingRequestParameters() {
63          MavenExecutionRequest request = new DefaultMavenExecutionRequest();
64          List<String> selectedProjects = new ArrayList<>();
65          selectedProjects.add(":module-a");
66          request.setSelectedProjects(selectedProjects);
67          Properties properties = new Properties();
68          properties.setProperty("remainingProjects", ":module-b, :module-c");
69  
70          repository.applyResumptionProperties(request, properties);
71  
72          assertThat(
73                  request.getProjectActivation().getOptionalActiveProjectSelectors(),
74                  containsInAnyOrder(":module-a", ":module-b", ":module-c"));
75      }
76  
77      @Test
78      void selectedProjectsAreNotAddedWhenPropertyValueIsEmpty() {
79          MavenExecutionRequest request = new DefaultMavenExecutionRequest();
80          Properties properties = new Properties();
81          properties.setProperty("remainingProjects", "");
82  
83          repository.applyResumptionProperties(request, properties);
84  
85          assertThat(request.getProjectActivation().getOptionalActiveProjectSelectors(), is(empty()));
86      }
87  
88      @Test
89      void applyResumptionData_shouldLoadData() {
90          MavenExecutionRequest request = new DefaultMavenExecutionRequest();
91          Build build = new Build();
92          build.setDirectory("src/test/resources/org/apache/maven/execution/");
93          MavenProject rootProject = new MavenProject();
94          rootProject.setBuild(build);
95  
96          repository.applyResumptionData(request, rootProject);
97  
98          assertThat(
99                  request.getProjectActivation().getOptionalActiveProjectSelectors(),
100                 containsInAnyOrder("example:module-c"));
101     }
102 }