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.continuum;
20  
21  import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
22  import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
23  import org.apache.maven.continuum.model.project.Project;
24  import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
25  import org.apache.maven.continuum.project.builder.maven.MavenTwoContinuumProjectBuilder;
26  
27  /**
28   * @author <a href="mailto:olamy@apache.org">olamy</a>
29   * @since 12 juin 2008
30   * @version $Id: AddProjectTest.java 915747 2010-02-24 10:51:01Z oching $
31   */
32  public class AddProjectTest
33      extends AbstractContinuumTest
34  {
35      static final String SCM_USERNAME = "test";
36      
37      static final String SCM_PASSWORD = ";password";
38      
39      public void testScmUserNamePasswordNotStoring()
40          throws Exception
41      {
42          String metadataUrl = "http://test:;password@svn.apache.org/repos/asf/continuum/tags/continuum-1.1/continuum-api/pom.xml";
43          DefaultContinuum continuum = (DefaultContinuum) lookup( Continuum.ROLE );
44          
45          ContinuumProjectBuildingResult result = continuum
46              .executeAddProjectsFromMetadataActivity( metadataUrl, MavenTwoContinuumProjectBuilder.ID,
47                                                       getDefaultProjectGroup().getId(), false, true, false, -1, false );
48          assertEquals( 1, result.getProjects().size() );
49          
50          // read the project from store
51          Project project = continuum.getProject( result.getProjects().get( 0 ).getId());
52          assertNull(  project.getScmUsername() );
53          assertNull( project.getScmPassword() );
54          assertTrue( project.isScmUseCache() );
55      }
56  
57      public void testScmUserNamePasswordStoring()
58          throws Exception
59      {
60          String metadataUrl = "http://test:;password@svn.apache.org/repos/asf/continuum/tags/continuum-1.1/continuum-api/pom.xml";
61          DefaultContinuum continuum = (DefaultContinuum) lookup( Continuum.ROLE );
62  
63          ContinuumProjectBuildingResult result = continuum
64              .executeAddProjectsFromMetadataActivity( metadataUrl, MavenTwoContinuumProjectBuilder.ID,
65                                                       getDefaultProjectGroup().getId(), false, false, false, -1, false );
66          assertEquals( 1, result.getProjects().size() );
67  
68          // read the project from store
69          Project project = continuum.getProject( result.getProjects().get( 0 ).getId() );
70          assertEquals( SCM_USERNAME, project.getScmUsername() );
71          assertEquals( SCM_PASSWORD, project.getScmPassword() );
72          assertFalse( project.isScmUseCache() );
73      }    
74      
75      public void testAntProjectScmUserNamePasswordNotStoring()
76          throws Exception
77      {
78          // use same url since we're just going to add the project, not build it
79          String scmUrl = "http://test:;password@svn.apache.org/repos/asf/continuum/tags/continuum-1.1/continuum-api/pom.xml";
80          DefaultContinuum continuum = (DefaultContinuum) lookup( Continuum.ROLE );
81          
82          Project project = new Project();
83          project.setName( "Sample Ant Project" );
84          project.setVersion( "1.0" );
85          project.setScmUsername( SCM_USERNAME );
86          project.setScmPassword( SCM_PASSWORD );
87          project.setScmUrl( scmUrl );        
88          project.setScmUseCache( true );
89          
90          BuildDefinitionService bdService = ( BuildDefinitionService )lookup( BuildDefinitionService.class.getName() );
91          
92          int projectId =
93              continuum.addProject( project, ContinuumBuildExecutorConstants.ANT_BUILD_EXECUTOR,
94                                    getDefaultProjectGroup().getId(),
95                                    bdService.getDefaultAntBuildDefinitionTemplate().getId() );
96                  
97          // read the project from store
98          Project retrievedProject = continuum.getProject( projectId );
99          assertNull(  retrievedProject.getScmUsername() );
100         assertNull( retrievedProject.getScmPassword() );
101         assertTrue( retrievedProject.isScmUseCache() );
102     }
103     
104     public void testAntProjectScmUserNamePasswordStoring()
105         throws Exception
106     {
107         // use same url since we're just going to add the project, not build it
108         String scmUrl = "http://test:;password@svn.apache.org/repos/asf/continuum/tags/continuum-1.1/continuum-api/pom.xml";
109         DefaultContinuum continuum = (DefaultContinuum) lookup( Continuum.ROLE );
110         
111         Project project = new Project();
112         project.setName( "Sample Ant Project" );
113         project.setVersion( "1.0" );
114         project.setScmUsername( SCM_USERNAME );
115         project.setScmPassword( SCM_PASSWORD );
116         project.setScmUrl( scmUrl );        
117         project.setScmUseCache( false );
118         
119         BuildDefinitionService bdService = ( BuildDefinitionService )lookup( BuildDefinitionService.class.getName() );
120         
121         int projectId =
122             continuum.addProject( project, ContinuumBuildExecutorConstants.ANT_BUILD_EXECUTOR,
123                                   getDefaultProjectGroup().getId(),
124                                   bdService.getDefaultAntBuildDefinitionTemplate().getId() );
125                
126         // read the project from store
127         Project retrievedProject = continuum.getProject( projectId );
128         assertEquals( SCM_USERNAME, retrievedProject.getScmUsername() );
129         assertEquals( SCM_PASSWORD, retrievedProject.getScmPassword() );
130         assertFalse( retrievedProject.isScmUseCache() );
131     }
132     
133 }