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.settings;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Properties;
24  import java.util.Random;
25  
26  import org.junit.jupiter.api.Test;
27  
28  import static org.junit.jupiter.api.Assertions.assertEquals;
29  import static org.junit.jupiter.api.AssertionsKt.assertNotNull;
30  
31  public class SettingsUtilsTest {
32  
33      @Test
34      public void testShouldAppendRecessivePluginGroupIds() {
35          Settings dominant = new Settings();
36          dominant.addPluginGroup("org.apache.maven.plugins");
37          dominant.addPluginGroup("org.codehaus.modello");
38  
39          Settings recessive = new Settings();
40          recessive.addPluginGroup("org.codehaus.plexus");
41  
42          SettingsUtils.merge(dominant, recessive, Settings.GLOBAL_LEVEL);
43  
44          List<String> pluginGroups = dominant.getPluginGroups();
45  
46          assertNotNull(pluginGroups);
47          assertEquals(3, pluginGroups.size());
48          assertEquals("org.apache.maven.plugins", pluginGroups.get(0));
49          assertEquals("org.codehaus.modello", pluginGroups.get(1));
50          assertEquals("org.codehaus.plexus", pluginGroups.get(2));
51      }
52  
53      public void testRoundTripProfiles() {
54          Random entropy = new Random();
55          Profile p = new Profile();
56          p.setId("id" + Long.toHexString(entropy.nextLong()));
57          Activation a = new Activation();
58          a.setActiveByDefault(entropy.nextBoolean());
59          a.setJdk("jdk" + Long.toHexString(entropy.nextLong()));
60          ActivationFile af = new ActivationFile();
61          af.setExists("exists" + Long.toHexString(entropy.nextLong()));
62          af.setMissing("missing" + Long.toHexString(entropy.nextLong()));
63          a.setFile(af);
64          ActivationProperty ap = new ActivationProperty();
65          ap.setName("name" + Long.toHexString(entropy.nextLong()));
66          ap.setValue("value" + Long.toHexString(entropy.nextLong()));
67          a.setProperty(ap);
68          ActivationOS ao = new ActivationOS();
69          ao.setArch("arch" + Long.toHexString(entropy.nextLong()));
70          ao.setFamily("family" + Long.toHexString(entropy.nextLong()));
71          ao.setName("name" + Long.toHexString(entropy.nextLong()));
72          ao.setVersion("version" + Long.toHexString(entropy.nextLong()));
73          a.setOs(ao);
74          p.setActivation(a);
75          Properties props = new Properties();
76          int count = entropy.nextInt(10);
77          for (int i = 0; i < count; i++) {
78              props.setProperty(
79                      "name" + Long.toHexString(entropy.nextLong()), "value" + Long.toHexString(entropy.nextLong()));
80          }
81          p.setProperties(props);
82          count = entropy.nextInt(3);
83          List<Repository> repos = new ArrayList<>();
84          for (int i = 0; i < count; i++) {
85              Repository r = new Repository();
86              r.setId("id" + Long.toHexString(entropy.nextLong()));
87              r.setName("name" + Long.toHexString(entropy.nextLong()));
88              r.setUrl("url" + Long.toHexString(entropy.nextLong()));
89              repos.add(r);
90          }
91          p.setRepositories(repos);
92          count = entropy.nextInt(3);
93          repos = new ArrayList<>();
94          for (int i = 0; i < count; i++) {
95              Repository r = new Repository();
96              r.setId("id" + Long.toHexString(entropy.nextLong()));
97              r.setName("name" + Long.toHexString(entropy.nextLong()));
98              r.setUrl("url" + Long.toHexString(entropy.nextLong()));
99              repos.add(r);
100         }
101         p.setPluginRepositories(repos);
102 
103         Profile clone = SettingsUtils.convertToSettingsProfile(SettingsUtils.convertFromSettingsProfile(p));
104 
105         assertEquals(p.getId(), clone.getId());
106         assertEquals(p.getActivation().getJdk(), clone.getActivation().getJdk());
107         assertEquals(
108                 p.getActivation().getFile().getExists(),
109                 clone.getActivation().getFile().getExists());
110         assertEquals(
111                 p.getActivation().getFile().getMissing(),
112                 clone.getActivation().getFile().getMissing());
113         assertEquals(
114                 p.getActivation().getProperty().getName(),
115                 clone.getActivation().getProperty().getName());
116         assertEquals(
117                 p.getActivation().getProperty().getValue(),
118                 clone.getActivation().getProperty().getValue());
119         assertEquals(
120                 p.getActivation().getOs().getArch(),
121                 clone.getActivation().getOs().getArch());
122         assertEquals(
123                 p.getActivation().getOs().getFamily(),
124                 clone.getActivation().getOs().getFamily());
125         assertEquals(
126                 p.getActivation().getOs().getName(),
127                 clone.getActivation().getOs().getName());
128         assertEquals(
129                 p.getActivation().getOs().getVersion(),
130                 clone.getActivation().getOs().getVersion());
131         assertEquals(p.getProperties(), clone.getProperties());
132         assertEquals(p.getRepositories().size(), clone.getRepositories().size());
133         // TODO deep compare the lists
134         assertEquals(
135                 p.getPluginRepositories().size(), clone.getPluginRepositories().size());
136         // TODO deep compare the lists
137     }
138 }