blob: d732efce11c22f909093b206f0900cd688f60073 [file] [log] [blame]
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 JSBundleTest extends TestCase {
public JSBundleTest(String name) {
super(name);
}
public void testNullHeaders() {
JSFrameworkImpl framework = new JSFrameworkImpl();
try {
new JSBundleImpl(framework, null);
} catch (NullPointerException e) {
return;
}
fail();
}
public void testNameAndEmptyVersion() 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);
assertEquals("test", jsBundle.getSymbolicName());
assertEquals(Version.emptyVersion, jsBundle.getVersion());
}
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);
assertEquals("test", jsBundle.getSymbolicName());
assertEquals(Version.parseVersion("1.8"), jsBundle.getVersion());
}
public void testNoExportsImportsRequires() 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);
JSBundleImpl jsBundle = new JSBundleImpl(framework, data);
assertEquals("test", jsBundle.getSymbolicName());
assertEquals(Version.parseVersion("1.8"), jsBundle.getVersion());
assertEquals(0, jsBundle.getExports().size());
assertEquals(0, jsBundle.getImports().size());
assertEquals(0, jsBundle.getRequires().size());
}
public void testOneExportsImportsRequires() throws JSBundleException {
JSFrameworkImpl framework = new JSFrameworkImpl();
Map headers = new HashMap();
headers.put(Constants.BUNDLE_SYMBOLICNAME, "test");
headers.put(Constants.BUNDLE_VERSION, "1.8");
headers.put(Constants.EXPORT_PACKAGE, "a.a");
headers.put(Constants.IMPORT_PACKAGE, "c.c");
headers.put(Constants.REQUIRE_BUNDLE, "test1");
JSBundleData data = new JSBundleData(0, "testloc", headers, null);
JSBundleImpl jsBundle = new JSBundleImpl(framework, data);
assertEquals("test", jsBundle.getSymbolicName());
assertEquals(Version.parseVersion("1.8"), jsBundle.getVersion());
assertEquals(1, jsBundle.getExports().size());
assertEquals("a.a", ((JSExportPackage) jsBundle.getExports().get(0)).getName());
assertEquals(1, jsBundle.getImports().size());
assertEquals("c.c", ((JSImportPackage) jsBundle.getImports().get(0)).getName());
assertEquals(1, jsBundle.getRequires().size());
assertEquals("test1", ((JSRequireBundle) jsBundle.getRequires().get(0)).getName());
}
public void testTwoExportsImportsRequires() throws JSBundleException {
JSFrameworkImpl framework = new JSFrameworkImpl();
Map headers = new HashMap();
headers.put(Constants.BUNDLE_SYMBOLICNAME, "test");
headers.put(Constants.BUNDLE_VERSION, "1.8");
headers.put(Constants.EXPORT_PACKAGE, "a.a, b.b");
headers.put(Constants.IMPORT_PACKAGE, "c.c, d.d");
headers.put(Constants.REQUIRE_BUNDLE, "test1, test2");
JSBundleData data = new JSBundleData(0, "testloc", headers, null);
JSBundleImpl jsBundle = new JSBundleImpl(framework, data);
assertEquals("test", jsBundle.getSymbolicName());
assertEquals(Version.parseVersion("1.8"), jsBundle.getVersion());
assertEquals(2, jsBundle.getExports().size());
assertEquals("a.a", ((JSExportPackage) jsBundle.getExports().get(0)).getName());
assertEquals("b.b", ((JSExportPackage) jsBundle.getExports().get(1)).getName());
assertEquals(2, jsBundle.getImports().size());
assertEquals("c.c", ((JSImportPackage) jsBundle.getImports().get(0)).getName());
assertEquals("d.d", ((JSImportPackage) jsBundle.getImports().get(1)).getName());
assertEquals(2, jsBundle.getRequires().size());
assertEquals("test1", ((JSRequireBundle) jsBundle.getRequires().get(0)).getName());
assertEquals("test2", ((JSRequireBundle) jsBundle.getRequires().get(1)).getName());
}
}