1 package org.apache.maven.settings;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Properties;
27 import java.util.Random;
28
29 public class SettingsUtilsTest
30 extends TestCase
31 {
32
33 public void testShouldAppendRecessivePluginGroupIds()
34 {
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 {
55 Random entropy = new Random();
56 Profile p = new Profile();
57 p.setId( "id" + Long.toHexString( entropy.nextLong() ) );
58 Activation a = new Activation();
59 a.setActiveByDefault( entropy.nextBoolean() );
60 a.setJdk( "jdk" + Long.toHexString( entropy.nextLong() ) );
61 ActivationFile af = new ActivationFile();
62 af.setExists( "exists" + Long.toHexString( entropy.nextLong() ) );
63 af.setMissing( "missing" + Long.toHexString( entropy.nextLong() ) );
64 a.setFile( af );
65 ActivationProperty ap = new ActivationProperty();
66 ap.setName( "name" + Long.toHexString( entropy.nextLong() ) );
67 ap.setValue( "value" + Long.toHexString( entropy.nextLong() ) );
68 a.setProperty( ap );
69 ActivationOS ao = new ActivationOS();
70 ao.setArch( "arch" + Long.toHexString( entropy.nextLong() ) );
71 ao.setFamily( "family" + Long.toHexString( entropy.nextLong() ) );
72 ao.setName( "name" + Long.toHexString( entropy.nextLong() ) );
73 ao.setVersion( "version" + Long.toHexString( entropy.nextLong() ) );
74 a.setOs( ao );
75 p.setActivation( a );
76 Properties props = new Properties();
77 int count = entropy.nextInt( 10 );
78 for ( int i = 0; i < count; i++ )
79 {
80 props.setProperty( "name" + Long.toHexString( entropy.nextLong() ),
81 "value" + Long.toHexString( entropy.nextLong() ) );
82 }
83 p.setProperties( props );
84 count = entropy.nextInt( 3 );
85 List<Repository> repos = new ArrayList<Repository>();
86 for ( int i = 0; i < count; i++ )
87 {
88 Repository r = new Repository();
89 r.setId( "id" + Long.toHexString( entropy.nextLong() ) );
90 r.setName( "name" + Long.toHexString( entropy.nextLong() ) );
91 r.setUrl( "url" + Long.toHexString( entropy.nextLong() ) );
92 repos.add( r );
93 }
94 p.setRepositories( repos );
95 count = entropy.nextInt( 3 );
96 repos = new ArrayList<Repository>();
97 for ( int i = 0; i < count; i++ )
98 {
99 Repository r = new Repository();
100 r.setId( "id" + Long.toHexString( entropy.nextLong() ) );
101 r.setName( "name" + Long.toHexString( entropy.nextLong() ) );
102 r.setUrl( "url" + Long.toHexString( entropy.nextLong() ) );
103 repos.add( r );
104 }
105 p.setPluginRepositories( repos );
106
107 Profile clone = SettingsUtils.convertToSettingsProfile( SettingsUtils.convertFromSettingsProfile( p ) );
108
109 assertEquals( p.getId(), clone.getId() );
110 assertEquals( p.getActivation().getJdk(), clone.getActivation().getJdk() );
111 assertEquals( p.getActivation().getFile().getExists(), clone.getActivation().getFile().getExists() );
112 assertEquals( p.getActivation().getFile().getMissing(), clone.getActivation().getFile().getMissing() );
113 assertEquals( p.getActivation().getProperty().getName(), clone.getActivation().getProperty().getName() );
114 assertEquals( p.getActivation().getProperty().getValue(), clone.getActivation().getProperty().getValue() );
115 assertEquals( p.getActivation().getOs().getArch(), clone.getActivation().getOs().getArch() );
116 assertEquals( p.getActivation().getOs().getFamily(), clone.getActivation().getOs().getFamily() );
117 assertEquals( p.getActivation().getOs().getName(), clone.getActivation().getOs().getName() );
118 assertEquals( p.getActivation().getOs().getVersion(), clone.getActivation().getOs().getVersion() );
119 assertEquals( p.getProperties(), clone.getProperties() );
120 assertEquals( p.getRepositories().size(), clone.getRepositories().size() );
121
122 assertEquals( p.getPluginRepositories().size(), clone.getPluginRepositories().size() );
123
124 }
125
126 }