You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2017/08/14 08:43:58 UTC
[3/7] karaf git commit: Extract common code in test
Extract common code in test
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/e442a1b8
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/e442a1b8
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/e442a1b8
Branch: refs/heads/model_features
Commit: e442a1b8a93e4861116c8c518dba74473097b546
Parents: 0400c2d
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Wed Aug 9 15:51:45 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Mon Aug 14 09:53:39 2017 +0200
----------------------------------------------------------------------
.../service/FeaturesServiceImplTest.java | 62 +++++++++-----------
1 file changed, 28 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/e442a1b8/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
index 01ad34b..a5ec75a 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
@@ -73,32 +73,27 @@ public class FeaturesServiceImplTest extends TestBase {
field.setAccessible(true);
field.set(null, null);
}
+
+ @Test
+ public void testListFeatureWithoutVersion() throws Exception {
+ Feature transactionFeature = feature("transaction", "1.0.0");
+ FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature);
+ assertNotNull(impl.getFeatures("transaction", null));
+ assertSame(transactionFeature, impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)[0]);
+ }
@Test
public void testGetFeature() throws Exception {
Feature transactionFeature = feature("transaction", "1.0.0");
- final Map<String, Map<String, Feature>> features = features(transactionFeature);
- FeaturesServiceConfig cfg = new FeaturesServiceConfig();
- BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class);
- EasyMock.replay(installSupport);
- final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg ) {
- protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception {
- return features;
- }
- };
+ FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature);
assertNotNull(impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION));
assertSame(transactionFeature, impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)[0]);
}
@Test
public void testGetFeatureStripVersion() throws Exception {
- FeaturesServiceConfig cfg = new FeaturesServiceConfig();
- BundleInstallSupport installSupport = EasyMock.mock(BundleInstallSupport.class);
- final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) {
- protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception {
- return features(feature("transaction", "1.0.0"));
- }
- };
+ Feature transactionFeature = feature("transaction", "1.0.0");
+ FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature);
Feature[] features = impl.getFeatures("transaction", " 1.0.0 ");
assertEquals(1, features.length);
Feature feature = features[0];
@@ -108,29 +103,15 @@ public class FeaturesServiceImplTest extends TestBase {
@Test
public void testGetFeatureNotAvailable() throws Exception {
- FeaturesServiceConfig cfg = new FeaturesServiceConfig();
- BundleInstallSupport installSupport = EasyMock.mock(BundleInstallSupport.class);
- final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) {
- protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception {
- return features(feature("transaction", "1.0.0"));
- }
- };
+ Feature transactionFeature = feature("transaction", "1.0.0");
+ FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature);
assertEquals(0, impl.getFeatures("activemq", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION).length);
}
@Test
public void testGetFeatureHighestAvailable() throws Exception {
- final Map<String, Map<String, Feature>> features = features(
- feature("transaction", "1.0.0"),
- feature("transaction", "2.0.0")
- );
- FeaturesServiceConfig cfg = new FeaturesServiceConfig();
- BundleInstallSupport installSupport = EasyMock.mock(BundleInstallSupport.class);
- final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) {
- protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception {
- return features;
- }
- };
+ FeaturesServiceImpl impl = featuresServiceWithFeatures(feature("transaction", "1.0.0"),
+ feature("transaction", "2.0.0"));
assertNotNull(impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION));
assertEquals("2.0.0", impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)[0].getVersion());
}
@@ -175,6 +156,19 @@ public class FeaturesServiceImplTest extends TestBase {
assertInstalled(featureService, b1Feature);
}
+ private FeaturesServiceImpl featuresServiceWithFeatures(Feature... staticFeatures) {
+ final Map<String, Map<String, Feature>> features = features(staticFeatures);
+ FeaturesServiceConfig cfg = new FeaturesServiceConfig();
+ BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class);
+ EasyMock.replay(installSupport);
+ final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg ) {
+ protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception {
+ return features;
+ }
+ };
+ return impl;
+ }
+
private FeaturesServiceImpl createTestFeatureService() {
FeaturesServiceConfig cfg = new FeaturesServiceConfig();
BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class);