View Javadoc

1   /*
2    * Copyright 2012 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package test.de.smartics.ci.config.maven;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  
21  import org.junit.Before;
22  import org.junit.Test;
23  
24  import de.smartics.ci.config.hudson.ScmType;
25  import de.smartics.ci.config.maven.MavenPom;
26  import de.smartics.testdoc.annotations.Uut;
27  import de.smartics.util.lang.BlankArgumentException;
28  
29  /**
30   * Tests {@link MavenPom#setScmConnectionString(String)}.
31   */
32  public class MavenPomScmTest
33  { // NOPMD
34    // ********************************* Fields *********************************
35  
36    // --- constants ------------------------------------------------------------
37  
38    // --- members --------------------------------------------------------------
39  
40    @Uut(method = "setScmConnectionString(String)")
41    private MavenPom uut;
42  
43    // ****************************** Inner Classes *****************************
44  
45    // ********************************* Methods ********************************
46  
47    // --- prepare --------------------------------------------------------------
48  
49    @Before
50    public void setUp()
51    {
52      uut = new MavenPom();
53    }
54  
55    // --- helper ---------------------------------------------------------------
56  
57    // --- tests ----------------------------------------------------------------
58  
59    @Test(expected = BlankArgumentException.class)
60    public void rejectsNullAsConnectionString()
61    {
62      uut.setScmConnectionString(null);
63    }
64  
65    @Test(expected = BlankArgumentException.class)
66    public void rejectsBlankAsConnectionString()
67    {
68      uut.setScmConnectionString("\n \t");
69    }
70  
71    @Test(expected = IllegalArgumentException.class)
72    public void rejectsConnectionStringNotConformingToFormat()
73    {
74      uut.setScmConnectionString("abc:def:http://some/url");
75    }
76  
77    @Test(expected = IllegalArgumentException.class)
78    public void rejectsConnectionStringNotStartingWithScmPrefix()
79    {
80      uut.setScmConnectionString("abc:svn:http://some/url");
81    }
82  
83    @Test(expected = IllegalArgumentException.class)
84    public void rejectsConnectionStringNotProvidingScmType()
85    {
86      uut.setScmConnectionString("abc:/some/url");
87    }
88  
89    @Test(expected = IllegalArgumentException.class)
90    public void rejectsConnectionStringNotProvidingScmTypeButHttpProtocol()
91    {
92      uut.setScmConnectionString("scm:http://some/url");
93    }
94  
95    @Test(expected = IllegalArgumentException.class)
96    public void rejectsConnectionStringNotProvidingScmTypeButHttpsProtocol()
97    {
98      uut.setScmConnectionString("scm:https://some/url");
99    }
100 
101   @Test(expected = IllegalArgumentException.class)
102   public void rejectsConnectionStringContainingOnlyScmPrefix()
103   {
104     uut.setScmConnectionString("scm:");
105   }
106 
107   @Test(expected = IllegalArgumentException.class)
108   public void rejectsConnectionStringContainingNoUrl()
109   {
110     uut.setScmConnectionString("scm:svn:");
111   }
112 
113   @Test(expected = IllegalArgumentException.class)
114   public void rejectsConnectionStringMissingScmTypeDelimiter()
115   {
116     uut.setScmConnectionString("scm:svn");
117   }
118 
119   @Test
120   public void readsScmInfoFromScmConnectionString()
121   {
122     final String url = "http://some/url";
123     uut.setScmConnectionString("scm:svn:" + url);
124     final ScmType scmType = uut.getScmType();
125     assertThat(scmType, is(ScmType.SVN));
126     final String scmUrl = uut.getScmUrl();
127     assertThat(scmUrl, is(url));
128   }
129 
130   @Test(expected = IllegalArgumentException.class)
131   public void rejectsUnknownScmType()
132   {
133     uut.setScmConnectionString("scm:unknown:http://some/url");
134   }
135 }