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 TestBSN_001 extends AbstractStateTest {
TestBSN_001(String testName)21 	public TestBSN_001(String testName) {
22 		super(testName);
23 	}
24 
25 	BundleDescription bundle_1 = null;
26 	BundleDescription bundle_2 = null;
27 	BundleDescription bundle_3 = null;
28 
testTest_001()29 	public void testTest_001() {
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 		ExportPackageDescription[] exports = bundle_1.getResolvedImports();
54 		assertNotNull("export array is unexpectedly null", exports);
55 		assertTrue("export array is unexpectedly empty", exports.length > 0);
56 		for (ExportPackageDescription exp : exports) {
57 			String exportPackageName = exp.getName();
58 			assertNotNull("package name is null", exportPackageName);
59 			if (exportPackageName.equals("foo")) {
60 				assertNotNull("Package [foo] is not wired when it should be ", exp.getExporter());
61 				assertEquals("Package [foo] is wired incorrectly ", exp.getExporter(), bundle_3);
62 			}
63 		} // end for
64 	} // end method
65 
checkWiringState_2()66 	public void checkWiringState_2() {
67 	} // end method
68 
checkWiringState_3()69 	public void checkWiringState_3() {
70 	} // end method
71 
checkWiring_a()72 	public void checkWiring_a() {
73 		checkWiringState_1();
74 		checkWiringState_2();
75 		checkWiringState_3();
76 	} // end method
77 
addBundlesToState_a(State state)78 	public void addBundlesToState_a(State state) {
79 		boolean added = false;
80 		added = state.addBundle(bundle_1);
81 		assertTrue("failed to add bundle ", added);
82 		added = state.addBundle(bundle_2);
83 		assertTrue("failed to add bundle ", added);
84 		added = state.addBundle(bundle_3);
85 		assertTrue("failed to add bundle ", added);
86 	} // end method
87 
checkBundlesResolved_a()88 	public void checkBundlesResolved_a() {
89 		assertTrue("unexpected bundle resolution state", bundle_1.isResolved());
90 		assertTrue("unexpected bundle resolution state", !bundle_2.isResolved());
91 		assertTrue("unexpected bundle resolution state", bundle_3.isResolved());
92 	} // end method
93 
create_bundle_1(StateObjectFactory sof)94 	public BundleDescription create_bundle_1(StateObjectFactory sof) {
95 		java.util.Dictionary dictionary_1 = new java.util.Properties();
96 		BundleDescription bundle = null;
97 		dictionary_1.put("Bundle-ManifestVersion", "2");
98 		dictionary_1.put("Bundle-SymbolicName", "A");
99 		dictionary_1.put("Import-Package", "foo; version=\"1.0\"; bundle-symbolic-name=\"C\"");
100 		try {
101 			bundle = sof.createBundleDescription(dictionary_1, "bundle_1", 1);
102 		} catch (BundleException be) {
103 			fail(be.getMessage());
104 		}
105 		return bundle;
106 	} // end of method
107 
create_bundle_2(StateObjectFactory sof)108 	public BundleDescription create_bundle_2(StateObjectFactory sof) {
109 		java.util.Dictionary dictionary_2 = new java.util.Properties();
110 		BundleDescription bundle = null;
111 		dictionary_2.put("Bundle-ManifestVersion", "2");
112 		dictionary_2.put("Bundle-SymbolicName", "B");
113 		dictionary_2.put("Import-Package", "foo; version=\"1.0\"; bundle-symbolic-name=\"A\"");
114 		try {
115 			bundle = sof.createBundleDescription(dictionary_2, "bundle_2", 2);
116 		} catch (BundleException be) {
117 			fail(be.getMessage());
118 		}
119 		return bundle;
120 	} // end of method
121 
create_bundle_3(StateObjectFactory sof)122 	public BundleDescription create_bundle_3(StateObjectFactory sof) {
123 		java.util.Dictionary dictionary_3 = new java.util.Properties();
124 		BundleDescription bundle = null;
125 		dictionary_3.put("Bundle-ManifestVersion", "2");
126 		dictionary_3.put("Bundle-SymbolicName", "C");
127 		dictionary_3.put("Export-Package", "foo; version=\"1.0\"");
128 		try {
129 			bundle = sof.createBundleDescription(dictionary_3, "bundle_3", 3);
130 		} catch (BundleException be) {
131 			fail(be.getMessage());
132 		}
133 		return bundle;
134 	} // end of method
135 
136 } // end of testcase
137