1 /******************************************************************************* 2 * Copyright (c) 2004, 2013 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.osgi.tests.resolver; 15 16 import org.eclipse.osgi.service.resolver.BundleDescription; 17 import org.eclipse.osgi.service.resolver.ExportPackageDescription; 18 import org.eclipse.osgi.service.resolver.State; 19 import org.eclipse.osgi.service.resolver.StateObjectFactory; 20 import org.eclipse.osgi.tests.services.resolver.AbstractStateTest; 21 import org.osgi.framework.BundleException; 22 23 24 public class TestDynamic_005 extends AbstractStateTest { TestDynamic_005(String testName)25 public TestDynamic_005(String testName) { 26 super(testName); 27 } 28 29 BundleDescription bundle_1 = null; 30 BundleDescription bundle_2 = null; 31 BundleDescription bundle_3 = null; 32 33 testTest_005()34 public void testTest_005() { 35 State state = buildEmptyState(); 36 StateObjectFactory sof = StateObjectFactory.defaultFactory; 37 38 bundle_1 = create_bundle_1(sof); 39 bundle_2 = create_bundle_2(sof); 40 bundle_3 = create_bundle_3(sof); 41 //*************************************************** 42 // stage a 43 // expect to pass =true 44 //*************************************************** 45 addBundlesToState_a(state); 46 //*************************************************** 47 try { 48 state.resolve(); 49 } catch (Throwable t) { 50 fail("unexpected exception class=" + t.getClass().getName() 51 + " message=" + t.getMessage()); 52 return; 53 } 54 checkBundlesResolved_a(); 55 checkWiring_a(); 56 57 // Dynamics 58 ExportPackageDescription exp = state.linkDynamicImport(bundle_1, "q"); 59 assertNotNull("Package [q] is not wired when it should be ", exp); 60 assertEquals("Package [q] is wired incorrectly ", exp.getExporter(), bundle_3); 61 62 } // end of method 63 64 checkWiringState_1()65 public void checkWiringState_1() { 66 } // end method 67 checkWiringState_2()68 public void checkWiringState_2() { 69 } // end method 70 checkWiringState_3()71 public void checkWiringState_3() { 72 } // end method 73 74 checkWiring_a()75 public void checkWiring_a() { 76 checkWiringState_1(); 77 checkWiringState_2(); 78 checkWiringState_3(); 79 } // end method 80 81 addBundlesToState_a(State state)82 public void addBundlesToState_a(State state) { 83 boolean added = false; 84 added = state.addBundle(bundle_1); 85 assertTrue("failed to add bundle ", added); 86 added = state.addBundle(bundle_2); 87 assertTrue("failed to add bundle ", added); 88 added = state.addBundle(bundle_3); 89 assertTrue("failed to add bundle ", added); 90 } // end method 91 92 checkBundlesResolved_a()93 public void checkBundlesResolved_a() { 94 assertTrue("unexpected bundle resolution state", bundle_1.isResolved()); 95 assertTrue("unexpected bundle resolution state", bundle_2.isResolved()); 96 assertTrue("unexpected bundle resolution state", bundle_3.isResolved()); 97 } // end method 98 99 create_bundle_1(StateObjectFactory sof)100 public BundleDescription create_bundle_1(StateObjectFactory sof) { 101 java.util.Dictionary dictionary_1 = new java.util.Properties(); 102 BundleDescription bundle = null; 103 dictionary_1.put("Bundle-ManifestVersion", "2"); 104 dictionary_1.put("Bundle-SymbolicName", "A"); 105 dictionary_1.put("DynamicImport-Package", "*"); 106 try { 107 bundle = sof.createBundleDescription(dictionary_1, "bundle_1", 1); 108 } catch (BundleException be) { 109 fail(be.getMessage()); 110 } 111 return bundle; 112 } // end of method 113 create_bundle_2(StateObjectFactory sof)114 public BundleDescription create_bundle_2(StateObjectFactory sof) { 115 java.util.Dictionary dictionary_2 = new java.util.Properties(); 116 BundleDescription bundle = null; 117 dictionary_2.put("Bundle-ManifestVersion", "2"); 118 dictionary_2.put("Bundle-SymbolicName", "B"); 119 dictionary_2.put("Export-Package", "p"); 120 try { 121 bundle = sof.createBundleDescription(dictionary_2, "bundle_2", 2); 122 } catch (BundleException be) { 123 fail(be.getMessage()); 124 } 125 return bundle; 126 } // end of method 127 create_bundle_3(StateObjectFactory sof)128 public BundleDescription create_bundle_3(StateObjectFactory sof) { 129 java.util.Dictionary dictionary_3 = new java.util.Properties(); 130 BundleDescription bundle = null; 131 dictionary_3.put("Bundle-ManifestVersion", "2"); 132 dictionary_3.put("Bundle-SymbolicName", "C"); 133 dictionary_3.put("Export-Package", "q"); 134 try { 135 bundle = sof.createBundleDescription(dictionary_3, "bundle_3", 3); 136 } catch (BundleException be) { 137 fail(be.getMessage()); 138 } 139 return bundle; 140 } // end of method 141 142 } // end of testcase 143