Package org.easymock

Examples of org.easymock.IMocksControl


        EasyMock.verify(mockDP);
    }
   
    @SuppressWarnings("unchecked")
    public void testCreateDistributionProviderService() throws Exception {
        IMocksControl control = EasyMock.createNiceControl();
       
        Bundle b = control.createMock(Bundle.class);
        Hashtable<String, String> ht = new Hashtable<String, String>();
        EasyMock.expect(b.getHeaders()).andReturn(ht).anyTimes();
       
        final Map<Object, Dictionary> services = new HashMap<Object, Dictionary>();
        BundleContext bc = control.createMock(BundleContext.class);
        EasyMock.expect(bc.registerService(
            (String) EasyMock.anyObject(),
            EasyMock.anyObject(),
            (Dictionary) EasyMock.anyObject())).andAnswer(new IAnswer<ServiceRegistration>() {
                public ServiceRegistration answer() throws Throwable {
                    services.put(EasyMock.getCurrentArguments()[1],
                        (Dictionary) EasyMock.getCurrentArguments()[2]);
                    return null;
                }               
            }).anyTimes();           

        EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
        EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
        control.replay();
       
        Activator a = new Activator() {
            @Override
            IntentMap getIntentMap() {
                Map<String, Object> intents = new HashMap<String, Object>();
View Full Code Here


    }
   
    public void testPublishPreexistingServices() throws Exception {
        TestService serviceObject = new TestServiceImpl();

        IMocksControl control = EasyMock.createNiceControl();
       
        Bundle b = control.createMock(Bundle.class);
        Hashtable<String, String> ht = new Hashtable<String, String>();
        EasyMock.expect(b.getHeaders()).andReturn(ht).anyTimes();
       
        BundleContext bc = control.createMock(BundleContext.class);      
       
        ServiceReference sref = control.createMock(ServiceReference.class);
        EasyMock.expect(sref.getBundle()).andReturn(b).anyTimes();
        EasyMock.expect(sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS)).
            andReturn(new String [] {TestService.class.getName()}).anyTimes();
        EasyMock.expect(sref.getPropertyKeys()).
            andReturn(new String [] {"osgi.remote.interfaces"}).anyTimes();
        EasyMock.expect(sref.getProperty("osgi.remote.interfaces")).
            andReturn("*").anyTimes();

        EasyMock.expect(bc.getServiceReferences(null, "(osgi.remote.interfaces=*)")).
            andReturn(new ServiceReference[] {sref}).anyTimes();
        EasyMock.expect(bc.getService(sref)).andReturn(serviceObject).anyTimes();

        EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
        EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
        control.replay();
       
        Activator a = new Activator() {
            @Override
            IntentMap getIntentMap() {
                IntentMap intentMap = new IntentMap();
View Full Code Here

   
    @Test
    public void testImportForNewlyAddedRSA() throws InterruptedException{
       
        IMocksControl c = EasyMock.createNiceControl();

        c.makeThreadSafe(true);
       
        final Semaphore sema = new Semaphore(0);
       
        BundleContext bc = c.createMock(BundleContext.class);
        ServiceRegistration sreg = c.createMock(ServiceRegistration.class);
        EasyMock.expect(bc.registerService((String)EasyMock.anyObject(), EasyMock.anyObject(), (Dictionary)EasyMock.anyObject())).andReturn(sreg).anyTimes();
        
       
        EndpointDescription epd = c.createMock(EndpointDescription.class);
        RemoteServiceAdmin rsa  = c.createMock(RemoteServiceAdmin.class);
        final ImportRegistration ireg = c.createMock(ImportRegistration.class);
        ImportReference iref = c.createMock(ImportReference.class);
       
        EasyMock.expect(rsa.importService(EasyMock.eq(epd))).andAnswer(new IAnswer<ImportRegistration>( ) {

            public ImportRegistration answer() throws Throwable {
                sema.release();
                return ireg;
            }
        }).once();
        EasyMock.expect(ireg.getImportReference()).andReturn(iref).anyTimes();
        EasyMock.expect(iref.getImportedEndpoint()).andReturn(epd).anyTimes();
        c.replay();
       
       
        RemoteServiceAdminList rsaList = new RemoteServiceAdminList(bc);
       
        TopologyManagerImport tm = new TopologyManagerImport(bc, rsaList);

        tm.start();
       
        // no RSa available yet so no import ... 
        tm.addImportableService("myFilter", epd);
       
        rsaList.add(rsa);
       
        tm.triggerExportImportForRemoteSericeAdmin(rsa);
       
        assertTrue(sema.tryAcquire(10, TimeUnit.SECONDS));
       
       
        tm.stop();
       
        c.verify();
       
    }
View Full Code Here

public class TopologyManagerTest {

    @Test
    public void testNotifyListenersOfRemovalIfAppropriate() throws InvalidSyntaxException {

        IMocksControl c = EasyMock.createNiceControl();

        BundleContext bc = c.createMock(BundleContext.class);
        ServiceReference sref = c.createMock(ServiceReference.class);
        ExportRegistration exReg = c.createMock(ExportRegistration.class);
        ExportRegistration exReg2 = c.createMock(ExportRegistration.class);
        EndpointListener epl = EasyMock.createMock(EndpointListener.class);
        EndpointDescription epd = c.createMock(EndpointDescription.class);
        EndpointDescription epd2 = c.createMock(EndpointDescription.class);
        ExportReference exRef = c.createMock(ExportReference.class);
        ExportReference exRef2 = c.createMock(ExportReference.class);
       
       
        Map props = new HashMap();
        String[] oc = new String[1];
        oc[0] = "myClass";
        props.put("objectClass", oc);
       
        Map props2 = new HashMap();
        oc = new String[1];
        oc[0] = "notMyClass";
        props2.put("objectClass", oc);
       
       
        EasyMock.expect(bc.getService(EasyMock.eq(sref))).andReturn(epl).anyTimes();
        EasyMock.expect(bc.createFilter((String)EasyMock.anyObject())).andAnswer(new IAnswer<Filter>() {
            public Filter answer() throws Throwable {
                return FrameworkUtil.createFilter((String)EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();
        EasyMock.expect(sref.getProperty(EasyMock.eq(EndpointListener.ENDPOINT_LISTENER_SCOPE)))
            .andReturn("(objectClass=myClass)").anyTimes();

       
        EasyMock.expect(exReg.getExportReference()).andReturn(exRef).anyTimes();
        EasyMock.expect(exRef.getExportedEndpoint()).andReturn(epd).anyTimes();
        EasyMock.expect(epd.getProperties()).andReturn(props).anyTimes();
       
        EasyMock.expect(exReg2.getExportReference()).andReturn(exRef2).anyTimes();
        EasyMock.expect(exRef2.getExportedEndpoint()).andReturn(epd2).anyTimes();
        EasyMock.expect(epd2.getProperties()).andReturn(props2).anyTimes();
       
        // must only be called for the first EndpointDestription !
        epl.endpointRemoved(EasyMock.eq(epd), EasyMock.eq("(objectClass=myClass)"));
        EasyMock.expectLastCall().once();
       
        c.replay();
        EasyMock.replay(epl);
       
        TopologyManager tm = new TopologyManager(bc, null);


        List<ExportRegistration> exRegs = new ArrayList<ExportRegistration>();
        exRegs.add(exReg);
        exRegs.add(exReg2);

        tm.notifyListenersOfRemovalIfAppropriate(sref, exRegs);

        c.verify();
        EasyMock.verify(epl);

    }
View Full Code Here

    RemoteServiceAdminList rsal = null;
   
    @Test
    public void testRemoteServiceAdminAddingAndRemoval() throws InvalidSyntaxException{
       
        IMocksControl control = EasyMock.createNiceControl();
       
        BundleContext bc = control.createMock(BundleContext.class);
        TopologyManager tm = control.createMock(TopologyManager.class);
        TopologyManagerImport tmi = control.createMock(TopologyManagerImport.class);
       
       
        RemoteServiceAdmin rsa = control.createMock(RemoteServiceAdmin.class);
        final ServiceReference rsaSref = control.createMock(ServiceReference.class);
       
       
        tm.removeRemoteServiceAdmin(EasyMock.eq(rsa));
        EasyMock.expectLastCall().once();
       
        tm.triggerExportImportForRemoteSericeAdmin(EasyMock.eq(rsa));
        EasyMock.expectLastCall().once();
       
        tmi.triggerExportImportForRemoteSericeAdmin(EasyMock.eq(rsa));
        EasyMock.expectLastCall().once();
       
        bc.addServiceListener((ServiceListener)EasyMock.anyObject(),(String)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, rsaSref);
                sl.serviceChanged(se);

                assertEquals(1,rsal.size());
               
                se = new ServiceEvent(ServiceEvent.UNREGISTERING, rsaSref);
                sl.serviceChanged(se);
               
                assertEquals(0,rsal.size());
               
                return null;
            }
        }).anyTimes();

        EasyMock.expect(bc.getService(EasyMock.same(rsaSref))).andReturn(rsa).anyTimes();

        EasyMock.expect(bc.createFilter((String)EasyMock.anyObject())).andReturn(null).anyTimes();
       
       
       
       control.replay();
       
       
       
       
       rsal  = new RemoteServiceAdminList(bc);
       
       
       
       
       
        rsal.setTopologyManager(tm);
        rsal.setTopologyManagerImport(tmi);
       
        System.out.println("start");
        rsal.start();
       
       
       
        control.verify();
       
       
       
    }
View Full Code Here

public class ActivatorTest {

    @Test
    public void testZookeeperDiscoveryStartstop() throws Exception {

        IMocksControl c = EasyMock.createNiceControl();
        final ZooKeeperDiscovery z = c.createMock(ZooKeeperDiscovery.class);

        z.stop();

        EasyMock.expectLastCall().once();

        Activator a = new Activator() {

            @Override
            protected ZooKeeperDiscovery createZooKeeperDiscovery() {
                return z;
            }

        };

        BundleContext bc = c.createMock(BundleContext.class);
        ServiceRegistration sr = c.createMock(ServiceRegistration.class);

        EasyMock.expect(
                        bc.registerService(EasyMock.eq(ManagedService.class.getName()), EasyMock.eq(a),
                                           (Dictionary)EasyMock.anyObject())).andReturn(sr).once();
        sr.unregister();
        EasyMock.expectLastCall().once();

        c.replay();

        a.start(bc);
       
        a.updated(null);
       
        a.stop(bc);

        c.verify();

    }
View Full Code Here

    }

    @Test
    public void testConfugrationUpdate() throws Exception {

        IMocksControl c = EasyMock.createNiceControl();
        final ZooKeeperDiscovery z = c.createMock(ZooKeeperDiscovery.class);

        Activator a = new Activator() {
            @Override
            protected ZooKeeperDiscovery createZooKeeperDiscovery() {
                return z;
            }

        };

        BundleContext bc = c.createMock(BundleContext.class);

        z.stop();
        EasyMock.expectLastCall().andStubThrow(new RuntimeException("No Update should take place here !!"));

        c.replay();

        a.start(bc);
       
        a.updated(null);

        c.verify();
        c.reset();

        final Dictionary d = new Properties();
        d.put("test", "value");

        z.stop();
        EasyMock.expectLastCall().once();
        z.start();
        EasyMock.expectLastCall().once();

        ServiceRegistration cmReg = c.createMock(ServiceRegistration.class);       
        cmReg.setProperties((Dictionary) EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Dictionary d = (Dictionary) EasyMock.getCurrentArguments()[0];
                assertEquals("value", d.get("test"));
                return null;
            }
        }).once();       
        a.cmReg = cmReg;
       
        c.replay();
        a.updated(d);
        c.verify();
    }
View Full Code Here

  }

  private ProviderMethodBinding createProviderMethodBinding(Object instance, Method method) {
    // Ew, but the constructor of ProviderMethod is private, and this is a
    // simple way to create a custom one.
    IMocksControl control = EasyMock.createControl();
    @SuppressWarnings("unchecked")
    ProviderMethod<Integer> providerMethod =
        (ProviderMethod<Integer>) control.createMock("providerMethod", ProviderMethod.class);

    EasyMock.expect(providerMethod.getInstance()).andStubReturn(instance);
    EasyMock.expect(providerMethod.getKey()).andStubReturn(Key.get(Integer.class));
    EasyMock.expect(providerMethod.getMethod()).andStubReturn(method);

    control.replay();

    // Note: guiceUtil and methodCallUtil are used in parts of the binding class
    // that we don't test currently, so are set to null.  When tests for
    // getCreationStatements() and getDependencies() are written, concrete
    // values (mocks?) will be required.
    ProviderMethodBinding result = new ProviderMethodBinding(
        errorManager,
        null,
        null,
        providerMethod,
        Context.forText("dummy context"));

    control.verify();
    return result;
  }
View Full Code Here

       
        exchange.getOut().setHeader("soapAction", "urn:hello:world");
        exchange.getOut().setHeader("MyFruitHeader", "peach");
        exchange.getOut().addAttachment("att-1", new DataHandler(new FileDataSource("pom.xml")));
       
        IMocksControl control = EasyMock.createNiceControl();
       
        Endpoint endpoint = control.createMock(Endpoint.class);
        Binding binding = control.createMock(Binding.class);
        EasyMock.expect(endpoint.getBinding()).andReturn(binding);
        org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
        EasyMock.expect(binding.createMessage()).andReturn(cxfMessage);
        cxfExchange.put(Endpoint.class, endpoint);
        control.replay();
       
        cxfBinding.populateCxfResponseFromExchange(exchange, cxfExchange);
       
        cxfMessage = cxfExchange.getOutMessage();
        assertNotNull(cxfMessage);
View Full Code Here

       
        exchange.getOut().setHeader("soapAction", "urn:hello:world");
        exchange.getOut().setHeader("MyFruitHeader", "peach");
        exchange.getOut().addAttachment("att-1", new DataHandler(new FileDataSource("pom.xml")));
       
        IMocksControl control = EasyMock.createNiceControl();
       
        Endpoint endpoint = control.createMock(Endpoint.class);
        Binding binding = control.createMock(Binding.class);
        EasyMock.expect(endpoint.getBinding()).andReturn(binding);
        org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
        EasyMock.expect(binding.createMessage()).andReturn(cxfMessage);
        cxfExchange.put(Endpoint.class, endpoint);
        control.replay();
       
        cxfBinding.populateCxfResponseFromExchange(exchange, cxfExchange);
       
        cxfMessage = cxfExchange.getOutMessage();
        assertNotNull(cxfMessage);
View Full Code Here

TOP

Related Classes of org.easymock.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.