1 package org.apache.continuum.installation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.continuum.dao.DaoUtils;
23 import org.apache.maven.continuum.AbstractContinuumTest;
24 import org.apache.maven.continuum.execution.ExecutorConfigurator;
25 import org.apache.maven.continuum.installation.AlreadyExistsInstallationException;
26 import org.apache.maven.continuum.installation.InstallationService;
27 import org.apache.maven.continuum.model.system.Installation;
28 import org.apache.maven.continuum.model.system.Profile;
29 import org.apache.maven.continuum.profile.ProfileService;
30 import org.codehaus.plexus.util.StringUtils;
31
32 import java.util.List;
33
34
35
36
37
38
39 public class DefaultInstallationServiceTest
40 extends AbstractContinuumTest
41 {
42 private static final String NEW_INSTALLATION_NAME = "newInstallation";
43
44 protected void setUp()
45 throws Exception
46 {
47 super.setUp();
48 DaoUtils daoUtils = (DaoUtils) lookup( DaoUtils.class.getName() );
49 daoUtils.eraseDatabase();
50 }
51
52 private InstallationService getInstallationService()
53 throws Exception
54 {
55
56
57 return (InstallationService) lookup( InstallationService.ROLE );
58 }
59
60 private Installation addInstallation( String name, String varName, String varValue, String type )
61 throws Exception
62 {
63
64 Installation installation = new Installation();
65 installation.setType( type );
66 installation.setName( name );
67 installation.setVarName( varName );
68 installation.setVarValue( varValue );
69 return getInstallationService().add( installation );
70 }
71
72 public void testAddInstallation()
73 throws Exception
74 {
75 Installation added = this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE );
76 Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
77 assertNotNull( getted );
78 assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
79 assertEquals( "bar", getted.getVarValue() );
80 assertEquals( 1, getInstallationService().getAllInstallations().size() );
81 }
82
83 public void testAddDuplicateInstallation()
84 throws Exception
85 {
86 Installation added = this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE );
87 Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
88 assertNotNull( getted );
89 assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
90 assertEquals( "bar", getted.getVarValue() );
91 try
92 {
93 this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE );
94 fail( "not in AlreadyExistsInstallationException" );
95 }
96 catch ( AlreadyExistsInstallationException e )
97 {
98
99 }
100 assertEquals( 1, getInstallationService().getAllInstallations().size() );
101 }
102
103 public void testRemove()
104 throws Exception
105 {
106 String name = "toremove";
107 Installation added = this.addInstallation( name, "foo", "bar", InstallationService.JDK_TYPE );
108 Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
109 assertNotNull( getted );
110 getInstallationService().delete( getted );
111 getted = getInstallationService().getInstallation( added.getInstallationId() );
112 assertNull( getted );
113
114 }
115
116 public void testUpdate()
117 throws Exception
118 {
119 String name = "toupdate";
120 Installation added = this.addInstallation( name, "foo", "bar", InstallationService.JDK_TYPE );
121 Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
122 assertNotNull( getted );
123 assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
124 assertEquals( "bar", getted.getVarValue() );
125 getted.setVarName( "updatefoo" );
126 getted.setVarValue( "updatedbar" );
127 getInstallationService().update( getted );
128 getted = getInstallationService().getInstallation( added.getInstallationId() );
129 assertNotNull( getted );
130 assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
131 assertEquals( "updatedbar", getted.getVarValue() );
132 }
133
134 public void testgetDefaultJdkInformations()
135 throws Exception
136 {
137 InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
138 List<String> infos = installationService.getDefaultJdkInformations();
139 assertNotNull( infos );
140 }
141
142 public void testgetJdkInformations()
143 throws Exception
144 {
145 InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
146 String javaHome = System.getenv( "JAVA_HOME" );
147 if ( StringUtils.isEmpty( javaHome ) )
148 {
149 javaHome = System.getProperty( "java.home" );
150 }
151 Installation installation = new Installation();
152 installation.setName( "test" );
153 installation.setType( InstallationService.JDK_TYPE );
154 installation.setVarValue( javaHome );
155
156 List<String> infos = installationService.getJdkInformations( installation );
157 assertNotNull( infos );
158 }
159
160 public void testgetJdkInformationsWithCommonMethod()
161 throws Exception
162 {
163 InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
164 ExecutorConfigurator java = installationService.getExecutorConfigurator( InstallationService.JDK_TYPE );
165 String javaHome = System.getenv( "JAVA_HOME" );
166 if ( StringUtils.isEmpty( javaHome ) )
167 {
168 javaHome = System.getProperty( "java.home" );
169 }
170 List<String> infos = installationService.getExecutorConfiguratorVersion( javaHome, java, null );
171 System.out.println( infos );
172 assertNotNull( infos );
173 }
174
175 public void testgetMvnVersionWithCommonMethod()
176 throws Exception
177 {
178 InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
179 ExecutorConfigurator java = installationService.getExecutorConfigurator( InstallationService.MAVEN2_TYPE );
180 List<String> infos = installationService.getExecutorConfiguratorVersion( null, java, null );
181 assertNotNull( infos );
182 }
183
184 public void testAddInstallationAutomaticProfile()
185 throws Exception
186 {
187
188 Installation installation = new Installation();
189 installation.setType( InstallationService.JDK_TYPE );
190 installation.setName( "automaticJdk" );
191 installation.setVarName( "automaticvarName" );
192 installation.setVarValue( "automaticvarValue" );
193 getInstallationService().add( installation, true );
194 ProfileService profileService = (ProfileService) lookup( ProfileService.ROLE, "default" );
195 List<Profile> profiles = profileService.getAllProfiles();
196 assertEquals( 1, profiles.size() );
197 Profile profile = profiles.get( 0 );
198 assertEquals( "automaticJdk", profile.getName() );
199 Installation jdk = profile.getJdk();
200 assertNotNull( jdk );
201 assertEquals( "automaticJdk", jdk.getName() );
202 }
203
204 public void testUpdateName()
205 throws Exception
206 {
207 Installation installation = new Installation();
208 installation.setType( InstallationService.JDK_TYPE );
209 installation.setName( "automatic" );
210 installation.setVarName( "automaticvarName" );
211 installation.setVarValue( "automaticvarValue" );
212 installation = getInstallationService().add( installation, true );
213
214 installation.setName( "new name here" );
215 getInstallationService().update( installation );
216
217 Installation getted = getInstallationService().getInstallation( installation.getInstallationId() );
218 assertEquals( "new name here", getted.getName() );
219
220
221 }
222 }