package org.wisdom.maven.utils;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;

/**
 * Test the Maven - OSGi conversions
 */
public class DefaultMaven2OSGiConverterTest {

    @Test
    public void testBundleSymbolicNameConversion() {
        //if artifactId is equal to last section of groupId then groupId is returned. eg.
        // org.apache.maven:maven -> org.apache.maven
        Artifact artifact = new DefaultArtifact("org.acme", "acme", "1.0", null, "jar", "", null);
        assertThat(DefaultMaven2OSGiConverter.getBundleSymbolicName(artifact)).isEqualTo("org.acme");
        //if artifactId starts with last section of groupId that portion is removed. eg.
        // org.apache.maven:maven-core -> org.apache.maven.core
        artifact = new DefaultArtifact("org.acme", "acme-api", "1.0", null, "jar", "", null);
        assertThat(DefaultMaven2OSGiConverter.getBundleSymbolicName(artifact)).isEqualTo("org.acme.api");
        // if artifactId starts with groupId then the artifactId is removed. eg.
        // org.apache:org.apache.maven.core -> org.apache.maven.core
        artifact = new DefaultArtifact("org.acme", "org.acme.api", "1.0", null, "jar", "", null);
        assertThat(DefaultMaven2OSGiConverter.getBundleSymbolicName(artifact)).isEqualTo("org.acme.api");
        // Default
        artifact = new DefaultArtifact("org.acme", "wisdom-api", "1.0", null, "jar", "", null);
        assertThat(DefaultMaven2OSGiConverter.getBundleSymbolicName(artifact)).isEqualTo("org.acme.wisdom.api");
    }

    @Test
    public void testVersionConversion() {
        // Regular versions
        assertThat(DefaultMaven2OSGiConverter.getVersion("1.0")).isEqualTo("1.0.0");
        assertThat(DefaultMaven2OSGiConverter.getVersion("1.0.0")).isEqualTo("1.0.0");
        assertThat(DefaultMaven2OSGiConverter.getVersion("1")).isEqualTo("1.0.0");

        // Snapshots
        assertThat(DefaultMaven2OSGiConverter.getVersion("1.0-SNAPSHOT")).isEqualTo("1.0.0.SNAPSHOT");
        assertThat(DefaultMaven2OSGiConverter.getVersion("1.0-1.0-20131224.083751-42"))
                .isEqualTo("1.0.0.1_0-20131224_083751-42");

        // Non-numeric versions
        assertThat(DefaultMaven2OSGiConverter.getVersion("alpha")).isEqualTo("0.0.0.alpha");

        // Version with qualifier
        assertThat(DefaultMaven2OSGiConverter.getVersion("1.0-alpha")).isEqualTo("1.0.0.alpha");
        assertThat(DefaultMaven2OSGiConverter.getVersion("1.0.0-RC1")).isEqualTo("1.0.0.RC1");
        assertThat(DefaultMaven2OSGiConverter.getVersion("1.0-RC-1")).isEqualTo("1.0.0.RC-1");
    }
}

@@ -624,34 +624,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getBu
@@ -973,34 +973,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getBu
@@ -1327,34 +1327,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getBu
@@ -1548,34 +1548,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getBu
@@ -1748,34 +1748,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getVe
@@ -1833,34 +1833,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getVe
@@ -1920,34 +1920,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getVe
@@ -2025,34 +2025,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getVe
@@ -2128,34 +2128,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getVe
@@ -2309,34 +2309,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getVe
@@ -2437,34 +2437,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getVe
@@ -2534,34 +2534,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getVe
@@ -2629,34 +2629,34 @@
 t(DefaultMaven2O
-SG
+sg
 iConverter.getVe

Fix tests after renaming.