ManifestHeaderProcessor { public static VersionRange parseVersionRange(String s) throws IllegalArgumentException{ return new VersionRange(s); }  static List<String> split(String value, String delimiter); static List<NameValuePair> parseExportString(String s); static List<NameValuePair> parseExportList(List<String> list); static Map<String, Map<String, String>> parseImportString(String s); static List<GenericMetadata> parseCapabilityString(String s); static List<GenericMetadata> parseRequirementString(String s); static NameValuePair parseBundleSymbolicName(String s); static VersionRange parseVersionRange(String s); static VersionRange parseVersionRange(String s, boolean exactVersion); static String generateFilter(Map<String, String> attribs); static String generateFilter(String type, String name,
      Map<String, String> attribs); static Map<String,String> parseFilter(String filter); static final String NESTED_FILTER_ATTRIBUTE; }
@Test public void testVersionRange() throws Exception { String version1 = "[1.2.3, 4.5.6]"; String version2="(1, 2]"; String version3="[2,4)"; String version4="(1,2)"; String version5="2"; String version6 = "2.3"; String version7="[1.2.3.q, 2.3.4.p)"; String version8="1.2.2.5"; String version9="a.b.c"; String version10=null; String version11=""; String version12="\"[1.2.3, 4.5.6]\""; VersionRange vr = ManifestHeaderProcessor.parseVersionRange(version1); assertEquals("The value is wrong", "1.2.3", vr.getMinimumVersion().toString()); assertFalse("The value is wrong", vr.isMinimumExclusive()); assertEquals("The value is wrong", "4.5.6", vr.getMaximumVersion().toString()); assertFalse("The value is wrong", vr.isMaximumExclusive()); vr = ManifestHeaderProcessor.parseVersionRange(version2); assertEquals("The value is wrong", "1.0.0", vr.getMinimumVersion().toString()); assertTrue("The value is wrong", vr.isMinimumExclusive()); assertEquals("The value is wrong", "2.0.0", vr.getMaximumVersion().toString()); assertFalse("The value is wrong", vr.isMaximumExclusive()); vr = ManifestHeaderProcessor.parseVersionRange(version3); assertEquals("The value is wrong", "2.0.0", vr.getMinimumVersion().toString()); assertFalse("The value is wrong", vr.isMinimumExclusive()); assertEquals("The value is wrong", "4.0.0", vr.getMaximumVersion().toString()); assertTrue("The value is wrong", vr.isMaximumExclusive()); vr = ManifestHeaderProcessor.parseVersionRange(version4); assertEquals("The value is wrong", "1.0.0", vr.getMinimumVersion().toString()); assertTrue("The value is wrong", vr.isMinimumExclusive()); assertEquals("The value is wrong", "2.0.0", vr.getMaximumVersion().toString()); assertTrue("The value is wrong", vr.isMaximumExclusive()); vr = ManifestHeaderProcessor.parseVersionRange(version5); assertEquals("The value is wrong", "2.0.0", vr.getMinimumVersion().toString()); assertFalse("The value is wrong", vr.isMinimumExclusive()); assertNull("The value is wrong", vr.getMaximumVersion()); assertFalse("The value is wrong", vr.isMaximumExclusive()); vr = ManifestHeaderProcessor.parseVersionRange(version6); assertEquals("The value is wrong", "2.3.0", vr.getMinimumVersion().toString()); assertFalse("The value is wrong", vr.isMinimumExclusive()); assertNull("The value is wrong", vr.getMaximumVersion()); assertFalse("The value is wrong", vr.isMaximumExclusive()); vr = ManifestHeaderProcessor.parseVersionRange(version7); assertEquals("The value is wrong", "1.2.3.q", vr.getMinimumVersion().toString()); assertFalse("The value is wrong", vr.isMinimumExclusive()); assertEquals("The value is wrong", "2.3.4.p", vr.getMaximumVersion().toString()); assertTrue("The value is wrong", vr.isMaximumExclusive()); vr = ManifestHeaderProcessor.parseVersionRange(version8); assertEquals("The value is wrong", "1.2.2.5", vr.getMinimumVersion().toString()); assertFalse("The value is wrong", vr.isMinimumExclusive()); assertNull("The value is wrong", vr.getMaximumVersion()); assertFalse("The value is wrong", vr.isMaximumExclusive()); boolean exception = false; try { vr = ManifestHeaderProcessor.parseVersionRange(version9); } catch (Exception e){ exception = true; } assertTrue("The value is wrong", exception); boolean exceptionNull = false; try { vr = ManifestHeaderProcessor.parseVersionRange(version10); } catch (Exception e){ exceptionNull = true; } assertTrue("The value is wrong", exceptionNull); vr = ManifestHeaderProcessor.parseVersionRange(version11); assertEquals("The value is wrong", "0.0.0", vr.getMinimumVersion().toString()); assertFalse("The value is wrong", vr.isMinimumExclusive()); assertNull("The value is wrong", vr.getMaximumVersion()); assertFalse("The value is wrong", vr.isMaximumExclusive()); vr = ManifestHeaderProcessor.parseVersionRange(version12); assertEquals("The value is wrong", "1.2.3", vr.getMinimumVersion().toString()); assertFalse("The value is wrong", vr.isMinimumExclusive()); assertEquals("The value is wrong", "4.5.6", vr.getMaximumVersion().toString()); assertFalse("The value is wrong", vr.isMaximumExclusive()); }
@Test public void testInvalidVersions() throws Exception { try { ManifestHeaderProcessor.parseVersionRange("a"); assertTrue("Should have thrown an exception", false); } catch (IllegalArgumentException e) { } try { ManifestHeaderProcessor.parseVersionRange("[1.0.0,1.0.1]", true); assertTrue("Should have thrown an exception", false); } catch (IllegalArgumentException e) { } }
@Test public void testExactVersion() throws Exception { VersionRange vr; try { vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 2.0.0]", true); fail("should not get here 1"); } catch (IllegalArgumentException e) { } vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 1.0.0]", true); assertTrue(vr.isExactVersion()); try { vr = ManifestHeaderProcessor.parseVersionRange("(1.0.0, 1.0.0]", true); fail("should not get here 2"); } catch (IllegalArgumentException e) { } try { vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 1.0.0)", true); fail("should not get here 3"); } catch (IllegalArgumentException e) { } vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 2.0.0]"); assertFalse(vr.isExactVersion()); vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 1.0.0]"); assertTrue(vr.isExactVersion()); }