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