Package org.easymock.classextension

Examples of org.easymock.classextension.IMocksControl


        Map<String, Object> intents = new HashMap<String, Object>();
        intents.put("A", new AbstractFeature() {});
        final IntentMap intentMap = new IntentMap();
        intentMap.setIntents(intents);
               
        IMocksControl control = EasyMock.createNiceControl();
        BundleContext dswContext = control.createMock(BundleContext.class);
        BundleContext callingContext = control.createMock(BundleContext.class);       
        List<AbstractFeature> features = new ArrayList<AbstractFeature>();
        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
        control.replay();

        DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
            @Override
            IntentMap getIntentMap(BundleContext callingContext) {
View Full Code Here


        intents.put("A_alt", feat1);
        intents.put("B", new AbstractFeature() {});
        final IntentMap intentMap = new IntentMap();
        intentMap.setIntents(intents);
       
        IMocksControl control = EasyMock.createNiceControl();
        BundleContext dswContext = control.createMock(BundleContext.class);
        BundleContext callingContext = control.createMock(BundleContext.class);
        List<AbstractFeature> features = new ArrayList<AbstractFeature>();
        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
        control.replay();
       
        DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
            @Override
            IntentMap getIntentMap(BundleContext callingContext) {
View Full Code Here

        assertTrue(effectiveIntents.contains("A"));
        assertTrue(effectiveIntents.contains("A_alt"));
    }
   
    public void testDefaultBindingIntent() {       
        IMocksControl control = EasyMock.createNiceControl();

        Map<String, Object> intents = new HashMap<String, Object>();
        BindingConfiguration feat1 = control.createMock(BindingConfiguration.class);
        intents.put("A", new AbstractFeature() {});
        intents.put("SOAP", feat1);
        intents.put("SOAP.1_1", feat1);
        intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class));
        final IntentMap intentMap = new IntentMap();
        intentMap.setIntents(intents);

        BundleContext dswContext = control.createMock(BundleContext.class);
        BundleContext callingContext = control.createMock(BundleContext.class);
        List<AbstractFeature> features = new ArrayList<AbstractFeature>();
        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
        control.replay();
       
        DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
            @Override
            IntentMap getIntentMap(BundleContext callingContext) {
View Full Code Here

        assertTrue(effectiveIntents.contains("SOAP"));
        assertTrue(effectiveIntents.contains("SOAP.1_1"));
    }
   
    public void testExplicitBindingIntent() {
        IMocksControl control = EasyMock.createNiceControl();

        Map<String, Object> intents = new HashMap<String, Object>();
        BindingConfiguration feat1 = control.createMock(BindingConfiguration.class);
        intents.put("A", new AbstractFeature() {});
        intents.put("SOAP", feat1);
        intents.put("SOAP.1_1", feat1);
        intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class));
        final IntentMap intentMap = new IntentMap();
        intentMap.setIntents(intents);

        BundleContext dswContext = control.createMock(BundleContext.class);
        BundleContext callingContext = control.createMock(BundleContext.class);
        List<AbstractFeature> features = new ArrayList<AbstractFeature>();
        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
        control.replay();
       
        DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
            @Override
            IntentMap getIntentMap(BundleContext callingContext) {
View Full Code Here

        Map<String, Object> appIntents = new HashMap<String, Object>();
        appIntents.put("A", new TestFeature("appFeatureA"));
        final IntentMap appIntentMap = new IntentMap();
        appIntentMap.setIntents(appIntents);

        IMocksControl control = EasyMock.createNiceControl();
        final BundleContext dswContext = control.createMock(BundleContext.class);
        final BundleContext callingContext = control.createMock(BundleContext.class);       
        List<AbstractFeature> features = new ArrayList<AbstractFeature>();
        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
        control.replay();

        DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);

        Map<String, Object> props = new HashMap<String, Object>();
        props.put("osgi.remote.requires.intents", requestedIntents);
View Full Code Here

        final IntentMap masterIntentMap = new IntentMap();
        masterIntentMap.setIntents(masterIntents);       
        final IntentMap appIntentMap = new IntentMap();
        appIntentMap.setIntents(new HashMap<String, Object>());

        IMocksControl control = EasyMock.createNiceControl();
        final BundleContext dswContext = control.createMock(BundleContext.class);
        final BundleContext callingContext = control.createMock(BundleContext.class);       
        List<AbstractFeature> features = new ArrayList<AbstractFeature>();
        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
        control.replay();
       
        DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);

        Map<String, Object> props = new HashMap<String, Object>();
        props.put("osgi.remote.requires.intents", "B A");
View Full Code Here

        final Semaphore sema = new Semaphore(1);
        sema.acquire();
       
        String scope = "(objectClass=abc)";
    
        IMocksControl c = EasyMock.createNiceControl();
       
       
        BundleContext bctx = c.createMock(BundleContext.class);
       
        Bundle topMgrBundle = c.createMock(Bundle.class);
       
        RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
        final ServiceReference rsaSref = c.createMock(ServiceReference.class);
        EndpointListener epl = c.createMock(EndpointListener.class);
        final ServiceReference eplSref = c.createMock(ServiceReference.class);
        EasyMock.expect(eplSref.getProperty(EasyMock.same(EndpointListener.ENDPOINT_LISTENER_SCOPE)))
            .andReturn(scope).anyTimes();
        EasyMock.expect(eplSref.getBundle()).andReturn(topMgrBundle).anyTimes();

        final ServiceReference sref = c.createMock(ServiceReference.class);
        EasyMock.expect(sref.getProperty(EasyMock.same(RemoteConstants.SERVICE_EXPORTED_INTERFACES)))
            .andReturn("*").anyTimes();
        Bundle srefBundle = c.createMock(Bundle.class);
        EasyMock.expect(sref.getBundle()).andReturn(srefBundle).anyTimes();
       
       
        EndpointDescription endpoint = c.createMock(EndpointDescription.class);
        {
            Map props = new HashMap();
            String[] objs = new String[1];
            objs[0] = "abc";
            props.put("objectClass", objs);
            EasyMock.expect(endpoint.getProperties()).andReturn(props).anyTimes();
        }

        ExportRegistration exportRegistration = c.createMock(ExportRegistration.class);
        ExportReference exportReference = c.createMock(ExportReference.class);

        EasyMock.expect(exportRegistration.getExportReference()).andReturn(exportReference).anyTimes();
        EasyMock.expect(exportReference.getExportedEndpoint()).andReturn(endpoint).anyTimes();
        {
            List ret = new ArrayList();
            ret.add(exportRegistration);
            EasyMock.expect(rsa.exportService(EasyMock.same(sref), (Map)EasyMock.anyObject())).andReturn(ret)
                .once();
        }

        epl.endpointAdded((EndpointDescription)EasyMock.anyObject(), (String)EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            public Object answer() throws Throwable {
                System.out.println("Call made !!!");
                sema.release();
                return null;
            }
           
        }).once();

        {/* BCTX */

            bctx.addServiceListener((ServiceListener)EasyMock.anyObject(), (String)EasyMock.anyObject());
            EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

                public Object answer() throws Throwable {
                    System.out.println("->   addServiceListener: "
                                       + EasyMock.getCurrentArguments()[1]);
                    ServiceListener sl = (ServiceListener)EasyMock.getCurrentArguments()[0];

                    if ("(objectClass=org.osgi.service.remoteserviceadmin.RemoteServiceAdmin)"
                        .equals(EasyMock.getCurrentArguments()[1])) {
                        ServiceEvent se = new ServiceEvent(ServiceEvent.REGISTERED, rsaSref);
                        sl.serviceChanged(se);
                    } else if ("(objectClass=org.osgi.service.remoteserviceadmin.EndpointListener)"
                        .equals(EasyMock.getCurrentArguments()[1])) {
                        ServiceEvent se = new ServiceEvent(ServiceEvent.REGISTERED, eplSref);
                        sl.serviceChanged(se);
                    }

                    return null;
                }
            }).anyTimes();

            bctx.addServiceListener((ServiceListener)EasyMock.anyObject());
            EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

                public Object answer() throws Throwable {
                    System.out.println("->   addServiceListener ");

                    ServiceListener sl = (ServiceListener)EasyMock.getCurrentArguments()[0];

                    ServiceEvent se = new ServiceEvent(ServiceEvent.REGISTERED, sref);
                    sl.serviceChanged(se);
                    se = new ServiceEvent(ServiceEvent.REGISTERED, eplSref);
                    sl.serviceChanged(se);
                    se = new ServiceEvent(ServiceEvent.REGISTERED, rsaSref);
                    sl.serviceChanged(se);

                    return null;
                }
            }).anyTimes();

            EasyMock.expect(bctx.getService(EasyMock.same(rsaSref))).andReturn(rsa).anyTimes();
            EasyMock.expect(bctx.getService(EasyMock.same(eplSref))).andReturn(epl).atLeastOnce();

            {
                ServiceReference[] refs = new ServiceReference[1];
                refs[0] = eplSref;
                EasyMock
                    .expect(
                            bctx.getServiceReferences(EasyMock.same(EndpointListener.class.getName()),
                                                      EasyMock
                                                          .same("("
                                                                + EndpointListener.ENDPOINT_LISTENER_SCOPE
                                                                + "=*)"))).andReturn(refs).anyTimes();
            }
           
            EasyMock.expect(bctx.createFilter(EasyMock.same(scope))).andReturn(FrameworkUtil.createFilter(scope)).anyTimes();

        }

       
        c.replay();

        //        TopologyManager tm = new TopologyManager(bctx);
        //        tm.start();

        Activator a = new Activator();
        a.start(bctx);
       
        // Wait until the EndpointListener.endpointAdded call was made as the controlflow is asynchronous
        sema.tryAcquire(30, TimeUnit.SECONDS);
       
        c.verify();

    }
View Full Code Here

public class InterfaceMonitorTest extends TestCase {

    public void testInterfaceMonitor() throws KeeperException, InterruptedException {

        IMocksControl c = EasyMock.createNiceControl();

        BundleContext ctx = c.createMock(BundleContext.class);
        ZooKeeperDiscovery zkd = c.createMock(ZooKeeperDiscovery.class);

        ZooKeeper zk = c.createMock(ZooKeeper.class);
        EasyMock.expect(zk.getState()).andReturn(ZooKeeper.States.CONNECTED).anyTimes();

        EasyMock.expect(zkd.getZookeeper()).andReturn(zk).anyTimes();

        EndpointListenerTrackerCustomizer.Interest interest = new EndpointListenerTrackerCustomizer.Interest();

        String scope = "(myProp=test)";
        String interf = "es.schaaf.test";
        String node = Util.getZooKeeperPath(interf);

        final InterfaceDataMonitorListenerImpl idmli = c.createMock(InterfaceDataMonitorListenerImpl.class);

        InterfaceMonitor im = new InterfaceMonitor(zk, interf, interest, scope, ctx) {
            @Override
            protected InterfaceDataMonitorListenerImpl createInterfaceDataMonitorListener(ZooKeeper zk,
                                                                                          String intf,
                                                                                          Interest zkd,
                                                                                          String scope,
                                                                                          BundleContext bctx) {
                return idmli;
            }
        };

        idmli.change();
        EasyMock.expectLastCall().once();

        zk.exists(EasyMock.eq(node), EasyMock.eq(im), EasyMock.eq(im), EasyMock.anyObject());
        EasyMock.expectLastCall().once();

        EasyMock.expect(zk.exists(EasyMock.eq(node), EasyMock.eq(false))).andReturn(new Stat()).anyTimes();

        EasyMock.expect(zk.getChildren(EasyMock.eq(node), EasyMock.eq(im))).andReturn(Collections.EMPTY_LIST)
            .once();

        c.replay();

        im.start();

        // simulate a zk callback
        WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.SyncConnected, node);
        im.process(we);

        c.verify();
    }
View Full Code Here

        out = Util.getStringPlusProperty(in);
        assertEquals(0, out.length);
    }
   
    public void testGetScopes(){
        IMocksControl c = EasyMock.createNiceControl();
       
        String[] scopes = new String[]{"myScope=test",""};
       
        ServiceReference sref = c.createMock(ServiceReference.class);
        EasyMock.expect(sref.getProperty(EasyMock.eq(EndpointListener.ENDPOINT_LISTENER_SCOPE))).andReturn(scopes).anyTimes();
       
        c.replay();
       
        String[] ret = Util.getScopes(sref);
       
        c.verify();
        assertEquals(1, ret.length);
        assertEquals(scopes[0], ret[0]);
       
    }
View Full Code Here

import org.osgi.service.remoteserviceadmin.RemoteConstants;

public class EndpointListenerFactoryTest extends TestCase {

    public void testScope() {
        IMocksControl c = EasyMock.createNiceControl();

        BundleContext ctx = c.createMock(BundleContext.class);
        ZooKeeperDiscovery zkd = c.createMock(ZooKeeperDiscovery.class);
        ServiceRegistration sreg = c.createMock(ServiceRegistration.class);
       
        EndpointListenerFactory eplf = new EndpointListenerFactory(zkd, ctx);

        EasyMock.expect(
                        ctx.registerService(EasyMock.eq(EndpointListener.class.getName()), EasyMock.eq(eplf),
                                            (Properties)EasyMock.anyObject())).andReturn(sreg).once();

       
        sreg.setProperties((Properties)EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            public Object answer() throws Throwable {
                Properties p = (Properties)EasyMock.getCurrentArguments()[0];
                assertNotNull(p);
                String scope = (String)p.get(EndpointListener.ENDPOINT_LISTENER_SCOPE);
                assertNotNull(scope);
                assertEquals("(&(" + Constants.OBJECTCLASS + "=*)(" + RemoteConstants.ENDPOINT_FRAMEWORK_UUID
                             + "=myUUID))", scope);
                return null;
            }
        }).once();

       
        EasyMock.expect(ctx.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("myUUID")
            .anyTimes();

       
       
       
        c.replay();
        eplf.start();
        c.verify();

       
       
        c.reset();
        sreg.unregister();
        EasyMock.expectLastCall().once();
        c.replay();
        eplf.stop();
        c.verify();
       
       
    }
View Full Code Here

TOP

Related Classes of org.easymock.classextension.IMocksControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.