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.*; 17 import org.eclipse.osgi.tests.services.resolver.AbstractStateTest; 18 import org.osgi.framework.BundleException; 19 20 public class TestCycle_005 extends AbstractStateTest { TestCycle_005(String testName)21 public TestCycle_005(String testName) { 22 super(testName); 23 } 24 25 BundleDescription bundle_1 = null; 26 BundleDescription bundle_2 = null; 27 BundleDescription bundle_3 = null; 28 testTest_002()29 public void testTest_002() { 30 State state = buildEmptyState(); 31 StateObjectFactory sof = StateObjectFactory.defaultFactory; 32 33 bundle_1 = create_bundle_1(sof); 34 bundle_2 = create_bundle_2(sof); 35 bundle_3 = create_bundle_3(sof); 36 //*************************************************** 37 // stage a 38 // expect to pass =true 39 //*************************************************** 40 addBundlesToState_a(state); 41 //*************************************************** 42 try { 43 state.resolve(); 44 } catch (Throwable t) { 45 fail("unexpected exception class=" + t.getClass().getName() + " message=" + t.getMessage()); 46 return; 47 } 48 checkBundlesResolved_a(); 49 checkWiring_a(); 50 } // end of method 51 checkWiringState_1()52 public void checkWiringState_1() { 53 } // end method 54 checkWiringState_2()55 public void checkWiringState_2() { 56 ExportPackageDescription[] exports = bundle_2.getResolvedImports(); 57 assertNotNull("export array is unexpectedly null", exports); 58 assertTrue("export array is unexpectedly empty", exports.length > 0); 59 for (ExportPackageDescription exp : exports) { 60 String exportPackageName = exp.getName(); 61 assertNotNull("package name is null", exportPackageName); 62 if (exportPackageName.equals("q")) { 63 assertNotNull("Package [q] is not wired when it should be ", exp.getExporter()); 64 assertEquals("Package [q] is wired incorrectly ", exp.getExporter(), bundle_3); 65 } 66 } // end for 67 } // end method 68 checkWiringState_3()69 public void checkWiringState_3() { 70 ExportPackageDescription[] exports = bundle_3.getResolvedImports(); 71 assertNotNull("export array is unexpectedly null", exports); 72 assertTrue("export array is unexpectedly empty", exports.length > 0); 73 for (ExportPackageDescription exp : exports) { 74 String exportPackageName = exp.getName(); 75 assertNotNull("package name is null", exportPackageName); 76 if (exportPackageName.equals("r")) { 77 assertNotNull("Package [r] is not wired when it should be ", exp.getExporter()); 78 assertEquals("Package [r] is wired incorrectly ", exp.getExporter(), bundle_2); 79 } 80 } // end for 81 } // end method 82 checkWiring_a()83 public void checkWiring_a() { 84 checkWiringState_1(); 85 checkWiringState_2(); 86 checkWiringState_3(); 87 } // end method 88 addBundlesToState_a(State state)89 public void addBundlesToState_a(State state) { 90 boolean added = false; 91 added = state.addBundle(bundle_1); 92 assertTrue("failed to add bundle ", added); 93 added = state.addBundle(bundle_2); 94 assertTrue("failed to add bundle ", added); 95 added = state.addBundle(bundle_3); 96 assertTrue("failed to add bundle ", added); 97 } // end method 98 checkBundlesResolved_a()99 public void checkBundlesResolved_a() { 100 assertTrue("unexpected bundle resolution state", !bundle_1.isResolved()); 101 assertTrue("unexpected bundle resolution state", bundle_2.isResolved()); 102 assertTrue("unexpected bundle resolution state", bundle_3.isResolved()); 103 } // end method 104 create_bundle_1(StateObjectFactory sof)105 public BundleDescription create_bundle_1(StateObjectFactory sof) { 106 java.util.Dictionary dictionary_1 = new java.util.Properties(); 107 BundleDescription bundle = null; 108 dictionary_1.put("Bundle-ManifestVersion", "2"); 109 dictionary_1.put("Bundle-SymbolicName", "A"); 110 dictionary_1.put("Export-Package", "r; version=2.0"); 111 dictionary_1.put("Import-Package", "p; version=1.0, z; version=1.0"); 112 try { 113 bundle = sof.createBundleDescription(dictionary_1, "bundle_1", 1); 114 } catch (BundleException be) { 115 fail(be.getMessage()); 116 } 117 return bundle; 118 } // end of method 119 create_bundle_2(StateObjectFactory sof)120 public BundleDescription create_bundle_2(StateObjectFactory sof) { 121 java.util.Dictionary dictionary_2 = new java.util.Properties(); 122 BundleDescription bundle = null; 123 dictionary_2.put("Bundle-ManifestVersion", "2"); 124 dictionary_2.put("Bundle-SymbolicName", "B"); 125 dictionary_2.put("Export-Package", "p; version=1.0, r; version=1.0"); 126 dictionary_2.put("Import-Package", "q; version=1.0"); 127 try { 128 bundle = sof.createBundleDescription(dictionary_2, "bundle_2", 2); 129 } catch (BundleException be) { 130 fail(be.getMessage()); 131 } 132 return bundle; 133 } // end of method 134 create_bundle_3(StateObjectFactory sof)135 public BundleDescription create_bundle_3(StateObjectFactory sof) { 136 java.util.Dictionary dictionary_3 = new java.util.Properties(); 137 BundleDescription bundle = null; 138 dictionary_3.put("Bundle-ManifestVersion", "2"); 139 dictionary_3.put("Bundle-SymbolicName", "C"); 140 dictionary_3.put("Export-Package", "q; version=1.0"); 141 dictionary_3.put("Import-Package", "r; version=1.0"); 142 try { 143 bundle = sof.createBundleDescription(dictionary_3, "bundle_3", 3); 144 } catch (BundleException be) { 145 fail(be.getMessage()); 146 } 147 return bundle; 148 } // end of method 149 150 } // end of testcase 151