Search in sources :

Example 6 with TestDownloadManager

use of org.apache.karaf.features.internal.support.TestDownloadManager in project karaf by apache.

the class SubsystemTest method testFeatureOptional.

@Test
public void testFeatureOptional() throws Exception {
    RepositoryImpl repo = new RepositoryImpl(getClass().getResource("data5/features.xml").toURI());
    Map<String, Set<String>> features = new HashMap<>();
    addToMapSet(features, "root", "f1");
    Map<String, Set<String>> expected = new HashMap<>();
    addToMapSet(expected, "root", "a/1.0.0");
    addToMapSet(expected, "root", "b/1.0.0");
    SubsystemResolver resolver = new SubsystemResolver(this.resolver, new TestDownloadManager(getClass(), "data5"));
    resolver.prepare(Arrays.asList(repo.getFeatures()), features, Collections.emptyMap());
    resolver.resolve(Collections.emptySet(), FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE, null, null, null);
    verify(resolver, expected);
}
Also used : Set(java.util.Set) MapUtils.addToMapSet(org.apache.karaf.features.internal.util.MapUtils.addToMapSet) HashMap(java.util.HashMap) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) Test(org.junit.Test)

Example 7 with TestDownloadManager

use of org.apache.karaf.features.internal.support.TestDownloadManager in project karaf by apache.

the class SubsystemTest method testFeatureOptionalAlreadyProvided.

@Test
public void testFeatureOptionalAlreadyProvided() throws Exception {
    RepositoryImpl repo = new RepositoryImpl(getClass().getResource("data5/features.xml").toURI());
    Map<String, Set<String>> features = new HashMap<>();
    addToMapSet(features, "root", "f1");
    addToMapSet(features, "root", "f3");
    Map<String, Set<String>> expected = new HashMap<>();
    addToMapSet(expected, "root", "a/1.0.0");
    addToMapSet(expected, "root", "c/1.0.0");
    SubsystemResolver resolver = new SubsystemResolver(this.resolver, new TestDownloadManager(getClass(), "data5"));
    resolver.prepare(Arrays.asList(repo.getFeatures()), features, Collections.emptyMap());
    resolver.resolve(Collections.emptySet(), FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE, null, null, null);
    verify(resolver, expected);
}
Also used : Set(java.util.Set) MapUtils.addToMapSet(org.apache.karaf.features.internal.util.MapUtils.addToMapSet) HashMap(java.util.HashMap) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) Test(org.junit.Test)

Example 8 with TestDownloadManager

use of org.apache.karaf.features.internal.support.TestDownloadManager in project karaf by apache.

the class SubsystemTest method testConditionalSatisfiedWithOptional.

@Test
public void testConditionalSatisfiedWithOptional() throws Exception {
    RepositoryImpl repo = new RepositoryImpl(getClass().getResource("data4/features.xml").toURI());
    Map<String, Set<String>> features = new HashMap<>();
    addToMapSet(features, "root/apps1", "f1");
    addToMapSet(features, "root/apps1", "f2");
    Map<String, Set<String>> expected = new HashMap<>();
    addToMapSet(expected, "root/apps1", "a/1.0.0");
    addToMapSet(expected, "root/apps1", "b/1.0.0");
    SubsystemResolver resolver = new SubsystemResolver(this.resolver, new TestDownloadManager(getClass(), "data4"));
    resolver.prepare(Arrays.asList(repo.getFeatures()), features, Collections.emptyMap());
    resolver.resolve(Collections.emptySet(), FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE, null, null, null);
    verify(resolver, expected);
}
Also used : Set(java.util.Set) MapUtils.addToMapSet(org.apache.karaf.features.internal.util.MapUtils.addToMapSet) HashMap(java.util.HashMap) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) Test(org.junit.Test)

Example 9 with TestDownloadManager

use of org.apache.karaf.features.internal.support.TestDownloadManager in project karaf by apache.

the class DeployerTest method testInstallSimpleFeature.

@Test
public void testInstallSimpleFeature() throws Exception {
    IMocksControl c = EasyMock.createControl();
    String dataDir = "data1";
    TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
    RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
    repo.load(true);
    Feature f100 = repo.getFeatures()[0];
    Feature f101 = repo.getFeatures()[1];
    Deployer.DeployCallback callback = c.createMock(Deployer.DeployCallback.class);
    BundleInstallSupport installSupport = c.createMock(BundleInstallSupportImpl.class);
    Deployer deployer = new Deployer(manager, resolver, installSupport, callback);
    callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
    EasyMock.expectLastCall().anyTimes();
    callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
    EasyMock.expectLastCall();
    installSupport.replaceDigraph(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.saveState(EasyMock.anyObject());
    EasyMock.expectLastCall();
    installSupport.installConfigs(f100);
    EasyMock.expectLastCall();
    installSupport.installLibraries(f100);
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
    EasyMock.expectLastCall();
    installSupport.resolveBundles(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
    EasyMock.expectLastCall();
    callback.callListeners(EasyMock.<FeatureEvent>anyObject());
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
    EasyMock.expectLastCall();
    Bundle bundleA = createTestBundle(1, Bundle.ACTIVE, dataDir, "a100");
    EasyMock.expect(installSupport.installBundle(EasyMock.eq(ROOT_REGION), EasyMock.eq("a100"), EasyMock.anyObject())).andReturn(bundleA);
    c.replay();
    Deployer.DeploymentState dstate = new Deployer.DeploymentState();
    dstate.state = new State();
    dstate.bundles = new HashMap<>();
    dstate.bundlesPerRegion = new HashMap<>();
    dstate.features = new HashMap<>();
    dstate.features.put(f100.getId(), f100);
    dstate.features.put(f101.getId(), f101);
    dstate.filtersPerRegion = new HashMap<>();
    dstate.filtersPerRegion.put(ROOT_REGION, new HashMap<>());
    Deployer.DeploymentRequest request = new Deployer.DeploymentRequest();
    request.bundleUpdateRange = DEFAULT_BUNDLE_UPDATE_RANGE;
    request.featureResolutionRange = DEFAULT_FEATURE_RESOLUTION_RANGE;
    request.globalRepository = null;
    request.options = EnumSet.noneOf(Option.class);
    request.overrides = Collections.emptySet();
    request.stateChanges = Collections.emptyMap();
    request.updateSnaphots = UPDATE_SNAPSHOTS_NONE;
    request.requirements = new HashMap<>();
    addToMapSet(request.requirements, ROOT_REGION, f100.getName() + "/" + new VersionRange(f100.getVersion(), true));
    deployer.deploy(dstate, request);
    c.verify();
}
Also used : Bundle(org.osgi.framework.Bundle) TestBundle(org.apache.karaf.features.internal.support.TestBundle) VersionRange(org.apache.felix.utils.version.VersionRange) Feature(org.apache.karaf.features.Feature) IMocksControl(org.easymock.IMocksControl) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) Test(org.junit.Test)

Example 10 with TestDownloadManager

use of org.apache.karaf.features.internal.support.TestDownloadManager in project karaf by apache.

the class SubsystemTest method test1.

@Test
public void test1() throws Exception {
    RepositoryImpl repo = new RepositoryImpl(getClass().getResource("data1/features.xml").toURI());
    Map<String, Set<String>> features = new HashMap<>();
    addToMapSet(features, "root", "f1");
    addToMapSet(features, "root/apps1", "f2");
    Map<String, Set<String>> expected = new HashMap<>();
    addToMapSet(expected, "root", "a/1.0.0");
    addToMapSet(expected, "root", "c/1.0.0");
    addToMapSet(expected, "root/apps1", "b/1.0.0");
    SubsystemResolver resolver = new SubsystemResolver(this.resolver, new TestDownloadManager(getClass(), "data1"));
    resolver.prepare(Arrays.asList(repo.getFeatures()), features, Collections.emptyMap());
    resolver.resolve(Collections.emptySet(), FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE, null, null, null);
    verify(resolver, expected);
}
Also used : Set(java.util.Set) MapUtils.addToMapSet(org.apache.karaf.features.internal.util.MapUtils.addToMapSet) HashMap(java.util.HashMap) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) Test(org.junit.Test)

Aggregations

TestDownloadManager (org.apache.karaf.features.internal.support.TestDownloadManager)17 Test (org.junit.Test)15 HashMap (java.util.HashMap)13 Set (java.util.Set)13 MapUtils.addToMapSet (org.apache.karaf.features.internal.util.MapUtils.addToMapSet)13 RepositoryImpl (org.apache.karaf.features.internal.service.RepositoryImpl)12 Feature (org.apache.karaf.features.Feature)6 TestBundle (org.apache.karaf.features.internal.support.TestBundle)5 IMocksControl (org.easymock.IMocksControl)5 Bundle (org.osgi.framework.Bundle)4 VersionRange (org.apache.felix.utils.version.VersionRange)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 Manifest (java.util.jar.Manifest)1