Maven2OsgiConverterTest xref

    1   package 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
    22  import java.io.File;
    23
    24  import org.apache.maven.plugin.testing.stubs.ArtifactStub;
    25  import org.codehaus.plexus.PlexusTestCase;
    26
    27  /**
    28   * Test for {@link DefaultMaven2OsgiConverter}
    29   *
    30   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
    31   * @version $Id: Maven2OsgiConverterTest.html 1490866 2013-06-07 23:25:18Z mcculls $
    32   */
    33  public 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
    54          artifact.setGroupId( "org.apache" );
    55          artifact.setArtifactId( "org.apache.commons-logging" );
    56          s = maven2Osgi.getBundleSymbolicName( artifact );
    57          assertEquals( "org.apache.commons-logging", s );
    58
    59          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
    120         osgiVersion = maven2Osgi.getVersion( "2-SNAPSHOT" );
    121         assertEquals( "2.0.0.SNAPSHOT", osgiVersion );
    122
    123         osgiVersion = maven2Osgi.getVersion( "2" );
    124         assertEquals( "2.0.0", osgiVersion );
    125
    126         osgiVersion = maven2Osgi.getVersion( "2.1" );
    127         assertEquals( "2.1.0", osgiVersion );
    128
    129         osgiVersion = maven2Osgi.getVersion( "2.1.3" );
    130         assertEquals( "2.1.3", osgiVersion );
    131
    132         osgiVersion = maven2Osgi.getVersion( "2.1.3.4" );
    133         assertEquals( "2.1.3.4", osgiVersion );
    134
    135         osgiVersion = maven2Osgi.getVersion( "4aug2000r7-dev" );
    136         assertEquals( "0.0.0.4aug2000r7-dev", osgiVersion );
    137
    138         osgiVersion = maven2Osgi.getVersion( "1.1-alpha-2" );
    139         assertEquals( "1.1.0.alpha-2", osgiVersion );
    140
    141         osgiVersion = maven2Osgi.getVersion( "1.0-alpha-16-20070122.203121-13" );
    142         assertEquals( "1.0.0.alpha-16-20070122_203121-13", osgiVersion );
    143
    144         osgiVersion = maven2Osgi.getVersion( "1.0-20070119.021432-1" );
    145         assertEquals( "1.0.0.20070119_021432-1", osgiVersion );
    146
    147         osgiVersion = maven2Osgi.getVersion( "1-20070119.021432-1" );
    148         assertEquals( "1.0.0.20070119_021432-1", osgiVersion );
    149
    150         osgiVersion = maven2Osgi.getVersion( "1.4.1-20070217.082013-7" );
    151         assertEquals( "1.4.1.20070217_082013-7", osgiVersion );
    152
    153         osgiVersion = maven2Osgi.getVersion( "0.0.0.4aug2000r7-dev" );
    154         assertEquals( "0.0.0.4aug2000r7-dev", osgiVersion );
    155
    156         osgiVersion = maven2Osgi.getVersion( "4aug2000r7-dev" );
    157         assertEquals( "0.0.0.4aug2000r7-dev", osgiVersion );
    158     }
    159
    160     private ArtifactStub getTestArtifact()
    161     {
    162         ArtifactStub a = new ArtifactStub();
    163         a.setGroupId( "commons-logging" );
    164         a.setArtifactId( "commons-logging" );
    165         a.setVersion( "1.1" );
    166         a.setFile( getTestFile( "commons-logging-1.1.jar" ) );
    167         return a;
    168     }
    169
    170     public static File getTestFile( String fileName )
    171     {
    172         return PlexusTestCase.getTestFile( "src/test/resources/" + fileName );
    173     }
    174 }