Search in sources :

Example 1 with FeatureDTO

use of com.amitinside.featureflags.dto.FeatureDTO in project feature-flags-for-osgi by amitjoy.

the class ManagerHelper method toFeatureDTO.

public static FeatureDTO toFeatureDTO(final Feature f) {
    requireNonNull(f, "Feature cannot be null");
    final FeatureDTO feature = new FeatureDTO();
    feature.id = f.id;
    feature.bundleId = f.bundleId;
    feature.name = f.name;
    feature.description = f.description;
    feature.isEnabled = f.isEnabled;
    return feature;
}
Also used : FeatureDTO(com.amitinside.featureflags.dto.FeatureDTO)

Example 2 with FeatureDTO

use of com.amitinside.featureflags.dto.FeatureDTO in project feature-flags-for-osgi by amitjoy.

the class FeatureManagerProviderTest method testGetFeaturesFromMetatypeXMLDescriptorWithoutDefaultValue.

@Test
public void testGetFeaturesFromMetatypeXMLDescriptorWithoutDefaultValue() 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("myfeature").findAny().get();
    assertEquals(FEATURE_DESC, feature.description);
    assertFalse(feature.isEnabled);
    extender.removedBundle(bundle, bundleEvent, null);
}
Also used : BundleEvent(org.osgi.framework.BundleEvent) FeatureDTO(com.amitinside.featureflags.dto.FeatureDTO) Test(org.junit.Test)

Example 3 with FeatureDTO

use of com.amitinside.featureflags.dto.FeatureDTO in project feature-flags-for-osgi by amitjoy.

the class FeatureManagerProviderTest method testConfigurationEventDeleted.

@Test
public void testConfigurationEventDeleted() 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);
    final ConfigurationEvent configEvent = new ConfigurationEvent(reference, 2, null, "a");
    manager.configurationEvent(configEvent);
    final List<FeatureDTO> newFeatures = manager.getFeatures().collect(Collectors.toList());
    assertTrue(newFeatures.isEmpty());
}
Also used : ConfigurationEvent(org.osgi.service.cm.ConfigurationEvent) BundleEvent(org.osgi.framework.BundleEvent) FeatureDTO(com.amitinside.featureflags.dto.FeatureDTO) Test(org.junit.Test)

Example 4 with FeatureDTO

use of com.amitinside.featureflags.dto.FeatureDTO in project feature-flags-for-osgi by amitjoy.

the class FeatureManagerProviderTest method testUpdateFeature1.

@Test
public void testUpdateFeature1() 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 });
    mockADWithDefaultValue();
    when(bundleContext1.getBundle(0)).thenReturn(systemBundle);
    when(bundle.getState()).thenReturn(ACTIVE);
    when(bundle.getBundleContext()).thenReturn(bundleContext1);
    when(configurationAdmin.getConfiguration("a", "?")).thenReturn(configuration);
    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);
    assertTrue(feature.isEnabled);
    feature = manager.getFeatures(FEATURE_ID).findFirst().get();
    assertEquals(FEATURE_ID, feature.id);
    assertEquals(FEATURE_DESC, feature.description);
    assertTrue(feature.isEnabled);
    feature = manager.getFeatures(FEATURE_ID).findAny().get();
    assertEquals(FEATURE_DESC, feature.description);
    assertTrue(feature.isEnabled);
    try {
        manager.updateFeature(FEATURE_ID, false);
    } catch (final Exception e) {
        assertFalse(true);
    }
    manager.unsetConfigurationAdmin(configurationAdmin);
    manager.unsetMetaTypeService(metaTypeService);
    manager.deactivate(bundleContext1);
}
Also used : BundleEvent(org.osgi.framework.BundleEvent) FeatureDTO(com.amitinside.featureflags.dto.FeatureDTO) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with FeatureDTO

use of com.amitinside.featureflags.dto.FeatureDTO in project feature-flags-for-osgi by amitjoy.

the class FeatureManagerProviderTest method testGetFeaturesFromMetatypeXMLDescriptorWithDefaultValue.

@Test
public void testGetFeaturesFromMetatypeXMLDescriptorWithDefaultValue() 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 });
    mockADWithDefaultValue();
    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);
    assertTrue(feature.isEnabled);
    feature = manager.getFeatures(FEATURE_ID).findFirst().get();
    assertEquals(FEATURE_ID, feature.id);
    assertEquals(FEATURE_DESC, feature.description);
    assertTrue(feature.isEnabled);
    feature = manager.getFeatures(FEATURE_ID).findAny().get();
    assertEquals(FEATURE_DESC, feature.description);
    assertTrue(feature.isEnabled);
    manager.unsetConfigurationAdmin(configurationAdmin);
    manager.unsetMetaTypeService(metaTypeService);
    manager.deactivate(bundleContext1);
}
Also used : BundleEvent(org.osgi.framework.BundleEvent) FeatureDTO(com.amitinside.featureflags.dto.FeatureDTO) Test(org.junit.Test)

Aggregations

FeatureDTO (com.amitinside.featureflags.dto.FeatureDTO)12 Test (org.junit.Test)11 BundleEvent (org.osgi.framework.BundleEvent)11 IOException (java.io.IOException)3 ConfigurationEvent (org.osgi.service.cm.ConfigurationEvent)3 MapToDictionary (org.apache.felix.utils.collections.MapToDictionary)1