Package org.apache.cxf.dosgi.discovery.local.internal

Examples of org.apache.cxf.dosgi.discovery.local.internal.LocalDiscovery


            }
        });
        EasyMock.expect(bc.getBundles()).andReturn(null);
        EasyMock.replay(bc);
               
        LocalDiscovery ld = new LocalDiscovery(bc);
        assertSame(bc, ld.bundleContext);
        assertNotNull(ld.listenerTracker);       
       
        EasyMock.verify(bc);
       
        EasyMock.reset(bc);
        bc.removeBundleListener(ld);       
        EasyMock.expectLastCall();
        bc.removeServiceListener((ServiceListener) EasyMock.anyObject());
        EasyMock.expectLastCall();
        EasyMock.replay(bc);

        ld.shutDown();
        EasyMock.verify(bc);
    }
View Full Code Here


        EasyMock.replay(b2);
       
        EasyMock.expect(bc.getBundles()).andReturn(new Bundle [] {b1, b2});
        EasyMock.replay(bc);
               
        LocalDiscovery ld = new LocalDiscovery(bc);
               
        assertEquals(3, ld.endpointDescriptions.size());
        Set<String> expected = new HashSet<String>(
                Arrays.asList("http://somewhere:12345", "http://somewhere:1", "http://somewhere"));
        Set<String> actual = new HashSet<String>();
View Full Code Here

        }
        assertEquals(expected, actual);
    }
   
    public void testBundleChanged() throws Exception {
        LocalDiscovery ld = getLocalDiscovery();

        Bundle bundle = EasyMock.createMock(Bundle.class);
        EasyMock.expect(bundle.getSymbolicName()).andReturn("testing.bundle").anyTimes();
        EasyMock.expect(bundle.getState()).andReturn(Bundle.ACTIVE);
        Dictionary<String, Object> headers = new Hashtable<String, Object>();
        headers.put("Remote-Service", "OSGI-INF/rsa/");
        EasyMock.expect(bundle.getHeaders()).andReturn(headers);
        EasyMock.expect(bundle.findEntries("OSGI-INF/rsa", "*.xml", false))
            .andReturn(Collections.enumeration(
                Collections.singleton(getClass().getResource("/ed3.xml"))));
        EasyMock.replay(bundle);
               
        BundleEvent be0 = new BundleEvent(BundleEvent.INSTALLED, bundle);
        ld.bundleChanged(be0);
        assertEquals(0, ld.endpointDescriptions.size());
       
        // Create an EndpointListener
        final Hashtable<String, Object> props = new Hashtable<String, Object>();
        props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, "(objectClass=*)");
        ServiceReference sr = EasyMock.createMock(ServiceReference.class);
        EasyMock.expect(sr.getPropertyKeys()).andReturn(props.keySet().toArray(new String [] {})).anyTimes();
        EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                return props.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();               
        EasyMock.replay(sr);

        EndpointListener el = EasyMock.createMock(EndpointListener.class);
        el.endpointAdded((EndpointDescription) EasyMock.anyObject(), EasyMock.eq("(objectClass=*)"));
        EasyMock.expectLastCall();
        EasyMock.replay(el);
        ld.registerTracker(sr, el);
       
        // Start the bundle
        BundleEvent be = new BundleEvent(BundleEvent.STARTED, bundle);
        ld.bundleChanged(be);
        assertEquals(1, ld.endpointDescriptions.size());
        EndpointDescription ed = ld.endpointDescriptions.keySet().iterator().next();
        assertEquals("http://somewhere:12345", ed.getId());
        assertSame(bundle, ld.endpointDescriptions.get(ed));
       
        EasyMock.verify(el);

        // Stop the bundle
        EasyMock.reset(el);
        el.endpointRemoved((EndpointDescription) EasyMock.anyObject(), EasyMock.eq("(objectClass=*)"));
        EasyMock.expectLastCall();
        EasyMock.replay(el);
       
        BundleEvent be1 = new BundleEvent(BundleEvent.STOPPED, bundle);
        ld.bundleChanged(be1);
        assertEquals(0, ld.endpointDescriptions.size());
       
        EasyMock.verify(el);
    }
View Full Code Here

       
        EasyMock.verify(el);
    }
   
    public void testEndpointListenerService() throws Exception {
        LocalDiscovery ld = getLocalDiscovery();

        Bundle bundle = EasyMock.createMock(Bundle.class);
        EasyMock.expect(bundle.getState()).andReturn(Bundle.ACTIVE);
        Dictionary<String, Object> headers = new Hashtable<String, Object>();
        headers.put("Remote-Service", "OSGI-INF/rsa/ed4.xml");
        EasyMock.expect(bundle.getHeaders()).andReturn(headers);
        EasyMock.expect(bundle.findEntries("OSGI-INF/rsa", "ed4.xml", false))
            .andReturn(Collections.enumeration(
                Collections.singleton(getClass().getResource("/ed4.xml"))));
        EasyMock.replay(bundle);
                       
        BundleEvent be = new BundleEvent(BundleEvent.STARTED, bundle);
        ld.bundleChanged(be);
        assertEquals(2, ld.endpointDescriptions.size());       

        final Hashtable<String, Object> props = new Hashtable<String, Object>();
        props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, new String [] {"(objectClass=org.example.ClassA)"});
        ServiceReference sr = EasyMock.createMock(ServiceReference.class);
View Full Code Here

        assertEquals(0, valIter.next().size());
        assertEquals(0, valIter.next().size());
    }
   
    public void testRegisterTracker() throws Exception {
        LocalDiscovery ld = getLocalDiscovery();

        final Hashtable<String, Object> props = new Hashtable<String, Object>();
        props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, "(objectClass=Aaaa)");
        ServiceReference sr = EasyMock.createMock(ServiceReference.class);
        EasyMock.expect(sr.getPropertyKeys()).andReturn(props.keySet().toArray(new String [] {})).anyTimes();
        EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                return props.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();               
        EasyMock.replay(sr);

        EndpointListener el = EasyMock.createMock(EndpointListener.class);
        EasyMock.replay(el);
       
        assertEquals("Precondition failed", 0, ld.listenerToFilters.size());
        assertEquals("Precondition failed", 0, ld.filterToListeners.size());
        ld.registerTracker(sr, el);
       
        assertEquals(1, ld.listenerToFilters.size());
        assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el));
        assertEquals(1, ld.filterToListeners.size());
        assertEquals(Collections.singletonList(el), ld.filterToListeners.get("(objectClass=Aaaa)"));
       
        // Add another one with the same scope filter
        ServiceReference sr2 = EasyMock.createMock(ServiceReference.class);
        EasyMock.expect(sr2.getPropertyKeys()).andReturn(props.keySet().toArray(new String [] {})).anyTimes();
        EasyMock.expect(sr2.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                return props.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();               
        EasyMock.replay(sr2);

        EndpointListener el2 = EasyMock.createMock(EndpointListener.class);
        EasyMock.replay(el2);
        ld.registerTracker(sr2, el2);

        assertEquals(2, ld.listenerToFilters.size());
        assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el));
        assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el2));
       
        assertEquals(1, ld.filterToListeners.size());
        assertEquals(Arrays.asList(el, el2), ld.filterToListeners.get("(objectClass=Aaaa)"));
       
        // Add another listener with a multi-value scope
        final Hashtable<String, Object> props2 = new Hashtable<String, Object>();
        props2.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, Arrays.asList("(objectClass=X)","(objectClass=Y)"));
        ServiceReference sr3 = EasyMock.createMock(ServiceReference.class);
        EasyMock.expect(sr3.getPropertyKeys()).andReturn(props2.keySet().toArray(new String [] {})).anyTimes();
        EasyMock.expect(sr3.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                return props2.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();               
        EasyMock.replay(sr3);

        EndpointListener el3 = EasyMock.createMock(EndpointListener.class);
        EasyMock.replay(el3);
        ld.registerTracker(sr3, el3);

        assertEquals(3, ld.listenerToFilters.size());
        assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el));
        assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el2));
        assertEquals(Arrays.asList("(objectClass=X)","(objectClass=Y)"), ld.listenerToFilters.get(el3));
View Full Code Here

        assertEquals(Collections.singletonList(el3), ld.filterToListeners.get("(objectClass=X)"));
        assertEquals(Collections.singletonList(el3), ld.filterToListeners.get("(objectClass=Y)"));
    }
   
    public void testClearTracker() throws Exception {
        LocalDiscovery ld = getLocalDiscovery();
       
        EndpointListener el = EasyMock.createMock(EndpointListener.class);
        ld.listenerToFilters.put(el, new ArrayList<String>(Arrays.asList("(a=b)", "(objectClass=foo.bar.Bheuaark)")));
        ld.filterToListeners.put("(a=b)", new ArrayList<EndpointListener>(Arrays.asList(el)));
        ld.filterToListeners.put("(objectClass=foo.bar.Bheuaark)", new ArrayList<EndpointListener>(Arrays.asList(el)));
                       
        ld.clearTracker("foobar"); // should not barf
       
        assertEquals(1, ld.listenerToFilters.size());
        assertEquals(2, ld.filterToListeners.size());
        assertEquals(1, ld.filterToListeners.values().iterator().next().size());
        ld.clearTracker(EasyMock.createMock(EndpointListener.class));
        assertEquals(1, ld.listenerToFilters.size());
        assertEquals(2, ld.filterToListeners.size());
        assertEquals(1, ld.filterToListeners.values().iterator().next().size());
        ld.clearTracker(el);
        assertEquals(0, ld.listenerToFilters.size());       
        assertEquals(2, ld.filterToListeners.size());
        assertEquals(0, ld.filterToListeners.values().iterator().next().size());
    }   
View Full Code Here

        bc.addBundleListener((BundleListener) EasyMock.anyObject());
        EasyMock.expectLastCall();
        EasyMock.expect(bc.getBundles()).andReturn(null);
        EasyMock.replay(bc);
               
        LocalDiscovery ld = new LocalDiscovery(bc);
        return ld;
    }   
View Full Code Here

TOP

Related Classes of org.apache.cxf.dosgi.discovery.local.internal.LocalDiscovery

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.