01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.bundles;
05:
06: import junit.framework.TestCase;
07:
08: public class MavenToOSGiTest extends TestCase {
09:
10: public void testSymbolicName() {
11: // Nulls
12: try {
13: helpTestSymbolicName(null, null, null);
14: fail("Expected error on no groupId or artifactId");
15: } catch (IllegalArgumentException e) {
16: // expected error, testing invalid condition
17: }
18: helpTestSymbolicName(null, "a", "a");
19: helpTestSymbolicName("a", null, "a");
20:
21: // Empty strings
22: try {
23: helpTestSymbolicName("", "", null);
24: fail("Expected error on no groupId or artifactId");
25: } catch (IllegalArgumentException e) {
26: // expected error, testing invalid condition
27: }
28: helpTestSymbolicName("", "a", "a");
29: helpTestSymbolicName("a", "", "a");
30:
31: // Normal
32: helpTestSymbolicName("org.foo", "bar", "org.foo.bar");
33:
34: // Dashes
35: helpTestSymbolicName("org.foo", "bar-with-dash",
36: "org.foo.bar-with-dash");
37: helpTestSymbolicName("org-foo", "bar-baz", "org-foo.bar-baz");
38:
39: // Invalid chars
40: helpTestSymbolicName("a #4-a_0.b-c.-d", "-#123!@#$%^&*() \t",
41: "a__4-a_0.b-c.-d.-_123____________");
42: }
43:
44: private static void helpTestSymbolicName(String groupId,
45: String artifactId, String expectedSymbolicName) {
46: String sName = MavenToOSGi.artifactIdToSymbolicName(groupId,
47: artifactId);
48: assertEquals(expectedSymbolicName, sName);
49: }
50:
51: public void testVersion() {
52: helpTestVersion(1, 2, 3, null, "1.2.3");
53: helpTestVersion(1, 0, 0, "SNAPSHOT", "1.0.0.SNAPSHOT");
54: helpTestVersion(1, 0, 0, "RC-1", "1.0.0.RC-1");
55: helpTestVersion(1, 2, 3, "A B:C-D@E#f$g%",
56: "1.2.3.A_B_C-D_E_f_g_");
57: }
58:
59: private static void helpTestVersion(int majorVersion,
60: int minorVersion, int incrementalVersion, String qualifier,
61: String expected) {
62: String sVersion = MavenToOSGi.projectVersionToBundleVersion(
63: majorVersion, minorVersion, incrementalVersion,
64: qualifier);
65: assertEquals(expected, sVersion);
66: }
67:
68: public void testVersionString() {
69: helpTestVersionString("1", "1.0.0");
70: helpTestVersionString("1.2", "1.2.0");
71: helpTestVersionString("1.2.3", "1.2.3");
72: helpTestVersionString("1.2.3-SNAPSHOT", "1.2.3.SNAPSHOT");
73: helpTestVersionString("1.2.3-RC-2", "1.2.3.RC-2");
74: helpTestVersionString("1.2-SNAPSHOT", "1.2.0.SNAPSHOT");
75: helpTestVersionString("1-SNAPSHOT", "1.0.0.SNAPSHOT");
76: helpTestVersionString("RELEASE", "0.0.0.RELEASE");
77: helpTestVersionString("", "0.0.0");
78: helpTestVersionString(null, "0.0.0");
79: helpTestVersionString("1.2.3-A B:C-D@E#f$g%",
80: "1.2.3.A_B_C-D_E_f_g_");
81:
82: // test getting passed an already valid OSGI version
83: helpTestVersionString("1.2.3.SNAPSHOT", "1.2.3.SNAPSHOT");
84: }
85:
86: private static void helpTestVersionString(String mavenVersion,
87: String expected) {
88: String sVersion = MavenToOSGi
89: .projectVersionToBundleVersion(mavenVersion);
90: assertEquals(expected, sVersion);
91: }
92:
93: }
|