View Javadoc

1   package org.apache.maven.continuum;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.continuum.AbstractAddProjectTest;
23  import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
24  import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
25  import org.apache.maven.continuum.model.project.Project;
26  import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
27  import org.apache.maven.continuum.project.builder.maven.MavenTwoContinuumProjectBuilder;
28  import org.eclipse.jetty.server.Handler;
29  import org.eclipse.jetty.server.Server;
30  import org.eclipse.jetty.server.handler.DefaultHandler;
31  import org.eclipse.jetty.server.handler.HandlerList;
32  import org.eclipse.jetty.server.handler.ResourceHandler;
33  
34  import java.util.Collections;
35  
36  /**
37   * @author <a href="mailto:olamy@apache.org">olamy</a>
38   * @version $Id: AddProjectTest.java 1399173 2012-10-17 10:05:38Z brett $
39   * @since 12 juin 2008
40   */
41  public class AddProjectTest
42      extends AbstractAddProjectTest
43  {
44      static final String SCM_USERNAME = "test";
45  
46      static final String SCM_PASSWORD = ";password";
47  
48      private Server server;
49  
50      private String scmUrl;
51  
52      @Override
53      protected void setUp()
54          throws Exception
55      {
56          super.setUp();
57  
58          createLocalRepository();
59  
60          server = startJettyServer();
61          int port = server.getConnectors()[0].getLocalPort();
62          scmUrl = "http://test:;password@localhost:" + port + "/projects/continuum/continuum-core/pom.xml";
63      }
64  
65      @Override
66      protected void tearDown()
67          throws Exception
68      {
69          super.tearDown();
70          server.stop();
71      }
72  
73      private Server startJettyServer()
74          throws Exception
75      {
76          Server server = new Server( 0 );
77          ResourceHandler handler = new ResourceHandler();
78          handler.setResourceBase( getTestFile( "src/test/resources" ).getAbsolutePath() );
79          HandlerList handlers = new HandlerList();
80          handlers.setHandlers( new Handler[]{ handler, new DefaultHandler() } );
81          server.setHandler( handlers );
82          server.start();
83          return server;
84      }
85  
86      public void testScmUserNamePasswordNotStoring()
87          throws Exception
88      {
89          DefaultContinuum continuum = (DefaultContinuum) lookup( Continuum.ROLE );
90  
91          ContinuumProjectBuildingResult result = continuum.executeAddProjectsFromMetadataActivity( scmUrl,
92                                                                                                    MavenTwoContinuumProjectBuilder.ID,
93                                                                                                    getDefaultProjectGroup().getId(),
94                                                                                                    false, true, false,
95                                                                                                    -1, false, false );
96          assertEquals( Collections.emptyList(), result.getErrors() );
97  
98          assertEquals( 1, result.getProjects().size() );
99  
100         // read the project from store
101         Project project = continuum.getProject( result.getProjects().get( 0 ).getId() );
102         assertNull( project.getScmUsername() );
103         assertNull( project.getScmPassword() );
104         assertTrue( project.isScmUseCache() );
105     }
106 
107     public void testScmUserNamePasswordStoring()
108         throws Exception
109     {
110         DefaultContinuum continuum = (DefaultContinuum) lookup( Continuum.ROLE );
111 
112         ContinuumProjectBuildingResult result = continuum.executeAddProjectsFromMetadataActivity( scmUrl,
113                                                                                                   MavenTwoContinuumProjectBuilder.ID,
114                                                                                                   getDefaultProjectGroup().getId(),
115                                                                                                   false, false, false,
116                                                                                                   -1, false, false );
117         assertEquals( Collections.emptyList(), result.getErrors() );
118 
119         assertEquals( 1, result.getProjects().size() );
120 
121         // read the project from store
122         Project project = continuum.getProject( result.getProjects().get( 0 ).getId() );
123         assertEquals( SCM_USERNAME, project.getScmUsername() );
124         assertEquals( SCM_PASSWORD, project.getScmPassword() );
125         assertFalse( project.isScmUseCache() );
126     }
127 
128     public void testAntProjectScmUserNamePasswordNotStoring()
129         throws Exception
130     {
131         DefaultContinuum continuum = (DefaultContinuum) lookup( Continuum.ROLE );
132 
133         Project project = new Project();
134         project.setName( "Sample Ant Project" );
135         project.setVersion( "1.0" );
136         project.setScmUsername( SCM_USERNAME );
137         project.setScmPassword( SCM_PASSWORD );
138         project.setScmUrl( this.scmUrl );
139         project.setScmUseCache( true );
140 
141         BuildDefinitionService bdService = (BuildDefinitionService) lookup( BuildDefinitionService.class.getName() );
142 
143         int projectId = continuum.addProject( project, ContinuumBuildExecutorConstants.ANT_BUILD_EXECUTOR,
144                                               getDefaultProjectGroup().getId(),
145                                               bdService.getDefaultAntBuildDefinitionTemplate().getId() );
146 
147         // read the project from store
148         Project retrievedProject = continuum.getProject( projectId );
149         assertNull( retrievedProject.getScmUsername() );
150         assertNull( retrievedProject.getScmPassword() );
151         assertTrue( retrievedProject.isScmUseCache() );
152     }
153 
154     public void testAntProjectScmUserNamePasswordStoring()
155         throws Exception
156     {
157         DefaultContinuum continuum = (DefaultContinuum) lookup( Continuum.ROLE );
158 
159         Project project = new Project();
160         project.setName( "Sample Ant Project" );
161         project.setVersion( "1.0" );
162         project.setScmUsername( SCM_USERNAME );
163         project.setScmPassword( SCM_PASSWORD );
164         project.setScmUrl( scmUrl );
165         project.setScmUseCache( false );
166 
167         BuildDefinitionService bdService = (BuildDefinitionService) lookup( BuildDefinitionService.class.getName() );
168 
169         int projectId = continuum.addProject( project, ContinuumBuildExecutorConstants.ANT_BUILD_EXECUTOR,
170                                               getDefaultProjectGroup().getId(),
171                                               bdService.getDefaultAntBuildDefinitionTemplate().getId() );
172 
173         // read the project from store
174         Project retrievedProject = continuum.getProject( projectId );
175         assertEquals( SCM_USERNAME, retrievedProject.getScmUsername() );
176         assertEquals( SCM_PASSWORD, retrievedProject.getScmPassword() );
177         assertFalse( retrievedProject.isScmUseCache() );
178     }
179 
180 }