Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 303b4eb39ab4664b28eb1a3bf2189ffd974f5b93 (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
/*******************************************************************************
 * Copyright (c) 2009, 2010 VMware Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution. 
 * The Eclipse Public License is available at
 *   http://www.eclipse.org/legal/epl-v10.html
 * and the Apache License v2.0 is available at 
 *   http://www.opensource.org/licenses/apache2.0.php.
 * You may elect to redistribute this code under either of these licenses.  
 *
 * Contributors:
 *   VMware Inc. - initial contribution
 *******************************************************************************/

package org.eclipse.gemini.web.internal;

import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.virgo.util.osgi.VersionRange;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Version;
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRevision;

public class SystemBundleExportsResolverTests {

    private BundleCapability capability1;

    private BundleCapability capability2;

    private BundleCapability capability3;

    private List<BundleCapability> input;

    @Before
    public void setUp() {
        this.capability1 = createMock(BundleCapability.class);
        this.capability2 = createMock(BundleCapability.class);
        this.capability3 = createMock(BundleCapability.class);
        this.input = new ArrayList<BundleCapability>();
        this.input.add(this.capability1);
        this.input.add(this.capability2);
    }

    @Test
    public void basic() {
        Map<String, Object> attributes1 = new HashMap<String, Object>();
        attributes1.put(BundleRevision.PACKAGE_NAMESPACE, "a");
        attributes1.put(SystemBundleExportsResolver.VERSION, new Version(1, 2, 3));
        expect(this.capability1.getAttributes()).andReturn(attributes1).times(2);

        Map<String, Object> attributes2 = new HashMap<String, Object>();
        attributes2.put(BundleRevision.PACKAGE_NAMESPACE, "b");
        attributes2.put(SystemBundleExportsResolver.VERSION, new Version(2, 3, 4));
        expect(this.capability2.getAttributes()).andReturn(attributes2).times(2);

        replay(this.capability1, this.capability2);

        Map<String, VersionRange> output = SystemBundleExportsResolver.combineDuplicateExports(this.input, false);

        assertEquals(2, output.size());
        assertEquals(new VersionRange("[1.2.3,1.2.3]"), output.get("a"));
        assertEquals(new VersionRange("[2.3.4,2.3.4]"), output.get("b"));

        verify(this.capability1, this.capability2);
    }

    @Test
    public void downwardExpansion() {
        Map<String, Object> attributes1 = new HashMap<String, Object>();
        attributes1.put(BundleRevision.PACKAGE_NAMESPACE, "a");
        attributes1.put(SystemBundleExportsResolver.VERSION, new Version(2, 0, 0));
        expect(this.capability1.getAttributes()).andReturn(attributes1).times(2);

        Map<String, Object> attributes2 = new HashMap<String, Object>();
        attributes2.put(BundleRevision.PACKAGE_NAMESPACE, "a");
        attributes2.put(SystemBundleExportsResolver.VERSION, new Version(1, 0, 0));
        expect(this.capability2.getAttributes()).andReturn(attributes2).times(2);

        replay(this.capability1, this.capability2);

        Map<String, VersionRange> output = SystemBundleExportsResolver.combineDuplicateExports(this.input, false);

        assertEquals(1, output.size());
        assertEquals(new VersionRange("[1.0.0,2.0.0]"), output.get("a"));

        verify(this.capability1, this.capability2);
    }

    @Test
    public void upwardExpansion() {
        Map<String, Object> attributes1 = new HashMap<String, Object>();
        attributes1.put(BundleRevision.PACKAGE_NAMESPACE, "a");
        attributes1.put(SystemBundleExportsResolver.VERSION, new Version(1, 0, 0));
        expect(this.capability1.getAttributes()).andReturn(attributes1).times(2);

        Map<String, Object> attributes2 = new HashMap<String, Object>();
        attributes2.put(BundleRevision.PACKAGE_NAMESPACE, "a");
        attributes2.put(SystemBundleExportsResolver.VERSION, new Version(2, 0, 0));
        expect(this.capability2.getAttributes()).andReturn(attributes2).times(2);

        replay(this.capability1, this.capability2);

        Map<String, VersionRange> output = SystemBundleExportsResolver.combineDuplicateExports(this.input, false);

        assertEquals(1, output.size());
        assertEquals(new VersionRange("[1.0.0,2.0.0]"), output.get("a"));

        verify(this.capability1, this.capability2);
    }

    @Test
    public void expansionInBothDirections() {
        Map<String, Object> attributes1 = new HashMap<String, Object>();
        attributes1.put(BundleRevision.PACKAGE_NAMESPACE, "a");
        attributes1.put(SystemBundleExportsResolver.VERSION, new Version(2, 0, 0));
        expect(this.capability1.getAttributes()).andReturn(attributes1).times(2);

        Map<String, Object> attributes2 = new HashMap<String, Object>();
        attributes2.put(BundleRevision.PACKAGE_NAMESPACE, "a");
        attributes2.put(SystemBundleExportsResolver.VERSION, new Version(3, 0, 0));
        expect(this.capability2.getAttributes()).andReturn(attributes2).times(2);

        Map<String, Object> attributes3 = new HashMap<String, Object>();
        attributes3.put(BundleRevision.PACKAGE_NAMESPACE, "a");
        attributes3.put(SystemBundleExportsResolver.VERSION, new Version(1, 0, 0));
        expect(this.capability3.getAttributes()).andReturn(attributes3).times(2);

        this.input.add(this.capability3);

        replay(this.capability1, this.capability2, this.capability3);

        Map<String, VersionRange> output = SystemBundleExportsResolver.combineDuplicateExports(this.input, false);

        assertEquals(1, output.size());
        assertEquals(new VersionRange("[1.0.0,3.0.0]"), output.get("a"));

        verify(this.capability1, this.capability2, this.capability3);
    }
}

Back to the top