Search in sources :

Example 6 with IMocksControl

use of org.easymock.IMocksControl in project karaf by apache.

the class DeployerTest method testUpdateSimpleFeature.

@Test
public void testUpdateSimpleFeature() throws Exception {
    IMocksControl c = EasyMock.createControl();
    final 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);
    final TestBundle bundleA = createTestBundle(1L, Bundle.ACTIVE, dataDir, "a100");
    callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
    EasyMock.expectLastCall().anyTimes();
    callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
    EasyMock.expectLastCall();
    installSupport.stopBundle(EasyMock.eq(bundleA), anyInt());
    EasyMock.expectLastCall().andStubAnswer(() -> {
        bundleA.state = Bundle.RESOLVED;
        return null;
    });
    installSupport.updateBundle(EasyMock.eq(bundleA), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            URL loc = getClass().getResource(dataDir + "/" + "a101" + ".mf");
            Manifest man = new Manifest(loc.openStream());
            Hashtable<String, String> headers = new Hashtable<>();
            for (Map.Entry<Object, Object> attr : man.getMainAttributes().entrySet()) {
                headers.put(attr.getKey().toString(), attr.getValue().toString());
            }
            bundleA.update(headers);
            return null;
        }
    });
    installSupport.startBundle(EasyMock.eq(bundleA));
    EasyMock.expectLastCall();
    installSupport.replaceDigraph(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.saveState(EasyMock.anyObject());
    EasyMock.expectLastCall();
    installSupport.installConfigs(f101);
    EasyMock.expectLastCall();
    installSupport.installLibraries(f101);
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
    EasyMock.expectLastCall();
    installSupport.resolveBundles(EasyMock.eq(Collections.singleton(bundleA)), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
    EasyMock.expectLastCall();
    installSupport.refreshPackages(EasyMock.eq(Collections.singleton(bundleA)));
    EasyMock.expectLastCall();
    callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureUninstalled, f100, FeaturesService.ROOT_REGION, false)));
    EasyMock.expectLastCall();
    callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled, f101, FeaturesService.ROOT_REGION, false)));
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
    EasyMock.expectLastCall();
    c.replay();
    Deployer.DeploymentState dstate = new Deployer.DeploymentState();
    dstate.state = new State();
    addToMapSet(dstate.state.installedFeatures, ROOT_REGION, f100.getId());
    addToMapSet(dstate.state.managedBundles, ROOT_REGION, 1L);
    dstate.bundles = new HashMap<>();
    dstate.bundles.put(1L, bundleA);
    dstate.bundlesPerRegion = new HashMap<>();
    addToMapSet(dstate.bundlesPerRegion, ROOT_REGION, 1L);
    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, f101.getName() + "/" + new VersionRange(f101.getVersion(), true));
    deployer.deploy(dstate, request);
    c.verify();
}
Also used : TestBundle(org.apache.karaf.features.internal.support.TestBundle) VersionRange(org.apache.felix.utils.version.VersionRange) Feature(org.apache.karaf.features.Feature) URL(java.net.URL) IMocksControl(org.easymock.IMocksControl) FeatureEvent(org.apache.karaf.features.FeatureEvent) Hashtable(java.util.Hashtable) Manifest(java.util.jar.Manifest) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Test(org.junit.Test)

Example 7 with IMocksControl

use of org.easymock.IMocksControl in project karaf by apache.

the class DeployerTest method doTestPrereqOnPrereq.

@SuppressWarnings("unchecked")
private void doTestPrereqOnPrereq(int scenario) throws Exception {
    IMocksControl c = EasyMock.createControl();
    String dataDir = "data3";
    TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
    RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
    repo.load(true);
    Map<String, Bundle> bundles = new HashMap<>();
    bundles.put("a100", createTestBundle(1, Bundle.ACTIVE, dataDir, "a100"));
    bundles.put("b100", createTestBundle(2, Bundle.ACTIVE, dataDir, "b100"));
    bundles.put("c100", createTestBundle(3, Bundle.ACTIVE, dataDir, "c100"));
    Deployer.DeploymentState dstate = new Deployer.DeploymentState();
    dstate.state = new State();
    dstate.bundles = new HashMap<>();
    dstate.bundlesPerRegion = new HashMap<>();
    dstate.features = new HashMap<>();
    for (Feature f : repo.getFeatures()) {
        dstate.features.put(f.getId(), f);
    }
    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;
    MyDeployCallback callback = new MyDeployCallback(dstate);
    BundleInstallSupport installSupport = c.createMock(BundleInstallSupportImpl.class);
    Capture<String> capture = Capture.newInstance();
    installSupport.installBundle(EasyMock.anyString(), EasyMock.capture(capture), anyObject(InputStream.class));
    EasyMock.expectLastCall().andAnswer(() -> bundles.get(capture.getValue())).atLeastOnce();
    installSupport.installConfigs(EasyMock.anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    installSupport.installLibraries(EasyMock.anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    installSupport.replaceDigraph(EasyMock.anyObject(), EasyMock.anyObject());
    expectLastCall().atLeastOnce();
    installSupport.resolveBundles(anyObject(Set.class), anyObject(Map.class), anyObject(Map.class));
    expectLastCall().atLeastOnce();
    Deployer deployer = new Deployer(manager, resolver, installSupport, callback);
    c.replay();
    for (int i = 1; i <= 4; i++) {
        request.requirements = new HashMap<>();
        addToMapSet(request.requirements, ROOT_REGION, "demo-" + scenario + "-c");
        Set<String> prereqs = new HashSet<>();
        while (true) {
            try {
                deployer.deploy(callback.dstate, request);
                break;
            } catch (Deployer.PartialDeploymentException e) {
                if (!prereqs.containsAll(e.getMissing())) {
                    prereqs.addAll(e.getMissing());
                } else {
                    throw new Exception("Deployment aborted due to loop in missing prerequisites: " + e.getMissing());
                }
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) Set(java.util.Set) MapUtils.addToMapSet(org.apache.karaf.features.internal.util.MapUtils.addToMapSet) HashMap(java.util.HashMap) Feature(org.apache.karaf.features.Feature) IMocksControl(org.easymock.IMocksControl) HashSet(java.util.HashSet) Bundle(org.osgi.framework.Bundle) TestBundle(org.apache.karaf.features.internal.support.TestBundle) InputStream(java.io.InputStream) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with IMocksControl

use of org.easymock.IMocksControl in project karaf by apache.

the class DeployerTest method testPrerequisite.

@Test
public void testPrerequisite() throws Exception {
    IMocksControl c = EasyMock.createControl();
    String dataDir = "data2";
    TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
    RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
    repo.load(true);
    Feature f1 = repo.getFeatures()[0];
    Feature f2 = repo.getFeatures()[1];
    Bundle serviceBundle1 = createTestBundle(1, Bundle.ACTIVE, dataDir, "a100");
    Bundle serviceBundle2 = createTestBundle(2, Bundle.ACTIVE, dataDir, "b100");
    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.installBundle(EasyMock.eq(ROOT_REGION), EasyMock.eq("a100"), EasyMock.anyObject());
    EasyMock.expectLastCall().andReturn(serviceBundle1);
    installSupport.replaceDigraph(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.saveState(EasyMock.anyObject());
    EasyMock.expectLastCall();
    installSupport.installConfigs(EasyMock.anyObject());
    EasyMock.expectLastCall();
    installSupport.installLibraries(EasyMock.anyObject());
    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();
    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(f1.getId(), f1);
    dstate.features.put(f2.getId(), f2);
    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, f2.getName());
    try {
        deployer.deploy(dstate, request);
        fail("Should have thrown an exception");
    } catch (Deployer.PartialDeploymentException e) {
    // ok
    }
    c.verify();
    c.reset();
    callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
    EasyMock.expectLastCall().anyTimes();
    callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
    EasyMock.expectLastCall();
    installSupport.installBundle(EasyMock.eq(ROOT_REGION), EasyMock.eq("b100"), EasyMock.anyObject());
    EasyMock.expectLastCall().andReturn(serviceBundle2);
    installSupport.replaceDigraph(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.saveState(EasyMock.anyObject());
    EasyMock.expectLastCall();
    installSupport.installConfigs(f2);
    EasyMock.expectLastCall();
    installSupport.installLibraries(f2);
    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();
    EasyMock.replay(callback);
    dstate = new Deployer.DeploymentState();
    dstate.state = new State();
    addToMapSet(dstate.state.installedFeatures, ROOT_REGION, f1.getId());
    dstate.state.stateFeatures.put(ROOT_REGION, Collections.singletonMap(f1.getId(), "Started"));
    addToMapSet(dstate.state.managedBundles, ROOT_REGION, serviceBundle1.getBundleId());
    dstate.bundles = new HashMap<>();
    dstate.bundles.put(serviceBundle1.getBundleId(), serviceBundle1);
    dstate.bundlesPerRegion = new HashMap<>();
    addToMapSet(dstate.bundlesPerRegion, ROOT_REGION, serviceBundle1.getBundleId());
    dstate.features = new HashMap<>();
    dstate.features.put(f1.getId(), f1);
    dstate.features.put(f2.getId(), f2);
    dstate.filtersPerRegion = new HashMap<>();
    dstate.filtersPerRegion.put(ROOT_REGION, new HashMap<>());
    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, f2.getName());
    deployer.deploy(dstate, request);
    EasyMock.verify(callback);
}
Also used : Bundle(org.osgi.framework.Bundle) TestBundle(org.apache.karaf.features.internal.support.TestBundle) Feature(org.apache.karaf.features.Feature) IMocksControl(org.easymock.IMocksControl) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) Test(org.junit.Test)

Example 9 with IMocksControl

use of org.easymock.IMocksControl in project karaf by apache.

the class DeployerTest method testUpdateServiceBundle.

@Test
public void testUpdateServiceBundle() 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 f1 = repo.getFeatures()[0];
    Bundle serviceBundle = createTestBundle(1, Bundle.ACTIVE, dataDir, "a100");
    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();
    callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
    EasyMock.expectLastCall();
    installSupport.installConfigs(f1);
    EasyMock.expectLastCall();
    installSupport.installLibraries(f1);
    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();
    c.replay();
    Deployer.DeploymentState dstate = new Deployer.DeploymentState();
    dstate.state = new State();
    dstate.bundles = new HashMap<>();
    dstate.bundles.put(serviceBundle.getBundleId(), serviceBundle);
    dstate.bundlesPerRegion = new HashMap<>();
    addToMapSet(dstate.bundlesPerRegion, ROOT_REGION, serviceBundle.getBundleId());
    dstate.features = Collections.singletonMap(f1.getId(), f1);
    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, f1.getName());
    deployer.deploy(dstate, request);
    c.verify();
}
Also used : Bundle(org.osgi.framework.Bundle) TestBundle(org.apache.karaf.features.internal.support.TestBundle) 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 IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class CXFBusLifeCycleManagerTest method testMultipleListeners.

@Test
public void testMultipleListeners() {
    IMocksControl ctrl = EasyMock.createStrictControl();
    BusLifeCycleListener listener1 = ctrl.createMock(BusLifeCycleListener.class);
    BusLifeCycleListener listener2 = ctrl.createMock(BusLifeCycleListener.class);
    CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
    mgr.registerLifeCycleListener(listener1);
    mgr.registerLifeCycleListener(listener2);
    ctrl.reset();
    listener1.initComplete();
    listener2.initComplete();
    ctrl.replay();
    mgr.initComplete();
    ctrl.verify();
    ctrl.reset();
    listener2.preShutdown();
    listener1.preShutdown();
    ctrl.replay();
    mgr.preShutdown();
    ctrl.verify();
    ctrl.reset();
    listener2.postShutdown();
    listener1.postShutdown();
    ctrl.replay();
    mgr.postShutdown();
    ctrl.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) CXFBusLifeCycleManager(org.apache.cxf.bus.managers.CXFBusLifeCycleManager) Test(org.junit.Test)

Aggregations

IMocksControl (org.easymock.IMocksControl)57 Test (org.junit.Test)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Message (org.apache.cxf.message.Message)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 MessageImpl (org.apache.cxf.message.MessageImpl)9 QName (javax.xml.namespace.QName)7 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)7 Before (org.junit.Before)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Exchange (org.apache.cxf.message.Exchange)6 FakeHttpServletRequest (com.google.gerrit.util.http.testutil.FakeHttpServletRequest)5 FakeHttpServletResponse (com.google.gerrit.util.http.testutil.FakeHttpServletResponse)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Binding (javax.xml.ws.Binding)5 Handler (javax.xml.ws.handler.Handler)5 MessageContext (javax.xml.ws.handler.MessageContext)5