@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();
}