1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
130 assertEquals(
131 p.getPluginRepositories().size(), clone.getPluginRepositories().size());
132
133 }
134 }