@Test
public void testClassLoadingFromImportedContribution() throws ClassNotFoundException, MalformedURLException {
Contribution contribA = createContribution("target/test-classes");
Contribution contribB = createContribution("target");
Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
ArrayList<Contribution> exportContribList = new ArrayList<Contribution>();
exportContribList.add(contribA);
exportContribList.add(contribC);
JavaImport import_ = javaImportExportFactory.createJavaImport();
import_.setPackage(this.getClass().getPackage().getName());
import_.setExportContributions(exportContribList);
contribB.getImports().add(import_);
import_ = javaImportExportFactory.createJavaImport();
import_.setPackage("calculator");
import_.setExportContributions(exportContribList);
contribB.getImports().add(import_);
JavaExport export = javaImportExportFactory.createJavaExport();
export.setPackage(this.getClass().getPackage().getName());
contribA.getExports().add(export);
export = javaImportExportFactory.createJavaExport();
export.setPackage("calculator");
contribC.getExports().add(export);
// Load class from parent, class is also present in imported contribution. Class should
// be loaded from parent
Class<?> testClassB = contribB.getClassLoader().loadClass(this.getClass().getName());
Assert.assertNotNull(testClassB);
Assert.assertSame(this.getClass(), testClassB);
// Load class from parent, class is also present in parent. Class should be loaded
// from parent.
Class<?> testClassA = contribA.getClassLoader().loadClass(this.getClass().getName());
Assert.assertNotNull(testClassA);
Assert.assertSame(this.getClass(), testClassA);
// Imported class should be the same as the one loaded by the exporting contribution
Assert.assertSame(testClassA, testClassB);
// Load class from imported contribution, class is not present in parent
Class<?> testClassB1 = contribB.getClassLoader().loadClass("calculator.AddService");
Assert.assertNotNull(testClassB1);
// Imported class should be the same as the one loaded by the exporting contribution
Class<?> testClassC = contribC.getClassLoader().loadClass("calculator.AddService");
Assert.assertNotNull(testClassC);
Assert.assertSame(testClassC, testClassB1);
// Try to load class from package which is not explicitly imported - should throw ClassNotFoundException