Search in sources :

Example 16 with ConfigurationEvent

use of org.osgi.service.cm.ConfigurationEvent in project feature-flags-for-osgi by amitjoy.

the class FeatureManagerProviderTest method testConfigurationEventUpdatedButIOException.

@Test
public void testConfigurationEventUpdatedButIOException() throws Exception {
    final FeatureManagerProvider manager = new FeatureManagerProvider();
    manager.setConfigurationAdmin(configurationAdmin);
    manager.setMetaTypeService(metaTypeService);
    manager.activate(bundleContext1);
    final MetaTypeExtender extender = manager.getExtender();
    final String[] pids = new String[] { "a" };
    final BundleEvent bundleEvent = new BundleEvent(BundleEvent.STARTED, bundle);
    when(metaTypeService.getMetaTypeInformation(bundle)).thenReturn(metaTypeInfo);
    when(metaTypeInfo.getPids()).thenReturn(pids);
    when(metaTypeInfo.getObjectClassDefinition("a", null)).thenReturn(ocd);
    when(ocd.getAttributeDefinitions(ALL)).thenReturn(new AttributeDefinition[] { ad });
    mockADWithoutDefaultValue();
    when(bundleContext1.getBundle(0)).thenReturn(systemBundle);
    when(bundle.getState()).thenReturn(ACTIVE);
    when(bundle.getBundleContext()).thenReturn(bundleContext1);
    extender.addingBundle(bundle, bundleEvent);
    Thread.sleep(1000);
    FeatureDTO feature = manager.getFeatures().collect(Collectors.toList()).get(0);
    assertEquals(FEATURE_ID, feature.id);
    assertEquals(FEATURE_DESC, feature.description);
    assertFalse(feature.isEnabled);
    feature = manager.getFeatures(FEATURE_ID).findFirst().get();
    assertEquals(FEATURE_ID, feature.id);
    assertEquals(FEATURE_DESC, feature.description);
    assertFalse(feature.isEnabled);
    feature = manager.getFeatures(FEATURE_ID).findAny().get();
    assertEquals(FEATURE_DESC, feature.description);
    assertFalse(feature.isEnabled);
    when(configurationAdmin.getConfiguration("a", "?")).thenThrow(IOException.class);
    final ConfigurationEvent configEvent = new ConfigurationEvent(reference, 1, null, "a");
    manager.configurationEvent(configEvent);
    final FeatureDTO updatedFeature = manager.getFeatures(FEATURE_ID).findAny().get();
    assertFalse(updatedFeature.isEnabled);
}
Also used : ConfigurationEvent(org.osgi.service.cm.ConfigurationEvent) BundleEvent(org.osgi.framework.BundleEvent) FeatureDTO(com.amitinside.featureflags.dto.FeatureDTO) Test(org.junit.Test)

Aggregations

ConfigurationEvent (org.osgi.service.cm.ConfigurationEvent)16 ConfigurationListener (org.osgi.service.cm.ConfigurationListener)8 Test (org.junit.Test)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Hashtable (java.util.Hashtable)4 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)4 FeatureDTO (com.amitinside.featureflags.dto.FeatureDTO)3 Dictionary (java.util.Dictionary)3 Capture (org.easymock.Capture)3 Bundle (org.osgi.framework.Bundle)3 BundleEvent (org.osgi.framework.BundleEvent)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 Configuration (org.osgi.service.cm.Configuration)2 FabricException (io.fabric8.api.FabricException)1 RuntimeProperties (io.fabric8.api.RuntimeProperties)1 BootstrapConfiguration (io.fabric8.zookeeper.bootstrap.BootstrapConfiguration)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1