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 TestRFC79_003 extends AbstractStateTest { TestRFC79_003(String testName)25 public TestRFC79_003(String testName) { 26 super(testName); 27 } 28 29 BundleDescription bundle_1 = null; 30 BundleDescription bundle_2 = null; 31 BundleDescription bundle_3 = null; 32 BundleDescription bundle_4 = null; 33 34 testTest_003()35 public void testTest_003() { 36 State state = buildEmptyState(); 37 StateObjectFactory sof = StateObjectFactory.defaultFactory; 38 39 bundle_1 = create_bundle_1(sof); 40 bundle_2 = create_bundle_2(sof); 41 bundle_3 = create_bundle_3(sof); 42 bundle_4 = create_bundle_4(sof); 43 //*************************************************** 44 // stage a 45 // expect to pass =true 46 //*************************************************** 47 addBundlesToState_a(state); 48 //*************************************************** 49 try { 50 state.resolve(); 51 } catch (Throwable t) { 52 fail("unexpected exception class=" + t.getClass().getName() 53 + " message=" + t.getMessage()); 54 return; 55 } 56 checkBundlesResolved_a(); 57 checkWiring_a(); 58 } // end of method 59 60 checkWiringState_1()61 public void checkWiringState_1() { 62 ExportPackageDescription[] exports = bundle_1.getResolvedImports(); 63 assertNotNull("export array is unexpectedly null", exports); 64 assertTrue("export array is unexpectedly empty", exports.length > 0); 65 for (ExportPackageDescription export : exports) { 66 String exportPackageName = export.getName(); 67 assertNotNull("package name is null", exportPackageName); 68 if (exportPackageName.equals("javax.servlet")) { 69 assertNotNull("Package [javax.servlet] is not wired when it should be ", export.getExporter()); 70 assertEquals("Package [javax.servlet] is wired incorrectly ", export.getExporter(), bundle_2); 71 } 72 } // end for 73 } // end method 74 checkWiringState_2()75 public void checkWiringState_2() { 76 ExportPackageDescription[] exports = bundle_2.getResolvedImports(); 77 assertNotNull("export array is unexpectedly null", exports); 78 assertTrue("export array is unexpectedly empty", exports.length > 0); 79 for (ExportPackageDescription export : exports) { 80 String exportPackageName = export.getName(); 81 assertNotNull("package name is null", exportPackageName); 82 if (exportPackageName.equals("javax.servlet")) { 83 assertNotNull("Package [javax.servlet] is not wired when it should be ", export.getExporter()); 84 assertEquals("Package [javax.servlet] is wired incorrectly ", export.getExporter(), bundle_2); 85 } 86 } // end for 87 } // end method 88 checkWiringState_3()89 public void checkWiringState_3() { 90 ExportPackageDescription[] exports = bundle_3.getResolvedImports(); 91 assertNotNull("export array is unexpectedly null", exports); 92 assertTrue("export array is unexpectedly empty", exports.length > 0); 93 for (ExportPackageDescription export : exports) { 94 String exportPackageName = export.getName(); 95 assertNotNull("package name is null", exportPackageName); 96 if (exportPackageName.equals("org.foo.impl")) { 97 assertNotNull("Package [org.foo.impl] is not wired when it should be ", export.getExporter()); 98 assertEquals("Package [org.foo.impl] is wired incorrectly ", export.getExporter(), bundle_1); 99 } else if (exportPackageName.equals("javax.servlet")) { 100 assertNotNull("Package [javax.servlet] is not wired when it should be ", export.getExporter()); 101 assertEquals("Package [javax.servlet] is wired incorrectly ", export.getExporter(), bundle_2); 102 } 103 } // end for 104 } // end method 105 checkWiringState_4()106 public void checkWiringState_4() { 107 ExportPackageDescription[] exports = bundle_4.getResolvedImports(); 108 assertNotNull("export array is unexpectedly null", exports); 109 assertTrue("export array is unexpectedly empty", exports.length > 0); 110 for (ExportPackageDescription export : exports) { 111 String exportPackageName = export.getName(); 112 assertNotNull("package name is null", exportPackageName); 113 if (exportPackageName.equals("org.foo.impl")) { 114 assertNotNull("Package [org.foo.impl] is not wired when it should be ", export.getExporter()); 115 assertEquals("Package [org.foo.impl] is wired incorrectly ", export.getExporter(), bundle_1); 116 } else if (exportPackageName.equals("javax.servlet")) { 117 assertNotNull("Package [javax.servlet] is not wired when it should be ", export.getExporter()); 118 assertEquals("Package [javax.servlet] is wired incorrectly ", export.getExporter(), bundle_2); 119 } 120 } // end for 121 } // end method 122 123 124 checkWiring_a()125 public void checkWiring_a() { 126 checkWiringState_1(); 127 checkWiringState_2(); 128 checkWiringState_3(); 129 checkWiringState_4(); 130 } // end method 131 132 addBundlesToState_a(State state)133 public void addBundlesToState_a(State state) { 134 boolean added = false; 135 added = state.addBundle(bundle_1); 136 assertTrue("failed to add bundle ", added); 137 added = state.addBundle(bundle_2); 138 assertTrue("failed to add bundle ", added); 139 added = state.addBundle(bundle_3); 140 assertTrue("failed to add bundle ", added); 141 added = state.addBundle(bundle_4); 142 assertTrue("failed to add bundle ", added); 143 } // end method 144 145 checkBundlesResolved_a()146 public void checkBundlesResolved_a() { 147 assertTrue("unexpected bundle resolution state", bundle_1.isResolved()); 148 assertTrue("unexpected bundle resolution state", bundle_2.isResolved()); 149 assertTrue("unexpected bundle resolution state", bundle_3.isResolved()); 150 assertTrue("unexpected bundle resolution state", bundle_4.isResolved()); 151 } // end method 152 153 create_bundle_1(StateObjectFactory sof)154 public BundleDescription create_bundle_1(StateObjectFactory sof) { 155 java.util.Dictionary dictionary_1 = new java.util.Properties(); 156 BundleDescription bundle = null; 157 dictionary_1.put("Bundle-ManifestVersion", "2"); 158 dictionary_1.put("Bundle-SymbolicName", "A"); 159 dictionary_1.put("Export-Package", "org.foo.impl; version=1.0.0, javax.servlet; version=2.1.0"); 160 dictionary_1.put("Import-Package", "javax.servlet; version=2.1.0"); 161 try { 162 bundle = sof.createBundleDescription(dictionary_1, "bundle_1", 1); 163 } catch (BundleException be) { 164 fail(be.getMessage()); 165 } 166 return bundle; 167 } // end of method 168 create_bundle_2(StateObjectFactory sof)169 public BundleDescription create_bundle_2(StateObjectFactory sof) { 170 java.util.Dictionary dictionary_2 = new java.util.Properties(); 171 BundleDescription bundle = null; 172 dictionary_2.put("Bundle-ManifestVersion", "2"); 173 dictionary_2.put("Bundle-SymbolicName", "B"); 174 dictionary_2.put("Export-Package", "org.foo.impl; version=1.0.0, javax.servlet; version=2.2.0"); 175 dictionary_2.put("Import-Package", "javax.servlet; version=2.2.0"); 176 try { 177 bundle = sof.createBundleDescription(dictionary_2, "bundle_2", 2); 178 } catch (BundleException be) { 179 fail(be.getMessage()); 180 } 181 return bundle; 182 } // end of method 183 create_bundle_3(StateObjectFactory sof)184 public BundleDescription create_bundle_3(StateObjectFactory sof) { 185 java.util.Dictionary dictionary_3 = new java.util.Properties(); 186 BundleDescription bundle = null; 187 dictionary_3.put("Bundle-ManifestVersion", "2"); 188 dictionary_3.put("Bundle-SymbolicName", "C"); 189 dictionary_3.put("Import-Package", "javax.servlet; version=2.1.0, org.foo.impl; version=\"[1.0.0, 1.0.0]\"; bundle-symbolic-name=A"); 190 try { 191 bundle = sof.createBundleDescription(dictionary_3, "bundle_3", 3); 192 } catch (BundleException be) { 193 fail(be.getMessage()); 194 } 195 return bundle; 196 } // end of method 197 create_bundle_4(StateObjectFactory sof)198 public BundleDescription create_bundle_4(StateObjectFactory sof) { 199 java.util.Dictionary dictionary_4 = new java.util.Properties(); 200 BundleDescription bundle = null; 201 dictionary_4.put("Bundle-ManifestVersion", "2"); 202 dictionary_4.put("Bundle-SymbolicName", "D"); 203 dictionary_4.put("Import-Package", "javax.servlet; version=2.1.0, org.foo.impl; version=\"[1.0.0, 1.0.0]\""); 204 try { 205 bundle = sof.createBundleDescription(dictionary_4, "bundle_4", 4); 206 } catch (BundleException be) { 207 fail(be.getMessage()); 208 } 209 return bundle; 210 } // end of method 211 212 213 } // end of testcase 214