Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e6a0bf6da6c6acb9b8afb1bb41240ecaa10e8bc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
/*******************************************************************************
 * Copyright (c) 2012, 2015 VMware Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   VMware Inc. - initial contribution
 *******************************************************************************/

package org.eclipse.equinox.region.internal.tests.hook;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.*;
import org.eclipse.equinox.region.*;
import org.eclipse.equinox.region.internal.tests.RegionReflectionUtils;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
import org.junit.*;
import org.osgi.framework.*;
import org.osgi.framework.hooks.resolver.ResolverHook;
import org.osgi.framework.wiring.*;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;

public class RegionResolverHookTests {

	private static final String PACKAGE_A = "package.a";

	private static final String PACKAGE_B = "package.b";

	private static final String PACKAGE_C = "package.c";

	private static final String PACKAGE_D = "package.d";

	private static final String PACKAGE_X = "package.x";

	private static final String PACKAGE_DUP = "duplicate";

	private static final String BUNDLE_X = "X";

	private static final Version BUNDLE_VERSION = new Version("0");

	private long bundleId;

	private static final String REGION_A = "RegionA";

	private static final String BUNDLE_A = "BundleA";

	private static final String REGION_B = "RegionB";

	private static final String BUNDLE_B = "BundleB";

	private static final String REGION_C = "RegionC";

	private static final String BUNDLE_C = "BundleC";

	private static final String REGION_D = "RegionD";

	private static final String BUNDLE_D = "BundleD";

	private RegionDigraph digraph;

	private ResolverHook resolverHook;

	private Map<String, Region> regions;

	private Map<String, Bundle> bundles;

	private Collection<BundleCapability> candidates;

	private ThreadLocal<Region> threadLocal;

	@Before
	public void setUp() throws Exception {
		this.bundleId = 1L;
		this.regions = new HashMap<String, Region>();
		this.bundles = new HashMap<String, Bundle>();
		this.threadLocal = new ThreadLocal<Region>();
		StubBundle stubSystemBundle = new StubBundle(0L, "osgi.framework", new Version("0"), "loc");
		StubBundleContext stubBundleContext = new StubBundleContext();
		stubBundleContext.addInstalledBundle(stubSystemBundle);
		this.digraph = RegionReflectionUtils.newStandardRegionDigraph(stubBundleContext, this.threadLocal);
		this.resolverHook = RegionReflectionUtils.newRegionResolverHook(this.digraph);
		this.candidates = new HashSet<BundleCapability>();

		// Create regions A, B, C, D containing bundles A, B, C, D, respectively.
		createRegion(REGION_A, BUNDLE_A);
		createRegion(REGION_B, BUNDLE_B);
		createRegion(REGION_C, BUNDLE_C);
		createRegion(REGION_D, BUNDLE_D);

		createBundle(BUNDLE_X);

	}

	@After
	public void tearDown() throws Exception {
		// nothing
	}

	@Test
	public void testResolveInSameRegion() {
		this.candidates.add(packageCapability(BUNDLE_A, PACKAGE_A));
		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_A), this.candidates);
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_A, PACKAGE_A)));
	}

	@Test
	public void testNoRegionResolvable() {
		Collection<BundleRevision> resolvable = new ArrayList<BundleRevision>(Collections.singleton(new StubBundleRevision(bundle(BUNDLE_X))));
		this.resolverHook.filterResolvable(resolvable);
		assertTrue("Resolvable is not empty" + resolvable, resolvable.isEmpty());
	}

	@Test
	public void testResolveInDisconnectedRegion() {
		this.candidates.add(packageCapability(BUNDLE_B, PACKAGE_B));
		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_A), this.candidates);
		assertFalse(this.candidates.contains(packageCapability(BUNDLE_B, PACKAGE_B)));
	}

	@Test
	public void testResolveConnectedRegionAllowed() throws BundleException, InvalidSyntaxException {
		RegionFilter filter = createFilter(PACKAGE_B);
		region(REGION_A).connectRegion(region(REGION_B), filter);

		this.candidates.add(packageCapability(BUNDLE_B, PACKAGE_B));
		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_A), this.candidates);
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_B, PACKAGE_B)));
	}

	@Test
	public void testResolveBundleCapabilityConnectedRegionAllowed() throws BundleException, InvalidSyntaxException {
		RegionFilter filter = createBundleFilter(BUNDLE_B, BUNDLE_VERSION);
		region(REGION_A).connectRegion(region(REGION_B), filter);

		this.candidates.add(bundleCapability(BUNDLE_B));
		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_A), this.candidates);
		assertTrue(this.candidates.contains(bundleCapability(BUNDLE_B)));
	}

	@Test
	public void testResolveConnectedRegionFiltering() throws BundleException, InvalidSyntaxException {
		region(REGION_A).connectRegion(region(REGION_B), createFilter(PACKAGE_B));
		Bundle x = createBundle(BUNDLE_X);
		region(REGION_B).addBundle(x);

		this.candidates.add(packageCapability(BUNDLE_B, PACKAGE_B));
		this.candidates.add(packageCapability(BUNDLE_X, PACKAGE_X));
		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_A), this.candidates);
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_B, PACKAGE_B)));
		assertFalse(this.candidates.contains(packageCapability(BUNDLE_X, PACKAGE_X)));
	}

	@Test
	public void testResolveBundleConnectedRegionFiltering() throws BundleException, InvalidSyntaxException {
		RegionFilter filter = createBundleFilter(BUNDLE_B, BUNDLE_VERSION);
		region(REGION_A).connectRegion(region(REGION_B), filter);
		Bundle x = createBundle(BUNDLE_X);
		region(REGION_B).addBundle(x);

		this.candidates.add(bundleCapability(BUNDLE_B));
		this.candidates.add(bundleCapability(BUNDLE_X));
		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_A), this.candidates);
		assertTrue(this.candidates.contains(bundleCapability(BUNDLE_B)));
		assertFalse(this.candidates.contains(bundleCapability(BUNDLE_X)));
	}

	@Test
	public void testResolveSingletonInSameRegions() {
		List<BundleCapability> collisionCandidates = new ArrayList<BundleCapability>();
		collisionCandidates.add(bundleCapability(BUNDLE_B));
		collisionCandidates.add(bundleCapability(BUNDLE_C));
		collisionCandidates.add(bundleCapability(BUNDLE_D));
		this.resolverHook.filterSingletonCollisions(bundleCapability(BUNDLE_A), collisionCandidates);
		assertEquals("Wrong number of collitions", 0, collisionCandidates.size());
	}

	@Test
	public void testResolveSingletonInDifferentRegions() throws BundleException {
		region(REGION_A).addBundle(bundle(BUNDLE_X));
		BundleCapability collision = bundleCapability(BUNDLE_X);
		List<BundleCapability> collisionCandidates = new ArrayList<BundleCapability>();
		collisionCandidates.add(collision);
		collisionCandidates.add(bundleCapability(BUNDLE_B));
		collisionCandidates.add(bundleCapability(BUNDLE_C));
		collisionCandidates.add(bundleCapability(BUNDLE_D));
		this.resolverHook.filterSingletonCollisions(bundleCapability(BUNDLE_A), collisionCandidates);
		assertEquals("Wrong number of collitions", 1, collisionCandidates.size());
		collisionCandidates.contains(collision);
	}

	@Test
	public void testResolveSingletonConnectedRegions() throws BundleException, InvalidSyntaxException {
		RegionFilter filter = createBundleFilter(BUNDLE_B, BUNDLE_VERSION);
		region(REGION_A).connectRegion(region(REGION_B), filter);
		region(REGION_A).addBundle(bundle(BUNDLE_X));
		BundleCapability collisionX = bundleCapability(BUNDLE_X);
		BundleCapability collisionB = bundleCapability(BUNDLE_B);
		List<BundleCapability> collisionCandidates = new ArrayList<BundleCapability>();
		collisionCandidates.add(collisionX);
		collisionCandidates.add(collisionB);
		collisionCandidates.add(bundleCapability(BUNDLE_C));
		collisionCandidates.add(bundleCapability(BUNDLE_D));
		this.resolverHook.filterSingletonCollisions(bundleCapability(BUNDLE_A), collisionCandidates);
		assertEquals("Wrong number of collitions", 2, collisionCandidates.size());
		collisionCandidates.contains(collisionX);
		collisionCandidates.contains(collisionB);
	}

	@Test
	public void testResolveTransitive() throws BundleException, InvalidSyntaxException {
		region(REGION_A).connectRegion(region(REGION_B), createFilter(PACKAGE_C));
		region(REGION_B).connectRegion(region(REGION_C), createFilter(PACKAGE_C));
		region(REGION_C).addBundle(bundle(BUNDLE_X));

		this.candidates.add(packageCapability(BUNDLE_B, PACKAGE_B));
		this.candidates.add(packageCapability(BUNDLE_C, PACKAGE_C));
		this.candidates.add(packageCapability(BUNDLE_X, PACKAGE_X));
		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_A), this.candidates);
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_C, PACKAGE_C)));
		assertFalse(this.candidates.contains(packageCapability(BUNDLE_B, PACKAGE_B)));
		assertFalse(this.candidates.contains(packageCapability(BUNDLE_X, PACKAGE_X)));
	}

	@Test
	public void testResolveTransitiveDups() throws BundleException, InvalidSyntaxException {
		region(REGION_A).connectRegion(region(REGION_B), createFilter(PACKAGE_B));
		region(REGION_A).connectRegion(region(REGION_C), createFilter(PACKAGE_DUP));
		region(REGION_A).connectRegion(region(REGION_D), createFilter(PACKAGE_DUP));
		region(REGION_B).connectRegion(region(REGION_C), createFilter(PACKAGE_DUP));
		region(REGION_C).connectRegion(region(REGION_D), createFilter(PACKAGE_DUP));
		region(REGION_D).connectRegion(region(REGION_A), createFilter(PACKAGE_DUP));

		this.candidates.add(packageCapability(BUNDLE_A, PACKAGE_DUP));
		this.candidates.add(packageCapability(BUNDLE_B, PACKAGE_DUP));
		this.candidates.add(packageCapability(BUNDLE_C, PACKAGE_DUP));
		this.candidates.add(packageCapability(BUNDLE_D, PACKAGE_DUP));

		Collection<BundleCapability> testCandidates = new ArrayList<BundleCapability>(this.candidates);
		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_A), testCandidates);
		assertTrue(testCandidates.contains(packageCapability(BUNDLE_A, PACKAGE_DUP)));
		assertFalse(testCandidates.contains(packageCapability(BUNDLE_B, PACKAGE_DUP)));
		assertTrue(testCandidates.contains(packageCapability(BUNDLE_C, PACKAGE_DUP)));
		assertTrue(testCandidates.contains(packageCapability(BUNDLE_D, PACKAGE_DUP)));

		testCandidates = new ArrayList<BundleCapability>(this.candidates);
		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_B), testCandidates);
		assertTrue(testCandidates.contains(packageCapability(BUNDLE_A, PACKAGE_DUP)));
		assertTrue(testCandidates.contains(packageCapability(BUNDLE_B, PACKAGE_DUP)));
		assertTrue(testCandidates.contains(packageCapability(BUNDLE_C, PACKAGE_DUP)));
		assertTrue(testCandidates.contains(packageCapability(BUNDLE_D, PACKAGE_DUP)));
	}

	@Test
	public void testResolveInCyclicGraph() throws BundleException, InvalidSyntaxException {
		region(REGION_D).addBundle(bundle(BUNDLE_X));

		region(REGION_A).connectRegion(region(REGION_B), createFilter(PACKAGE_D, PACKAGE_X));
		region(REGION_B).connectRegion(region(REGION_A), createFilter());

		region(REGION_B).connectRegion(region(REGION_D), createFilter(PACKAGE_D));
		region(REGION_D).connectRegion(region(REGION_B), createFilter());

		region(REGION_B).connectRegion(region(REGION_C), createFilter(PACKAGE_X));
		region(REGION_C).connectRegion(region(REGION_B), createFilter());

		region(REGION_C).connectRegion(region(REGION_D), createFilter(PACKAGE_X));
		region(REGION_D).connectRegion(region(REGION_C), createFilter());

		region(REGION_A).connectRegion(region(REGION_C), createFilter());
		region(REGION_C).connectRegion(region(REGION_A), createFilter());

		region(REGION_D).connectRegion(region(REGION_A), createFilter());
		region(REGION_A).connectRegion(region(REGION_D), createFilter());

		// Find from region A.
		this.candidates.add(packageCapability(BUNDLE_B, PACKAGE_B));
		this.candidates.add(packageCapability(BUNDLE_C, PACKAGE_C));
		this.candidates.add(packageCapability(BUNDLE_D, PACKAGE_D));
		this.candidates.add(packageCapability(BUNDLE_X, PACKAGE_X));

		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_A), this.candidates);
		assertEquals(2, this.candidates.size());
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_D, PACKAGE_D)));
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_X, PACKAGE_X)));

		// Find from region B
		this.candidates.add(packageCapability(BUNDLE_B, PACKAGE_B));
		this.candidates.add(packageCapability(BUNDLE_C, PACKAGE_C));
		this.candidates.add(packageCapability(BUNDLE_D, PACKAGE_D));
		this.candidates.add(packageCapability(BUNDLE_X, PACKAGE_X));

		this.resolverHook.filterMatches(bundleRequirement(BUNDLE_B), this.candidates);
		assertEquals(3, this.candidates.size());
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_B, PACKAGE_B)));
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_D, PACKAGE_D)));
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_X, PACKAGE_X)));
	}

	@Test
	public void testResolveFromSystemBundle() {
		this.candidates.add(packageCapability(BUNDLE_A, PACKAGE_A));

		Bundle stubBundle = new StubBundle(0L, "sys", BUNDLE_VERSION, "");
		this.resolverHook.filterMatches(new StubBundleRequirement(stubBundle), this.candidates);
		assertEquals(1, this.candidates.size());
		assertTrue(this.candidates.contains(packageCapability(BUNDLE_A, PACKAGE_A)));
	}

	@Test
	public void testResolveFromBundleInNoRegion() {
		this.candidates.add(packageCapability(BUNDLE_A, PACKAGE_A));

		Bundle stranger = createBundle("stranger");
		this.resolverHook.filterMatches(new StubBundleRequirement(stranger), this.candidates);
		assertEquals(0, this.candidates.size());
	}

	@Test
	public void testUnimplementedMethods() {
		this.resolverHook.end();
	}

	private BundleCapability packageCapability(final String bundleSymbolicName, String packageName) {
		return new StubPackageCapability(bundleSymbolicName, packageName);
	}

	private BundleCapability bundleCapability(String bundleSymbolicName) {
		return new StubBundleCapability(bundleSymbolicName);
	}

	private Region createRegion(String regionName, String... bundleSymbolicNames) throws BundleException {
		Region region = this.digraph.createRegion(regionName);
		for (String bundleSymbolicName : bundleSymbolicNames) {
			Bundle stubBundle = createBundle(bundleSymbolicName);
			region.addBundle(stubBundle);
		}
		this.regions.put(regionName, region);
		return region;
	}

	private Region region(String regionName) {
		return this.regions.get(regionName);
	}

	private RegionFilter createFilter(final String... packageNames) throws InvalidSyntaxException {
		Collection<String> filters = new ArrayList<String>(packageNames.length);
		for (String pkg : packageNames) {
			filters.add('(' + RegionFilter.VISIBLE_PACKAGE_NAMESPACE + '=' + pkg + ')');
		}
		RegionFilterBuilder builder = digraph.createRegionFilterBuilder();
		for (String filter : filters) {
			builder.allow(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, filter);
		}
		return builder.build();
	}

	private RegionFilter createBundleFilter(String bundleSymbolicName, Version bundleVersion) throws InvalidSyntaxException {
		String bundleFilter = "(&(" + RegionFilter.VISIBLE_BUNDLE_NAMESPACE + '=' + bundleSymbolicName + ')' + '(' + Constants.BUNDLE_VERSION_ATTRIBUTE + ">=" + (bundleVersion == null ? "0" : bundleVersion.toString()) + "))";
		RegionFilterBuilder builder = digraph.createRegionFilterBuilder();
		return builder.allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, bundleFilter).build();
	}

	private Bundle createBundle(String bundleSymbolicName) {
		Bundle stubBundle = new StubBundle(this.bundleId++, bundleSymbolicName, BUNDLE_VERSION, "loc:" + bundleSymbolicName);
		this.bundles.put(bundleSymbolicName, stubBundle);
		return stubBundle;
	}

	BundleRequirement bundleRequirement(String bundleSymbolicName) {
		return new StubBundleRequirement(bundle(bundleSymbolicName));
	}

	Bundle bundle(String bundleSymbolicName) {
		Bundle bundleA = this.bundles.get(bundleSymbolicName);
		return bundleA;
	}

	final class StubPackageCapability implements BundleCapability {

		private final String bundleSymbolicName;

		private final String packageName;

		StubPackageCapability(String bundleSymbolicName, String packageName) {
			this.bundleSymbolicName = bundleSymbolicName;
			this.packageName = packageName;
		}

		@Override
		public String getNamespace() {
			return BundleRevision.PACKAGE_NAMESPACE;
		}

		@Override
		public Map<String, String> getDirectives() {
			return new HashMap<String, String>();
		}

		@Override
		public Map<String, Object> getAttributes() {
			HashMap<String, Object> attributes = new HashMap<String, Object>();
			attributes.put(BundleRevision.PACKAGE_NAMESPACE, this.packageName);
			return attributes;
		}

		@Override
		public BundleRevision getResource() {
			return getRevision();
		}

		@Override
		public BundleRevision getRevision() {
			return new StubBundleRevision(bundle(this.bundleSymbolicName));
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + (this.bundleSymbolicName == null ? 0 : this.bundleSymbolicName.hashCode());
			result = prime * result + (this.packageName == null ? 0 : this.packageName.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (!(obj instanceof StubPackageCapability)) {
				return false;
			}
			StubPackageCapability other = (StubPackageCapability) obj;
			if (!getOuterType().equals(other.getOuterType())) {
				return false;
			}
			if (this.bundleSymbolicName == null) {
				if (other.bundleSymbolicName != null) {
					return false;
				}
			} else if (!this.bundleSymbolicName.equals(other.bundleSymbolicName)) {
				return false;
			}
			if (this.packageName == null) {
				if (other.packageName != null) {
					return false;
				}
			} else if (!this.packageName.equals(other.packageName)) {
				return false;
			}
			return true;
		}

		private RegionResolverHookTests getOuterType() {
			return RegionResolverHookTests.this;
		}

	}

	final class StubBundleCapability implements BundleCapability {

		private final String bundleSymbolicName;

		StubBundleCapability(String bundleSymbolicName) {
			this.bundleSymbolicName = bundleSymbolicName;
		}

		@Override
		public String getNamespace() {
			return BundleRevision.BUNDLE_NAMESPACE;
		}

		@Override
		public Map<String, String> getDirectives() {
			return new HashMap<String, String>();
		}

		@Override
		public Map<String, Object> getAttributes() {
			HashMap<String, Object> attributes = new HashMap<String, Object>();
			attributes.put(BundleRevision.BUNDLE_NAMESPACE, bundleSymbolicName);
			return attributes;
		}

		@Override
		public BundleRevision getResource() {
			return getRevision();
		}

		@Override
		public BundleRevision getRevision() {
			return new StubBundleRevision(bundle(this.bundleSymbolicName));
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + ((bundleSymbolicName == null) ? 0 : bundleSymbolicName.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (!(obj instanceof StubBundleCapability))
				return false;
			StubBundleCapability other = (StubBundleCapability) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (bundleSymbolicName == null) {
				if (other.bundleSymbolicName != null)
					return false;
			} else if (!bundleSymbolicName.equals(other.bundleSymbolicName))
				return false;
			return true;
		}

		private RegionResolverHookTests getOuterType() {
			return RegionResolverHookTests.this;
		}

	}

	final class StubBundleRequirement implements BundleRequirement {

		private final StubBundleRevision bundleRevision;

		StubBundleRequirement(Bundle bundle) {
			this.bundleRevision = new StubBundleRevision(bundle);
		}

		@Override
		public String getNamespace() {
			throw new UnsupportedOperationException();
		}

		@Override
		public Map<String, String> getDirectives() {
			throw new UnsupportedOperationException();
		}

		@Override
		public Map<String, Object> getAttributes() {
			throw new UnsupportedOperationException();
		}

		@Override
		public BundleRevision getResource() {
			return getRevision();
		}

		@Override
		public BundleRevision getRevision() {
			return this.bundleRevision;
		}

		@Override
		public boolean matches(BundleCapability capability) {
			throw new UnsupportedOperationException();
		}
	}

	final class StubBundleRevision implements BundleRevision {

		private final Bundle bundle;

		StubBundleRevision(Bundle bundle) {
			this.bundle = bundle;
		}

		@Override
		public Bundle getBundle() {
			return this.bundle;
		}

		@Override
		public String getSymbolicName() {
			return this.bundle.getSymbolicName();
		}

		@Override
		public Version getVersion() {
			return this.bundle.getVersion();
		}

		@Override
		public List<BundleCapability> getDeclaredCapabilities(String namespace) {
			throw new UnsupportedOperationException();
		}

		@Override
		public int getTypes() {
			throw new UnsupportedOperationException();
		}

		@Override
		public List<BundleRequirement> getDeclaredRequirements(String namespace) {
			throw new UnsupportedOperationException();
		}

		@Override
		public BundleWiring getWiring() {
			throw new UnsupportedOperationException();
		}

		@SuppressWarnings({"cast", "unchecked", "rawtypes"})
		@Override
		public List<Capability> getCapabilities(String namespace) {
			return (List<Capability>) (List) getDeclaredCapabilities(namespace);
		}

		@SuppressWarnings({"cast", "unchecked", "rawtypes"})
		@Override
		public List<Requirement> getRequirements(String namespace) {
			return (List<Requirement>) (List) getDeclaredRequirements(namespace);
		}
	}

}

Back to the top