| package org.eclipse.e4.languages.javascript.test; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| import junit.framework.TestCase; |
| import org.eclipse.e4.internal.languages.javascript.*; |
| import org.eclipse.e4.languages.javascript.*; |
| import org.osgi.framework.Constants; |
| import org.osgi.framework.Version; |
| |
| public class JSExportTest extends TestCase { |
| |
| public JSExportTest(String name) { |
| super(name); |
| } |
| |
| protected void setUp() throws Exception { |
| // |
| } |
| |
| protected void tearDown() throws Exception { |
| // |
| } |
| |
| public void testBothNull() { |
| try { |
| new JSExportPackage(null, null); |
| } catch (IllegalArgumentException e) { |
| return; |
| } |
| fail(); |
| } |
| |
| public void testNullHeader() throws JSBundleException { |
| JSFrameworkImpl framework = new JSFrameworkImpl(); |
| Map headers = new HashMap(); |
| headers.put(Constants.BUNDLE_SYMBOLICNAME, "test"); |
| JSBundleData data = new JSBundleData(0, "testloc", headers, null); |
| JSBundle jsBundle = new JSBundleImpl(framework, data); |
| |
| try { |
| new JSExportPackage(null, jsBundle); |
| } catch (IllegalArgumentException e) { |
| return; |
| } |
| fail(); |
| } |
| |
| public void testNullJSBundle() { |
| try { |
| new JSExportPackage("a.a", null); |
| } catch (IllegalArgumentException e) { |
| return; |
| } |
| fail(); |
| } |
| |
| public void testNameAndEmptyVersion() throws JSBundleException { |
| JSFrameworkImpl framework = new JSFrameworkImpl(); |
| Map headers = new HashMap(); |
| headers.put(Constants.BUNDLE_SYMBOLICNAME, "test"); |
| headers.put(Constants.BUNDLE_VERSION, "1.8"); |
| JSBundleData data = new JSBundleData(0, "testloc", headers, null); |
| JSBundle jsBundle = new JSBundleImpl(framework, data); |
| |
| JSExportPackage jsExport = new JSExportPackage("a.a", jsBundle); |
| assertEquals("a.a", jsExport.getName()); |
| assertEquals(Version.emptyVersion, jsExport.getVersion()); |
| assertEquals("test", jsExport.getBundleSymbolicName()); |
| assertEquals(Version.parseVersion("1.8"), jsExport.getBundleVersion()); |
| assertEquals(0, jsExport.getAttributes().size()); |
| assertEquals(0, jsExport.getDirectives().size()); |
| assertEquals(0, jsExport.getMandatory().size()); |
| } |
| |
| public void testNameAndVersion() throws JSBundleException { |
| JSFrameworkImpl framework = new JSFrameworkImpl(); |
| Map headers = new HashMap(); |
| headers.put(Constants.BUNDLE_SYMBOLICNAME, "test"); |
| headers.put(Constants.BUNDLE_VERSION, "1.8"); |
| JSBundleData data = new JSBundleData(0, "testloc", headers, null); |
| JSBundle jsBundle = new JSBundleImpl(framework, data); |
| |
| JSExportPackage jsExport = new JSExportPackage("a.a;version=1.2.1", jsBundle); |
| assertEquals("a.a", jsExport.getName()); |
| assertEquals(Version.parseVersion("1.2.1"), jsExport.getVersion()); |
| assertEquals("test", jsExport.getBundleSymbolicName()); |
| assertEquals(Version.parseVersion("1.8"), jsExport.getBundleVersion()); |
| assertEquals(1, jsExport.getAttributes().size()); |
| assertEquals(0, jsExport.getDirectives().size()); |
| assertEquals(0, jsExport.getMandatory().size()); |
| } |
| |
| public void testMandatory() throws JSBundleException { |
| JSFrameworkImpl framework = new JSFrameworkImpl(); |
| Map headers = new HashMap(); |
| headers.put(Constants.BUNDLE_SYMBOLICNAME, "test"); |
| headers.put(Constants.BUNDLE_VERSION, "1.8"); |
| JSBundleData data = new JSBundleData(0, "testloc", headers, null); |
| JSBundle jsBundle = new JSBundleImpl(framework, data); |
| |
| JSExportPackage jsExport = new JSExportPackage("a.a;i=1;j=2;mandatory:=i,j;version=1.2.1", jsBundle); |
| assertEquals("a.a", jsExport.getName()); |
| assertEquals(Version.parseVersion("1.2.1"), jsExport.getVersion()); |
| assertEquals("test", jsExport.getBundleSymbolicName()); |
| assertEquals(Version.parseVersion("1.8"), jsExport.getBundleVersion()); |
| assertEquals(3, jsExport.getAttributes().size()); |
| assertEquals(1, jsExport.getDirectives().size()); |
| assertEquals(2, jsExport.getMandatory().size()); |
| } |
| } |