blob: 3e179dd3b07700e1607c5fae922c43d58f87b4ef [file] [log] [blame]
Stuart McCullochdfc5abb2012-05-25 14:13:15 +00001package org.apache.maven.shared.osgi;
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
22import java.io.File;
23
24import org.apache.maven.plugin.testing.stubs.ArtifactStub;
25import org.codehaus.plexus.PlexusTestCase;
26
27/**
28 * Test for {@link DefaultMaven2OsgiConverter}
Carsten Ziegeler846bd7a2015-05-15 08:53:36 +000029 *
Stuart McCullochdfc5abb2012-05-25 14:13:15 +000030 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
31 * @version $Id$
32 */
33public class Maven2OsgiConverterTest
34 extends PlexusTestCase
35{
36
37 private Maven2OsgiConverter maven2Osgi = new DefaultMaven2OsgiConverter();
38
39 public void testGetBundleSymbolicName()
40 {
41 ArtifactStub artifact = getTestArtifact();
42 String s;
43 s = maven2Osgi.getBundleSymbolicName( artifact );
44 assertEquals( "org.apache.commons.logging", s );
45
46 artifact.setGroupId( "org.apache.commons" );
47 s = maven2Osgi.getBundleSymbolicName( artifact );
48 assertEquals( "org.apache.commons.logging", s );
49
50 artifact.setGroupId( "org.apache.commons.commons-logging" );
51 s = maven2Osgi.getBundleSymbolicName( artifact );
52 assertEquals( "org.apache.commons.commons-logging", s );
53
Stuart McCulloch00e35142012-05-25 14:18:01 +000054 artifact.setGroupId( "org.apache" );
55 artifact.setArtifactId( "org.apache.commons-logging" );
56 s = maven2Osgi.getBundleSymbolicName( artifact );
57 assertEquals( "org.apache.commons-logging", s );
58
Stuart McCullochdfc5abb2012-05-25 14:13:15 +000059 artifact.setFile( getTestFile( "junit-3.8.2.jar" ) );
60 artifact.setGroupId( "junit" );
61 artifact.setArtifactId( "junit" );
62 s = maven2Osgi.getBundleSymbolicName( artifact );
63 assertEquals( "junit", s );
64
65 artifact.setFile( getTestFile( "xml-apis-1.0.b2.jar" ) );
66 artifact.setGroupId( "xml-apis" );
67 artifact.setArtifactId( "a" );
68 s = maven2Osgi.getBundleSymbolicName( artifact );
69 assertEquals( "xml-apis.a", s );
70
71 artifact.setFile( getTestFile( "test-1.jar" ) );
72 artifact.setGroupId( "test" );
73 artifact.setArtifactId( "test" );
74 s = maven2Osgi.getBundleSymbolicName( artifact );
75 assertEquals( "test", s );
76
77 artifact.setFile( getTestFile( "xercesImpl-2.6.2.jar" ) );
78 artifact.setGroupId( "xerces" );
79 artifact.setArtifactId( "xercesImpl" );
80 s = maven2Osgi.getBundleSymbolicName( artifact );
81 assertEquals( "xerces.Impl", s );
82
83 artifact.setFile( getTestFile( "aopalliance-1.0.jar" ) );
84 artifact.setGroupId( "org.aopalliance" );
85 artifact.setArtifactId( "aopalliance" );
86 s = maven2Osgi.getBundleSymbolicName( artifact );
87 assertEquals( "org.aopalliance", s );
88 }
89
90 public void testGetBundleFileName()
91 {
92 ArtifactStub artifact = getTestArtifact();
93 String s;
94 s = maven2Osgi.getBundleFileName( artifact );
95 assertEquals( "org.apache.commons.logging_1.1.0.jar", s );
96
97 artifact.setGroupId( "org.aopalliance" );
98 artifact.setArtifactId( "aopalliance" );
99 s = maven2Osgi.getBundleFileName( artifact );
100 assertEquals( "org.aopalliance_1.1.0.jar", s );
101 }
102
103 public void testGetVersion()
104 {
105 ArtifactStub artifact = getTestArtifact();
106 String s = maven2Osgi.getVersion( artifact );
107 assertEquals( "1.1.0", s );
108 }
109
110 public void testConvertVersionToOsgi()
111 {
112 String osgiVersion;
113
114 osgiVersion = maven2Osgi.getVersion( "2.1.0-SNAPSHOT" );
115 assertEquals( "2.1.0.SNAPSHOT", osgiVersion );
116
117 osgiVersion = maven2Osgi.getVersion( "2.1-SNAPSHOT" );
118 assertEquals( "2.1.0.SNAPSHOT", osgiVersion );
119
Carsten Ziegeler846bd7a2015-05-15 08:53:36 +0000120 osgiVersion = maven2Osgi.getVersion( "0.1-SNAPSHOT" );
121 assertEquals( "0.1.0.SNAPSHOT", osgiVersion );
122
Stuart McCullochdfc5abb2012-05-25 14:13:15 +0000123 osgiVersion = maven2Osgi.getVersion( "2-SNAPSHOT" );
124 assertEquals( "2.0.0.SNAPSHOT", osgiVersion );
125
126 osgiVersion = maven2Osgi.getVersion( "2" );
127 assertEquals( "2.0.0", osgiVersion );
128
129 osgiVersion = maven2Osgi.getVersion( "2.1" );
130 assertEquals( "2.1.0", osgiVersion );
131
132 osgiVersion = maven2Osgi.getVersion( "2.1.3" );
133 assertEquals( "2.1.3", osgiVersion );
134
135 osgiVersion = maven2Osgi.getVersion( "2.1.3.4" );
136 assertEquals( "2.1.3.4", osgiVersion );
137
138 osgiVersion = maven2Osgi.getVersion( "4aug2000r7-dev" );
139 assertEquals( "0.0.0.4aug2000r7-dev", osgiVersion );
140
141 osgiVersion = maven2Osgi.getVersion( "1.1-alpha-2" );
142 assertEquals( "1.1.0.alpha-2", osgiVersion );
143
144 osgiVersion = maven2Osgi.getVersion( "1.0-alpha-16-20070122.203121-13" );
145 assertEquals( "1.0.0.alpha-16-20070122_203121-13", osgiVersion );
146
147 osgiVersion = maven2Osgi.getVersion( "1.0-20070119.021432-1" );
148 assertEquals( "1.0.0.20070119_021432-1", osgiVersion );
149
150 osgiVersion = maven2Osgi.getVersion( "1-20070119.021432-1" );
151 assertEquals( "1.0.0.20070119_021432-1", osgiVersion );
152
153 osgiVersion = maven2Osgi.getVersion( "1.4.1-20070217.082013-7" );
154 assertEquals( "1.4.1.20070217_082013-7", osgiVersion );
Carsten Ziegeler846bd7a2015-05-15 08:53:36 +0000155
Stuart McCullochdfc5abb2012-05-25 14:13:15 +0000156 osgiVersion = maven2Osgi.getVersion( "0.0.0.4aug2000r7-dev" );
157 assertEquals( "0.0.0.4aug2000r7-dev", osgiVersion );
Carsten Ziegeler846bd7a2015-05-15 08:53:36 +0000158
Stuart McCullochdfc5abb2012-05-25 14:13:15 +0000159 osgiVersion = maven2Osgi.getVersion( "4aug2000r7-dev" );
160 assertEquals( "0.0.0.4aug2000r7-dev", osgiVersion );
161 }
162
163 private ArtifactStub getTestArtifact()
164 {
165 ArtifactStub a = new ArtifactStub();
166 a.setGroupId( "commons-logging" );
167 a.setArtifactId( "commons-logging" );
168 a.setVersion( "1.1" );
169 a.setFile( getTestFile( "commons-logging-1.1.jar" ) );
170 return a;
171 }
172
173 public static File getTestFile( String fileName )
174 {
175 return PlexusTestCase.getTestFile( "src/test/resources/" + fileName );
176 }
177}