Package org.easymock

Examples of org.easymock.IMocksControl


        Enumeration<URL> rsBEnum = Collections.enumeration(Arrays.asList(rsB));
        URL rsC = getClass().getResource("/rs_c.xml");
        Enumeration<URL> rsCEnum = Collections.enumeration(Arrays.asList(rsC));
       
        // Set up some mock objects
        IMocksControl control = EasyMock.createNiceControl();
        Bundle b0 = control.createMock(Bundle.class);
        EasyMock.expect(b0.getState()).andReturn(Bundle.ACTIVE).anyTimes();
        EasyMock.expect(b0.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                andReturn(rsAEnum).anyTimes();
       
        BundleContext bc = control.createMock(BundleContext.class);
        ServiceReference sr = control.createMock(ServiceReference.class);
        TestDiscoveredServiceTracker dst = new TestDiscoveredServiceTracker();

        EasyMock.expect(bc.getBundles()).andReturn(new Bundle[] {b0}).anyTimes();
        EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA)).
                andReturn(Collections.singleton("org.example.SomeService")).anyTimes();
       
        EasyMock.expect(bc.getService(sr)).andReturn(dst).anyTimes();
        control.replay();

        // create the local discovery service
        LocalDiscoveryService lds = new LocalDiscoveryService(bc);
       
        // it should be prepopulated with the info from bundle b0
View Full Code Here


            Enumeration<URL> rsBEnum = Collections.enumeration(Arrays.asList(rsB));
            URL rsC = getClass().getResource("/rs_f.xml");
            Enumeration<URL> rsCEnum = Collections.enumeration(Arrays.asList(rsC));
           
            // Set up some mock objects
            IMocksControl control = EasyMock.createNiceControl();
            Bundle b0 = control.createMock(Bundle.class);
            EasyMock.expect(b0.getState()).andReturn(Bundle.ACTIVE).anyTimes();
            EasyMock.expect(b0.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                    andReturn(rsAEnum).anyTimes();
           
            BundleContext bc = control.createMock(BundleContext.class);
            Filter mockFilter = control.createMock(Filter.class);
            ServiceReference sr = control.createMock(ServiceReference.class);
            TestDiscoveredServiceTracker dst = new TestDiscoveredServiceTracker();
   
            EasyMock.expect(bc.getBundles()).andReturn(new Bundle[] {b0}).anyTimes();
            EasyMock.expect(bc.createFilter("(blah <= 5)")).andReturn(mockFilter).anyTimes();
            EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.FILTER_MATCH_CRITERIA)).
                    andReturn(Collections.singleton("(blah <= 5)")).anyTimes();
           
            EasyMock.expect(bc.getService(sr)).andReturn(dst).anyTimes();
           
            // set up the mock filter behaviour
            Dictionary<String, Object> d1 = new Hashtable<String, Object>();
            d1.put("blah", "5");
            EasyMock.expect(mockFilter.match(d1)).andReturn(true).anyTimes();
            Dictionary<String, Object> d2 = new Hashtable<String, Object>();
            d2.put("blah", "3");
            d2.put("boo", "hello");
            EasyMock.expect(mockFilter.match(d2)).andReturn(true).anyTimes();
           
            control.replay();
   
            // create the local discovery service
            LocalDiscoveryService lds = new LocalDiscoveryService(bc);
           
            // it should be prepopulated with the info from bundle b0
View Full Code Here

        try {
            URL rsA = getClass().getResource("/rs_a.xml");
            Enumeration<URL> rsAEnum = Collections.enumeration(Arrays.asList(rsA));
           
            // Set up some mock objects
            IMocksControl control = EasyMock.createNiceControl();
            Bundle b0 = control.createMock(Bundle.class);
            EasyMock.expect(b0.getState()).andReturn(Bundle.ACTIVE).anyTimes();
            EasyMock.expect(b0.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                    andReturn(rsAEnum).anyTimes();
           
            BundleContext bc = control.createMock(BundleContext.class);
            EasyMock.expect(bc.getBundles()).andReturn(new Bundle[] {b0}).anyTimes();
   
            TestDiscoveredServiceTracker dst = new TestDiscoveredServiceTracker();
   
            ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
            EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA)).
                    andReturn(Collections.singleton("org.example.SomeService")).anyTimes();
            EasyMock.replay(sr);
           
            EasyMock.expect(bc.getService(sr)).andReturn(dst).anyTimes();
            control.replay();
   
            // create the local discovery service
            LocalDiscoveryService lds = new LocalDiscoveryService(bc);
           
            // it should be prepopulated with the info from bundle b0
View Full Code Here

            Enumeration<URL> rsAEnum = Collections.enumeration(Arrays.asList(rsA));
            URL rsB = getClass().getResource("/rs_b.xml");
            Enumeration<URL> rsBEnum = Collections.enumeration(Arrays.asList(rsB));
           
            // Set up some mock objects
            IMocksControl control = EasyMock.createNiceControl();
            Bundle b0 = control.createMock(Bundle.class);
            EasyMock.expect(b0.getState()).andReturn(Bundle.INSTALLED).anyTimes();
            EasyMock.expect(b0.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                    andReturn(rsAEnum).anyTimes();
   
            Bundle b1 = control.createMock(Bundle.class);
            EasyMock.expect(b1.getState()).andReturn(Bundle.ACTIVE).anyTimes();
            EasyMock.expect(b1.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                    andReturn(rsBEnum).anyTimes();
           
            BundleContext bc = control.createMock(BundleContext.class);
            ServiceReference sr = control.createMock(ServiceReference.class);
            TestDiscoveredServiceTracker dst = new TestDiscoveredServiceTracker();
   
            EasyMock.expect(bc.getBundles()).andReturn(new Bundle[] {b0, b1}).anyTimes();
            EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA)).
                    andReturn(Collections.singleton("org.example.SomeService")).anyTimes();
           
            EasyMock.expect(bc.getService(sr)).andReturn(dst).anyTimes();
            control.replay();
   
            // create the local discovery service
            LocalDiscoveryService lds = new LocalDiscoveryService(bc);
           
            ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(
View Full Code Here

    }
   
    public void testCreatThenShutdown() {
        final List<String> bundleListenerRegs = new ArrayList<String>();
       
        IMocksControl control = EasyMock.createNiceControl();
        BundleContext bc = control.createMock(BundleContext.class);
        bc.addBundleListener((BundleListener) EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                assertTrue("Should be a LocalDiscoveryService",
                        EasyMock.getCurrentArguments()[0] instanceof LocalDiscoveryService);
                bundleListenerRegs.add("addBundleListener");
                return null;
            }           
        });
       
        bc.removeBundleListener((BundleListener) EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                assertTrue("Should be a LocalDiscoveryService",
                        EasyMock.getCurrentArguments()[0] instanceof LocalDiscoveryService);
                bundleListenerRegs.add("removeBundleListener");
                return null;
            }           
        });
       
        control.replay();
       
        assertEquals("Precondition failed", 0, bundleListenerRegs.size());
        LocalDiscoveryService lds = new LocalDiscoveryService(bc);
        assertEquals(1, bundleListenerRegs.size());
        assertEquals("addBundleListener", bundleListenerRegs.get(0));
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

public class ClientServiceFactoryTest extends TestCase {
    public void testGetService() {
        Object myTestProxyObject = new Object();
       
        IMocksControl control = EasyMock.createNiceControl();
        BundleContext dswContext = control.createMock(BundleContext.class);
        ServiceEndpointDescription sd = control.createMock(ServiceEndpointDescription.class);
        ConfigurationTypeHandler handler = control.createMock(ConfigurationTypeHandler.class);

        BundleContext requestingContext = control.createMock(BundleContext.class);
        Bundle requestingBundle = control.createMock(Bundle.class);
        EasyMock.expect(requestingBundle.getBundleContext()).andReturn(requestingContext);
       
        ServiceReference sr = control.createMock(ServiceReference.class);
        ServiceRegistration sreg = control.createMock(ServiceRegistration.class);
        EasyMock.expect(sreg.getReference()).andReturn(sr);
       
        handler.createProxy(sr, dswContext, requestingContext, String.class, sd);
        EasyMock.expectLastCall().andReturn(myTestProxyObject);       
        control.replay();      
       
        ClientServiceFactory csf = new ClientServiceFactory(dswContext, String.class, sd, handler);
        assertSame(myTestProxyObject, csf.getService(requestingBundle, sreg));
    }
View Full Code Here

import org.osgi.service.discovery.ServiceEndpointDescription;
import org.osgi.service.discovery.ServicePublication;

public class ServiceHookUtilsTest extends TestCase {
    public void testCreateServer() {
        IMocksControl control = EasyMock.createNiceControl();
       
        Server srvr = control.createMock(Server.class);
        ServiceReference serviceReference = control.createMock(ServiceReference.class);
        BundleContext dswContext = control.createMock(BundleContext.class);
        BundleContext callingContext = control.createMock(BundleContext.class);
        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("java.lang.String");
        Object service = "hi";

        ConfigurationTypeHandler handler = control.createMock(ConfigurationTypeHandler.class);
        handler.createServer(serviceReference, dswContext, callingContext, sd, String.class, service);
        EasyMock.expectLastCall().andReturn(srvr);
        control.replay();
       
        assertSame(srvr,
            ServiceHookUtils.createServer(handler, serviceReference, dswContext, callingContext, sd, service));       
    }
View Full Code Here

        assertSame(srvr,
            ServiceHookUtils.createServer(handler, serviceReference, dswContext, callingContext, sd, service));       
    }

    public void testNoServerWhenNoInterfaceSpecified() {
        IMocksControl control = EasyMock.createNiceControl();
       
        Server srvr = control.createMock(Server.class);
        ServiceReference serviceReference = control.createMock(ServiceReference.class);
        BundleContext dswContext = control.createMock(BundleContext.class);
        BundleContext callingContext = control.createMock(BundleContext.class);
        ServiceEndpointDescription sd = mockServiceDescription(control, "Foo");
        Object service = "hi";

        ConfigurationTypeHandler handler = control.createMock(ConfigurationTypeHandler.class);
        handler.createServer(serviceReference, dswContext, callingContext, sd, String.class, service);
        EasyMock.expectLastCall().andReturn(srvr);
        control.replay();
       
        assertNull(ServiceHookUtils.createServer(handler, serviceReference, dswContext, callingContext, sd, service));       
    }
View Full Code Here

import org.osgi.service.distribution.DistributionProvider;

public class ActivatorTest extends TestCase{
    @SuppressWarnings("unchecked")
    private BundleContext getMockBundleContext() {
        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();
        return bc;
    }
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.