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.shared.osgi;
20  
21  import java.io.File;
22  
23  import org.apache.maven.plugin.testing.stubs.ArtifactStub;
24  import org.codehaus.plexus.PlexusTestCase;
25  
26  /**
27   * Test for {@link DefaultMaven2OsgiConverter}
28   * 
29   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
30   * @version $Id: Maven2OsgiConverterTest.java 590533 2007-10-31 01:43:00Z carlos $
31   */
32  public class Maven2OsgiConverterTest
33      extends PlexusTestCase
34  {
35  
36      private Maven2OsgiConverter maven2Osgi = new DefaultMaven2OsgiConverter();
37  
38      public void testGetBundleSymbolicName()
39      {
40          ArtifactStub artifact = getTestArtifact();
41          String s;
42          s = maven2Osgi.getBundleSymbolicName( artifact );
43          assertEquals( "org.apache.commons.logging", s );
44  
45          artifact.setGroupId( "org.apache.commons" );
46          s = maven2Osgi.getBundleSymbolicName( artifact );
47          assertEquals( "org.apache.commons.logging", s );
48  
49          artifact.setGroupId( "org.apache.commons.commons-logging" );
50          s = maven2Osgi.getBundleSymbolicName( artifact );
51          assertEquals( "org.apache.commons.commons-logging", s );
52  
53          artifact.setFile( getTestFile( "junit-3.8.2.jar" ) );
54          artifact.setGroupId( "junit" );
55          artifact.setArtifactId( "junit" );
56          s = maven2Osgi.getBundleSymbolicName( artifact );
57          assertEquals( "junit", s );
58  
59          artifact.setFile( getTestFile( "xml-apis-1.0.b2.jar" ) );
60          artifact.setGroupId( "xml-apis" );
61          artifact.setArtifactId( "a" );
62          s = maven2Osgi.getBundleSymbolicName( artifact );
63          assertEquals( "xml-apis.a", s );
64  
65          artifact.setFile( getTestFile( "test-1.jar" ) );
66          artifact.setGroupId( "test" );
67          artifact.setArtifactId( "test" );
68          s = maven2Osgi.getBundleSymbolicName( artifact );
69          assertEquals( "test", s );
70  
71          artifact.setFile( getTestFile( "xercesImpl-2.6.2.jar" ) );
72          artifact.setGroupId( "xerces" );
73          artifact.setArtifactId( "xercesImpl" );
74          s = maven2Osgi.getBundleSymbolicName( artifact );
75          assertEquals( "xerces.Impl", s );
76  
77          artifact.setFile( getTestFile( "aopalliance-1.0.jar" ) );
78          artifact.setGroupId( "org.aopalliance" );
79          artifact.setArtifactId( "aopalliance" );
80          s = maven2Osgi.getBundleSymbolicName( artifact );
81          assertEquals( "org.aopalliance", s );
82      }
83  
84      public void testGetBundleFileName()
85      {
86          ArtifactStub artifact = getTestArtifact();
87          String s;
88          s = maven2Osgi.getBundleFileName( artifact );
89          assertEquals( "org.apache.commons.logging_1.1.0.jar", s );
90  
91          artifact.setGroupId( "org.aopalliance" );
92          artifact.setArtifactId( "aopalliance" );
93          s = maven2Osgi.getBundleFileName( artifact );
94          assertEquals( "org.aopalliance_1.1.0.jar", s );
95      }
96  
97      public void testGetVersion()
98      {
99          ArtifactStub artifact = getTestArtifact();
100         String s = maven2Osgi.getVersion( artifact );
101         assertEquals( "1.1.0", s );
102     }
103 
104     public void testConvertVersionToOsgi()
105     {
106         String osgiVersion;
107 
108         osgiVersion = maven2Osgi.getVersion( "2.1.0-SNAPSHOT" );
109         assertEquals( "2.1.0.SNAPSHOT", osgiVersion );
110 
111         osgiVersion = maven2Osgi.getVersion( "2.1-SNAPSHOT" );
112         assertEquals( "2.1.0.SNAPSHOT", osgiVersion );
113 
114         osgiVersion = maven2Osgi.getVersion( "2-SNAPSHOT" );
115         assertEquals( "2.0.0.SNAPSHOT", osgiVersion );
116 
117         osgiVersion = maven2Osgi.getVersion( "2" );
118         assertEquals( "2.0.0", osgiVersion );
119 
120         osgiVersion = maven2Osgi.getVersion( "2.1" );
121         assertEquals( "2.1.0", osgiVersion );
122 
123         osgiVersion = maven2Osgi.getVersion( "2.1.3" );
124         assertEquals( "2.1.3", osgiVersion );
125 
126         osgiVersion = maven2Osgi.getVersion( "2.1.3.4" );
127         assertEquals( "2.1.3.4", osgiVersion );
128 
129         osgiVersion = maven2Osgi.getVersion( "4aug2000r7-dev" );
130         assertEquals( "0.0.0.4aug2000r7_dev", osgiVersion );
131 
132         osgiVersion = maven2Osgi.getVersion( "1.1-alpha-2" );
133         assertEquals( "1.1.0.alpha_2", osgiVersion );
134 
135         osgiVersion = maven2Osgi.getVersion( "1.0-alpha-16-20070122.203121-13" );
136         assertEquals( "1.0.0.alpha_16_20070122_203121_13", osgiVersion );
137 
138         osgiVersion = maven2Osgi.getVersion( "1.0-20070119.021432-1" );
139         assertEquals( "1.0.0.20070119_021432_1", osgiVersion );
140 
141         osgiVersion = maven2Osgi.getVersion( "1-20070119.021432-1" );
142         assertEquals( "1.0.0.20070119_021432_1", osgiVersion );
143 
144         osgiVersion = maven2Osgi.getVersion( "1.4.1-20070217.082013-7" );
145         assertEquals( "1.4.1.20070217_082013_7", osgiVersion );
146         
147         osgiVersion = maven2Osgi.getVersion( "0.0.0.4aug2000r7-dev" );
148         assertEquals( "0.0.0.4aug2000r7-dev", osgiVersion );
149         
150         osgiVersion = maven2Osgi.getVersion( "4aug2000r7-dev" );
151         assertEquals( "0.0.0.4aug2000r7_dev", osgiVersion );
152     }
153 
154     private ArtifactStub getTestArtifact()
155     {
156         ArtifactStub a = new ArtifactStub();
157         a.setGroupId( "commons-logging" );
158         a.setArtifactId( "commons-logging" );
159         a.setVersion( "1.1" );
160         a.setFile( getTestFile( "commons-logging-1.1.jar" ) );
161         return a;
162     }
163 
164     public static File getTestFile( String fileName )
165     {
166         return PlexusTestCase.getTestFile( "src/test/resources/" + fileName );
167     }
168 }