Package org.easymock

Examples of org.easymock.IMocksControl


  
   
    @BeforeClass
    public static void oneTimeSetUp() throws Exception {
       
        IMocksControl control = EasyMock.createNiceControl();
        Bus bus = control.createMock(Bus.class);
        WSDLManager manager = new WSDLManagerImpl();      
        WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
        DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
        EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(dfm).anyTimes();
        EasyMock.expect(dfm.getDestinationFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes();
        BindingFactoryManager bfm = control.createMock(BindingFactoryManager.class);
        EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm).anyTimes();
        EasyMock.expect(bfm.getBindingFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes();
        control.replay();
       
        int n = 19;
        services = new ServiceInfo[n];
        endpoints = new EndpointInfo[n];
        for (int i = 0; i < n; i++) {
            String resourceName = "/attachment/wsdl11/test" + i + ".wsdl";
            URL url = Wsdl11AttachmentPolicyProviderTest.class.getResource(resourceName);      
            try {
                services[i] = builder.buildServices(manager.getDefinition(url.toString())).get(0);
            } catch (WSDLException ex) {
                ex.printStackTrace();
                fail("Failed to build service from resource " + resourceName);
            }
            assertNotNull(services[i]);
            endpoints[i] = services[i].getEndpoints().iterator().next();
            assertNotNull(endpoints[i]);
        }
       
        control.verify();

    }
View Full Code Here


public class RemoteServiceAdminCoreTest {

    @Test
    public void dontExportOwnServiceProxies() {

        IMocksControl c = EasyMock.createNiceControl();
        Bundle b = c.createMock(Bundle.class);
        BundleContext bc = c.createMock(BundleContext.class);

        EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();

        Dictionary d = new Properties();
        EasyMock.expect(b.getHeaders()).andReturn(d).anyTimes();

        ServiceReference sref = c.createMock(ServiceReference.class);
        EasyMock.expect(sref.getBundle()).andReturn(b).anyTimes();

        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc);

        c.replay();

        // must return an empty List as sref if from the same bundle
        List exRefs = rsaCore.exportService(sref, null);

        assertNotNull(exRefs);
        assertEquals(0, exRefs.size());

        // must be empty ...
        assertEquals(rsaCore.getExportedServices().size(), 0);

        c.verify();

    }
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testImport() {

        IMocksControl c = EasyMock.createNiceControl();
        Bundle b = c.createMock(Bundle.class);
        BundleContext bc = c.createMock(BundleContext.class);

        Dictionary d = new Properties();
        EasyMock.expect(b.getHeaders()).andReturn(d).anyTimes();

        EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
        EasyMock.expect(b.getSymbolicName()).andReturn("BundleName").anyTimes();

        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc) {
            @Override
            protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl imReg,
                                                    ConfigurationTypeHandler handler,
                                                    BundleContext requestingContext) {

            }
        };

        Map p = new HashMap();
        p.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
        p.put(Constants.OBJECTCLASS, new String[] {
            "es.schaaf.my.class"
        });
        p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "unsupportetConfiguration");
        EndpointDescription endpoint = new EndpointDescription(p);

        c.replay();

        // must be null as the endpoint doesn't contain any usable configurations
        assertNull(rsaCore.importService(endpoint));
        // must be empty ...
        assertEquals(0, rsaCore.getImportedEndpoints().size());

        p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "org.apache.cxf.ws");
        endpoint = new EndpointDescription(p);

        ImportRegistration ireg = rsaCore.importService(endpoint);
        assertNotNull(ireg);

        assertEquals(1, rsaCore.getImportedEndpoints().size());

        // lets import the same endpoint once more -> should get a copy of the ImportRegistration
        ImportRegistration ireg2 = rsaCore.importService(endpoint);
        assertNotNull(ireg2);
        assertEquals(2,rsaCore.getImportedEndpoints().size());

        assertEquals(ireg, (rsaCore.getImportedEndpoints().toArray())[0]);

        assertEquals(ireg.getImportReference().getImportedEndpoint(), ireg2.getImportReference()
            .getImportedEndpoint());

        // remove the registration ....

        // first call shouldn't remove the import ...
        ireg2.close();
        assertEquals(1, rsaCore.getImportedEndpoints().size());

        // second call should really close and remove the import ...
        ireg.close();
        assertEquals(0, rsaCore.getImportedEndpoints().size());

        c.verify();

    }
View Full Code Here

    }

    @Test
    public void testDefaultConfigurationType() {

        IMocksControl c = EasyMock.createNiceControl();
        Bundle b = c.createMock(Bundle.class);
        BundleContext bc = c.createMock(BundleContext.class);

        c.replay();

        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc);

        Properties serviceProperties = new Properties();

        List<String> types = rsaCore.determineConfigurationTypes(serviceProperties);

        c.verify();

        assertNotNull(types);
        assertEquals(1, types.size());

        assertTrue(types.contains(org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE));
View Full Code Here

    }

    @Test
    public void testSpecificConfigurationType() {

        IMocksControl c = EasyMock.createNiceControl();
        Bundle b = c.createMock(Bundle.class);
        BundleContext bc = c.createMock(BundleContext.class);

        c.replay();

        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc);

        Properties serviceProperties = new Properties();

        serviceProperties.setProperty(RemoteConstants.SERVICE_EXPORTED_CONFIGS,
                                      org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE);

        List<String> types = rsaCore.determineConfigurationTypes(serviceProperties);

        c.verify();

        assertNotNull(types);
        assertEquals(1, types.size());

        assertTrue(types.contains(org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE));
View Full Code Here

public class ImportRegistrationImplTest {

    @Test
    public void testException(){
       
        IMocksControl c = EasyMock.createNiceControl();
        Exception e = c.createMock(Exception.class);
        c.replay();
       
        ImportRegistrationImpl i = new ImportRegistrationImpl(e);
       
        assertEquals(e, i.getException());
        assertNull(i.getImportedEndpointDescription());
View Full Code Here

    }
   
    @Test
    public void testDefaultCtor(){
       
        IMocksControl c = EasyMock.createNiceControl();
        EndpointDescription ed = c.createMock(EndpointDescription.class);
        RemoteServiceAdminCore rsac = c.createMock(RemoteServiceAdminCore.class);
       
       
        c.replay();
       
        ImportRegistrationImpl i = new ImportRegistrationImpl(ed,rsac);
       
        assertNull(i.getException());
        assertEquals(i, i.getParent());
View Full Code Here

   
    @Test
    public void testCloneAndClose(){
    
        IMocksControl c = EasyMock.createControl();
        EndpointDescription ed = c.createMock(EndpointDescription.class);
        RemoteServiceAdminCore rsac = c.createMock(RemoteServiceAdminCore.class);
       
        ServiceRegistration sr = c.createMock(ServiceRegistration.class);
        ServiceReference sref = c.createMock(ServiceReference.class);
        EasyMock.expect(sr.getReference()).andReturn(sref).anyTimes();
       
        c.replay();
       
        ImportRegistrationImpl i1 = new ImportRegistrationImpl(ed,rsac);
       
        ImportRegistrationImpl i2 = new ImportRegistrationImpl(i1);
       
        ImportRegistrationImpl i3 = new ImportRegistrationImpl(i2);
       
       
        try{
            i2.setImportedServiceRegistration(sr);   
            assertTrue("An exception should be thrown here !", false);
        }catch(IllegalStateException e){
            // must be thrown here ...
        }
       
        i1.setImportedServiceRegistration(sr);
       
       
       
       
        assertEquals(i1, i1.getParent());
        assertEquals(i1, i2.getParent());
        assertEquals(i1, i3.getParent());
       
        assertEquals(ed,i1.getImportedEndpointDescription());
        assertEquals(ed,i2.getImportedEndpointDescription());
        assertEquals(ed,i3.getImportedEndpointDescription());
       
        c.verify();
        c.reset();
       
        rsac.removeImportRegistration(EasyMock.eq(i3));
        EasyMock.expectLastCall().once();
       
        c.replay();
       
        i3.close();
        i3.close(); // shouldn't change anything
       
        assertNull(i3.getImportedEndpointDescription());
       
       
        c.verify();
        c.reset();
       
        rsac.removeImportRegistration(EasyMock.eq(i1));
        EasyMock.expectLastCall().once();
       
        c.replay();
       
       
        i1.close();
       
        c.verify();
        c.reset();
       
        rsac.removeImportRegistration(EasyMock.eq(i2));
        EasyMock.expectLastCall().once();
       
        sr.unregister();
        EasyMock.expectLastCall().once();
       
        c.replay();
       
        i2.close();

        c.verify();
       
       
    }
View Full Code Here

       
    }
   
    @Test
    public void testCloseAll(){
        IMocksControl c = EasyMock.createControl();
        EndpointDescription ed = c.createMock(EndpointDescription.class);
        RemoteServiceAdminCore rsac = c.createMock(RemoteServiceAdminCore.class);
       
        c.replay();
       
        ImportRegistrationImpl i1 = new ImportRegistrationImpl(ed,rsac);
       
        ImportRegistrationImpl i2 = new ImportRegistrationImpl(i1);
       
        ImportRegistrationImpl i3 = new ImportRegistrationImpl(i2);
       
       
        assertEquals(i1, i1.getParent());
        assertEquals(i1, i2.getParent());
        assertEquals(i1, i3.getParent());
       
        c.verify();
        c.reset();
       
        rsac.removeImportRegistration(EasyMock.eq(i2));
        EasyMock.expectLastCall().once();
       
        c.replay();
       
        i2.close();

        c.verify();
        c.reset();
       
        rsac.removeImportRegistration(EasyMock.eq(i1));
        EasyMock.expectLastCall().once();
        rsac.removeImportRegistration(EasyMock.eq(i3));
        EasyMock.expectLastCall().once();
       
        c.replay();
        i3.closeAll();
        c.verify();
    }
View Full Code Here

       //IntentMap im = new IntentMap();
       //im.setIntents(new HashMap<String, Object>());

       // IntentMapLoader.initializeWithExistingMap(im);
       
        IMocksControl control = EasyMock.createNiceControl();
        BundleContext bc = getMockBundleContext(control);
       
        ServiceRegistration sr = control.createMock(ServiceRegistration.class);
        EasyMock.expect(bc.registerService(EasyMock.eq(RemoteServiceAdmin.class.getName()),EasyMock.anyObject(), (Dictionary)EasyMock.anyObject())).andReturn(sr).atLeastOnce();
       
       
        control.replay();
       
       
        Activator a = new Activator();
        a.setBundleContext(bc);
        a.start();
       
        control.verify();
       
    }
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.