ManifestHeaderProcessor { public static List<NameValuePair> parseExportString(String s){ NameValueList retval = new NameValueList(); genericImportExportProcess(retval, s); return retval; }  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 testParseExportString() { String exportPackage = "com.acme.foo,com.acme.bar;version=1,com.acme.bar;version=2;uses:=\"a.b.c,d.e.f\";security=false;mandatory:=security"; List<NameValuePair> exportPackageReturn = ManifestHeaderProcessor.parseExportString(exportPackage); int i =0; assertEquals("The number of the packages is wrong.", 3, exportPackageReturn.size()); for (NameValuePair nvp : exportPackageReturn) { if (nvp.getName().equals("com.acme.foo")) { i++; assertTrue("The directive or attribute should not be set.", nvp.getAttributes().isEmpty() ); } else if ((nvp.getName().equals("com.acme.bar")) && ("2".equals(nvp.getAttributes().get("version")))) { i++; assertEquals("The directive is wrong.", "a.b.c,d.e.f", nvp.getAttributes().get("uses:")); assertEquals("The directive is wrong.", "false", nvp.getAttributes().get("security")); assertEquals("The directive is wrong.", "security", nvp.getAttributes().get("mandatory:")); } else if ((nvp.getName().equals("com.acme.bar")) && ("1".equals(nvp.getAttributes().get("version")))) { i++; assertNull("The directive is wrong.", nvp.getAttributes().get("uses:")); assertNull("The directive is wrong.", nvp.getAttributes().get("security")); assertNull("The directive is wrong.", nvp.getAttributes().get("mandatory:")); } } assertEquals("The names of the packages are wrong.", 3, i); exportPackage = "com.acme.foo"; exportPackageReturn = ManifestHeaderProcessor.parseExportString(exportPackage); int k =0; assertEquals("The number of the packages is wrong.", 1, exportPackageReturn.size()); for (NameValuePair nvp : exportPackageReturn) { if (nvp.getName().equals("com.acme.foo")) { k++; assertTrue("The directive or attribute should not be set.", nvp.getAttributes().isEmpty() ); } } assertEquals("The names of the packages are wrong.", 1, k); exportPackage = "com.acme.foo;com.acme.bar;version=\"2\";resolution:=optional"; exportPackageReturn = ManifestHeaderProcessor.parseExportString(exportPackage); k =0; assertEquals("The number of the packages is wrong.", 2, exportPackageReturn.size()); for (NameValuePair nvp : exportPackageReturn) { if (nvp.getName().equals("com.acme.foo")) { k++; assertEquals("The attribute is wrong.", "2", nvp.getAttributes().get("version") ); assertEquals("The attribute is wrong.", "optional", nvp.getAttributes().get("resolution:")); } else if (nvp.getName().equals("com.acme.bar")) { k++; assertEquals("The attribute is wrong.", "2", nvp.getAttributes().get("version") ); assertEquals("The attribute is wrong.", "optional", nvp.getAttributes().get("resolution:")); } } assertEquals("The names of the packages are wrong.", 2, k); exportPackageReturn = ManifestHeaderProcessor.parseExportString("some.export.with.space.in;directive := spacey"); assertEquals(exportPackageReturn.toString(), "spacey", exportPackageReturn.get(0).getAttributes().get("directive:")); }
@Test public void testExportMandatoryAttributes() { String exportPackage = "com.acme.foo,com.acme.bar;version=2;company=dodo;security=false;mandatory:=\"security,company\""; List<NameValuePair> exportPackageReturn = ManifestHeaderProcessor.parseExportString(exportPackage); int i =0; assertEquals("The number of the packages is wrong.", 2, exportPackageReturn.size()); for (NameValuePair nvp : exportPackageReturn) { if (nvp.getName().equals("com.acme.foo")) { i++; assertTrue("The directive or attribute should not be set.", nvp.getAttributes().isEmpty() ); } else if ((nvp.getName().equals("com.acme.bar")) && ("2".equals(nvp.getAttributes().get("version")))) { i++; assertEquals("The directive is wrong.", "dodo", nvp.getAttributes().get("company")); assertEquals("The directive is wrong.", "false", nvp.getAttributes().get("security")); assertEquals("The directive is wrong.", "security,company", nvp.getAttributes().get("mandatory:")); } } assertEquals("The names of the packages are wrong.", 2, i); }