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
|
/*******************************************************************************
* Copyright (c) 2011, 2013 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;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.easymock.EasyMock;
import org.eclipse.equinox.region.Region;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.BundleException;
public class StandardBundleIdToRegionMappingTests {
private Object bundleIdToRegionMapping;
private Region mockRegion;
private static final long TEST_BUNDLE_ID = 1L;
private static final long OTHER_TEST_BUNDLE_ID = 2L;
@Before
public void setUp() throws Exception {
this.bundleIdToRegionMapping = RegionReflectionUtils.newStandardBundleIdToRegionMapping();
this.mockRegion = EasyMock.createMock(Region.class);
}
@Test
public void testAssociateBundleWithRegion() {
assertNull(RegionReflectionUtils.getRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID));
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
assertEquals(mockRegion, RegionReflectionUtils.getRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID));
}
@Test
public void testAssociateBundleAlreadyAssociatedWithRegion() {
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
}
@Test(expected = BundleException.class)
public void testAssociateBundleAlreadyAssociatedWithOtherRegion() {
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, EasyMock.createMock(Region.class));
}
@Test
public void testDissociateBundle() {
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
RegionReflectionUtils.dissociateBundleFromRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
assertNull(RegionReflectionUtils.getRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID));
}
@Test
public void testIsBundleAssociatedWithRegion() {
assertFalse(RegionReflectionUtils.isBundleAssociatedWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion));
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
assertFalse(RegionReflectionUtils.isBundleAssociatedWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion));
}
@Test
public void testGetBundleIds() {
assertEquals(0, RegionReflectionUtils.getBundleIds(this.bundleIdToRegionMapping, mockRegion).size());
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, OTHER_TEST_BUNDLE_ID, mockRegion);
assertEquals(2, RegionReflectionUtils.getBundleIds(this.bundleIdToRegionMapping, mockRegion).size());
assertTrue(RegionReflectionUtils.getBundleIds(this.bundleIdToRegionMapping, mockRegion).contains(TEST_BUNDLE_ID));
assertTrue(RegionReflectionUtils.getBundleIds(this.bundleIdToRegionMapping, mockRegion).contains(OTHER_TEST_BUNDLE_ID));
}
@Test
public void testClear() {
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
RegionReflectionUtils.clear(this.bundleIdToRegionMapping);
assertNull(RegionReflectionUtils.getRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID));
}
@Test
public void testGetRegion() {
assertNull(RegionReflectionUtils.getRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID));
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion);
RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, OTHER_TEST_BUNDLE_ID, mockRegion);
assertNull(RegionReflectionUtils.getRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID));
assertNull(RegionReflectionUtils.getRegion(this.bundleIdToRegionMapping, OTHER_TEST_BUNDLE_ID));
}
}
|