def testDuplicatedFactory(self): """ Tests the behavior of iPOPO if two bundles provide the same factory. """ # Start the framework self.framework = FrameworkFactory.get_framework() self.framework.start() ipopo = install_ipopo(self.framework) # Install bundles: both provide a "basic-component-factory" factory # and instantiate a component (both with different names) module_A = install_bundle(self.framework, "tests.ipopo.ipopo_bundle") module_B = install_bundle(self.framework, "tests.ipopo.ipopo_bundle_copy") # Ensure that the module providing the factory is the correct one self.assertIs(module_A, ipopo.get_factory_bundle( module_A.BASIC_FACTORY).get_module(), "Duplicated factory is not provided by the first module") self.assertIs(module_A, ipopo.get_factory_bundle( module_B.BASIC_FACTORY).get_module(), "Duplicated factory is not provided by the first module") # Component of module A must be there self.assertIsNotNone( ipopo.get_instance_details(module_A.BASIC_INSTANCE), "Component from module A not started") # Component of module B must be absent self.assertRaises(ValueError, ipopo.get_instance_details, module_B.BASIC_INSTANCE)
def testConstantGetReference(self): """ Tests the ipopo.constants.get_service_reference() method """ # Try without the bundle self.assertIsNone(constants.get_ipopo_svc_ref(self.context), "iPOPO service found while not installed.") # Install the iPOPO bundle ipopo_svc = install_ipopo(self.framework) # Test the method result ref, svc = constants.get_ipopo_svc_ref(self.context) self.assertIsNotNone(ref, "Invalid service reference") self.assertIs(svc, ipopo_svc, "Found a different service.") # Stop the iPOPO bundle ref.get_bundle().stop() # Ensure the service is not accessible anymore self.assertIsNone(constants.get_ipopo_svc_ref(self.context), "iPOPO service found while stopped.") # Uninstall the bundle ref.get_bundle().uninstall() # Ensure the service is not accessible anymore self.assertIsNone(constants.get_ipopo_svc_ref(self.context), "iPOPO service found while stopped.")
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.ipopo = install_ipopo(self.framework)
def testInstantiateKillBeforeIPopo(self): """ Tests if the component is correctly instantiated when added and killed when removed """ # Add the component to the waiting list self.waiting.add(FACTORY_A, NAME_A) # Install iPOPO ipopo = install_ipopo(self.framework) # The component must be absent self.assertFalse(ipopo.is_registered_instance(NAME_A), "Instance already there") # Install the component bundle install_bundle(self.framework) # The instance must have been started self.assertTrue(ipopo.is_registered_instance(NAME_A), "Instance not there") # Remove the component from the waiting list self.waiting.remove(NAME_A) # The instance must have been kill self.assertFalse(ipopo.is_registered_instance(NAME_A), "Instance still there")
def testDuplicatedFactory(self): """ Tests the behavior of iPOPO if two bundles provide the same factory. """ # Start the framework self.framework = FrameworkFactory.get_framework() self.framework.start() ipopo = install_ipopo(self.framework) # Install bundles: both provide a "basic-component-factory" factory # and instantiate a component (both with different names) module_A = install_bundle(self.framework, "tests.ipopo.ipopo_bundle") module_B = install_bundle(self.framework, "tests.ipopo.ipopo_bundle_copy") # Ensure that the module providing the factory is the correct one self.assertIs( module_A, ipopo.get_factory_bundle(module_A.BASIC_FACTORY).get_module(), "Duplicated factory is not provided by the first module") self.assertIs( module_A, ipopo.get_factory_bundle(module_B.BASIC_FACTORY).get_module(), "Duplicated factory is not provided by the first module") # Component of module A must be there self.assertIsNotNone( ipopo.get_instance_details(module_A.BASIC_INSTANCE), "Component from module A not started") # Component of module B must be absent self.assertRaises(ValueError, ipopo.get_instance_details, module_B.BASIC_INSTANCE)
def testHandlerAfterBundle(self): """ Test a single component life cycle """ # Install iPOPO ipopo = install_ipopo(self.framework) # Install the component bundle install_bundle(self.framework, COMPONENT_BUNDLE_NAME) # The component must be absent self.assertFalse(ipopo.is_registered_instance(COMPONENT_NAME), "Instance already there") # Install the handler install_bundle(self.framework, HANDLER_BUNDLE_NAME) # The component must have been validated self.assertTrue(ipopo.is_registered_instance(COMPONENT_NAME), "Instance has not been validated") # Remove the handler self.framework.get_bundle_by_name(HANDLER_BUNDLE_NAME).stop() # The component must be absent self.assertFalse(ipopo.is_registered_instance(COMPONENT_NAME), "Instance still there") # Remove the component self.framework.get_bundle_by_name(COMPONENT_BUNDLE_NAME).stop()
def testWaitingFactoryDetails(self): """ Tests the "handlers" entry of factory details dictionary """ # Install iPOPO ipopo = install_ipopo(self.framework) # Install the component bundle install_bundle(self.framework, COMPONENT_BUNDLE_NAME) # Find the component in the waiting list waiting = ipopo.get_waiting_components() for name, factory, missing in waiting: if name == COMPONENT_NAME: break else: # Component not found self.fail("Component not in the waiting handler list") # Check the missing handler self.assertCountEqual(missing, [HANDLER_ID]) # The instance details must fail (instance not ready) self.assertRaises(ValueError, ipopo.get_instance_details, COMPONENT_NAME) # Get factory details factory_details = ipopo.get_factory_details(factory) # The handlers details must be present self.assertIn(HANDLER_ID, factory_details["handlers"]) # Install the handler install_bundle(self.framework, HANDLER_BUNDLE_NAME) # The component is not waiting anymore waiting = ipopo.get_waiting_components() for name, factory, missing in waiting: if name == COMPONENT_NAME: self.fail("Component is still waiting for its handler") # Get instance details (must not fail) ipopo.get_instance_details(COMPONENT_NAME) # Remove the handler self.framework.get_bundle_by_name(HANDLER_BUNDLE_NAME).stop() # The component must be back in the waiting list waiting = ipopo.get_waiting_components() for name, factory, missing in waiting: if name == COMPONENT_NAME: break else: # Component not found self.fail("Component not in the waiting handler list") # The instance details must fail (instance not ready) self.assertRaises(ValueError, ipopo.get_instance_details, COMPONENT_NAME)
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.ipopo = install_ipopo(self.framework) self.module = install_bundle(self.framework, "tests.ipopo.ipopo_fields_bundle")
def testDuplicateHandler(self): """ Duplicated handler must be ignored """ # Install iPOPO ipopo = install_ipopo(self.framework) # Install the original handler install_bundle(self.framework, HANDLER_BUNDLE_NAME) # Register the duplicated handler properties = {constants.PROP_HANDLER_ID: HANDLER_ID} # Register the handler factory service context = self.framework.get_bundle_context() dummy_handler = DummyHandlerFactory() svc_reg = context.register_service( constants.SERVICE_IPOPO_HANDLER_FACTORY, dummy_handler, properties) # Install the component bundle install_bundle(self.framework, COMPONENT_BUNDLE_NAME) # The component is not waiting waiting = ipopo.get_waiting_components() for info in waiting: if info[0] == COMPONENT_NAME: self.fail("Component is waiting for its handler") # The duplicated handler must not have been called self.assertFalse(dummy_handler.called, "Second handler has been used") # Remove the original handler self.framework.get_bundle_by_name(HANDLER_BUNDLE_NAME).stop() # The component is not waiting waiting = ipopo.get_waiting_components() for info in waiting: if info[0] == COMPONENT_NAME: self.fail("Component is waiting for its handler") # The duplicated handler must have been called self.assertTrue(dummy_handler.called, "Second handler has not been used") # Unregister the duplicated handler svc_reg.unregister() # The component must be back in the waiting list waiting = ipopo.get_waiting_components() for info in waiting: if info[0] == COMPONENT_NAME: break else: # Component not found self.fail("Component not in the waiting handler list")
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.ipopo = install_ipopo(self.framework) # Install the test bundle self.module = install_bundle(self.framework)
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.ipopo = install_ipopo(self.framework) # Compatibility issue if sys.version_info[0] < 3: self.assertCountEqual = self.assertItemsEqual
def testInsideFramework(self): """ Tests the behavior of a manipulated class attributes """ # Start the framework self.framework = FrameworkFactory.get_framework() self.framework.start() ipopo = install_ipopo(self.framework) module = install_bundle(self.framework) # Instantiate the test class instance = module.ComponentFactoryA() # Check fields presence and values self.assertTrue(instance._test_ctrl, "Default service controller is On") self.assertIsNone(instance._req_1, "Requirement is not None") self.assertEqual(instance.prop_1, 10, "Constructor property value lost") self.assertEqual(instance.usable, True, "Incorrect property value") del instance # Instantiate component A (validated) instance = ipopo.instantiate(module.FACTORY_A, NAME_A) # Check fields presence and values self.assertTrue(instance._test_ctrl, "Default service controller is On") self.assertIsNone(instance._req_1, "Requirement is not None") self.assertIsNone(instance.prop_1, "Default property value is None") self.assertEqual(instance.usable, True, "Incorrect property value") instance.prop_1 = 42 instance.usable = False self.assertEqual(instance.prop_1, 42, "Property value not modified") self.assertEqual(instance.usable, False, "Property value not modified") # Set A usable again instance.change(True) self.assertEqual(instance.usable, True, "Property value not modified")
def testInsideFramework(self): """ Tests the behavior of a manipulated class attributes """ # Start the framework self.framework = FrameworkFactory.get_framework() self.framework.start() ipopo = install_ipopo(self.framework) module = install_bundle(self.framework) # Instantiate the test class instance = module.ComponentFactoryA() # Check fields presence and values self.assertTrue( instance._test_ctrl, "Default service controller is On") self.assertIsNone(instance._req_1, "Requirement is not None") self.assertEqual( instance.prop_1, 10, "Constructor property value lost") self.assertEqual(instance.usable, True, "Incorrect property value") del instance # Instantiate component A (validated) instance = ipopo.instantiate(module.FACTORY_A, NAME_A) # Check fields presence and values self.assertTrue( instance._test_ctrl, "Default service controller is On") self.assertIsNone(instance._req_1, "Requirement is not None") self.assertIsNone(instance.prop_1, "Default property value is None") self.assertEqual(instance.usable, True, "Incorrect property value") instance.prop_1 = 42 instance.usable = False self.assertEqual(instance.prop_1, 42, "Property value not modified") self.assertEqual(instance.usable, False, "Property value not modified") # Set A usable again instance.change(True) self.assertEqual(instance.usable, True, "Property value not modified")
def testInstantiateConflict(self): """ Try to instantiate a component with a name already used """ # Install iPOPO ipopo = install_ipopo(self.framework) # Install the component bundle module = install_bundle(self.framework) # The component must be present self.assertTrue(ipopo.is_registered_instance(module.BASIC_INSTANCE), "Auto-instance not yet there") # This addition must not fail, but must be logger self.waiting.add(module.BASIC_FACTORY, module.BASIC_INSTANCE) # The original instance must still be there self.assertTrue(ipopo.is_registered_instance(module.BASIC_INSTANCE), "Instance has been killed")
def test_ipopo_start_installed(self): """ Tests if iPOPO starts instances of already installed bundles """ # Uninstall the iPOPO bundle ipopo_bundle = self.framework.get_bundle_by_name("pelix.ipopo.core") ipopo_bundle.uninstall() self.ipopo = None # Install the test bundle module = install_bundle(self.framework) # Install iPOPO self.ipopo = install_ipopo(self.framework) # Test if the automatic instance is there self.assertTrue(self.ipopo.is_registered_factory(module.BASIC_FACTORY), "Factory not registered") self.assertTrue( self.ipopo.is_registered_instance(module.BASIC_INSTANCE), "Component not created")
def testIPopoStartInstalled(self): """ Tests if iPOPO starts instances of already installed bundles """ # Uninstall the iPOPO bundle ipopo_bundle = self.framework.get_bundle_by_name("pelix.ipopo.core") ipopo_bundle.uninstall() self.ipopo = None # Install the test bundle module = install_bundle(self.framework) # Install iPOPO self.ipopo = install_ipopo(self.framework) # Test if the automatic instance is there self.assertTrue(self.ipopo.is_registered_factory(module.BASIC_FACTORY), "Factory not registered") self.assertTrue( self.ipopo.is_registered_instance(module.BASIC_INSTANCE), "Component not created")