blob: cf3d1cef5f8c4dbce6d2400ff05cb029485802d5 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.core.config;
import com.yahoo.osgi.MockOsgi;
import org.osgi.framework.Bundle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* @author gjoranv
*/
class TestOsgi extends MockOsgi {
private final Map<String, Bundle> availableBundles;
private final List<Bundle> installedBundles = new ArrayList<>();
private final List<Bundle> allowedDuplicates = new ArrayList<>();
TestOsgi(Map<String, Bundle> availableBundles) {
this.availableBundles = availableBundles;
}
@Override
public List<Bundle> install(String fileReferenceValue) {
if (! availableBundles.containsKey(fileReferenceValue))
throw new IllegalArgumentException("No such bundle: " + fileReferenceValue);
Bundle bundle = availableBundles.get(fileReferenceValue);
installedBundles.add(bundle);
return List.of(bundle);
}
@Override
public Bundle[] getBundles() {
return installedBundles.toArray(new Bundle[0]);
}
public List<Bundle> getInstalledBundles() {
return installedBundles;
}
@Override
public List<Bundle> getCurrentBundles() {
var currentBundles = new ArrayList<>(installedBundles);
currentBundles.removeAll(allowedDuplicates);
return currentBundles;
}
@Override
public void allowDuplicateBundles(Collection<Bundle> bundles) {
allowedDuplicates.clear();
allowedDuplicates.addAll(bundles);
}
}
|