Пример #1
0
    def testConstructor(self):
        """
        Tests the behavior of the __init__ method
        """
        # Must fail due to the lack of endpoint.id
        self.assertRaises(ValueError, beans.EndpointDescription,
                          self.svc_ref, None)

        # Must not fail
        beans.EndpointDescription(
            self.svc_ref,
            {pelix.remote.PROP_ENDPOINT_ID: "toto",
             pelix.remote.PROP_IMPORTED_CONFIGS: ['titi']})

        # Must fail due to the lack of properties
        for mandatory in (pelix.remote.PROP_ENDPOINT_ID,
                          pelix.remote.PROP_IMPORTED_CONFIGS):
            self.assertRaises(ValueError, beans.EndpointDescription,
                              None, {mandatory: "toto",
                                     pelix.constants.OBJECTCLASS: "spec",
                                     pelix.constants.SERVICE_ID: 1})

        # Must not fail
        beans.EndpointDescription(
            None,
            {pelix.remote.PROP_ENDPOINT_ID: "toto",
             pelix.remote.PROP_IMPORTED_CONFIGS: ['titi'],
             pelix.constants.OBJECTCLASS: "spec",
             pelix.constants.SERVICE_ID: 1})
Пример #2
0
    def testEdefIOTypes(self):
        """
        Tests the writing and parsing of an EndpointDescription bean with
        "complex" properties
        """
        properties = {  # Strings whitespaces are not well kept in XML
            "string": "some string just to see...",
            "int": 12,
            "float": 12.0,
            "tuple_str": ("a", "b", "c"),
            "tuple_int": (1, 2, 3),
            "tuple_float": (1.0, 2.0, 3.0),
            "list_str": ["a", "b", "c"],
            "list_int": [1, 2, 3],
            "list_float": [1.0, 2.0, 3.0],
            "set_str": set(["a", "b", "c"]),
            "set_int": set([1, 2, 3]),
            "set_float": set([1.0, 2.0, 3.0])}

        all_props = properties.copy()
        all_props[pelix.remote.PROP_ENDPOINT_ID] = 'toto'
        all_props[pelix.remote.PROP_IMPORTED_CONFIGS] = ['titi']

        # Prepare an endpoint description with different property values
        endpoint = beans.EndpointDescription(self.svc_ref, all_props)

        # Write it & parse it
        xml_string = EDEFWriter().to_string([endpoint])
        parsed = EDEFReader().parse(xml_string)[0]
        parsed_properties = parsed.get_properties()

        # Check values
        self.assertDictContainsSubset(endpoint.get_properties(),
                                      parsed_properties)
Пример #3
0
    def testEdefStringReload(self):
        """
        Tries to convert an EndpointDescription to its XML format (EDEF) and to
        reload this string
        """
        original = beans.EndpointDescription(
            self.svc_ref, {
                pelix.remote.PROP_ENDPOINT_ID: "toto",
                pelix.remote.PROP_IMPORTED_CONFIGS: ['titi'],
                pelix.constants.OBJECTCLASS: "spec"
            })

        # Write the endpoint to an XML string
        writer = EDEFWriter()
        xml_string = writer.to_string([original])

        # Parse the XML
        reader = EDEFReader()
        endpoints = reader.parse(xml_string)

        # Ensure we have a valid result
        self.assertEqual(len(endpoints), 1, "Parsed more than one endpoint")
        endpoint = endpoints[0]

        # Ensure equality
        self.assertIsNot(original, endpoint,
                         "Same exact endpoint object returned")

        self.assertEqual(original, endpoint, "Parsed endpoint is different")
        self.assertEqual(endpoint, original, "Parsed endpoint is different")

        # Ensure properties equality
        self.assertDictEqual(original.get_properties(),
                             endpoint.get_properties(),
                             "Endpoint properties changed")
Пример #4
0
 def testProperties(self):
     """
     There must be no "service.exported.*" property in an endpoint
     description
     """
     # Original endpoint description
     original = beans.EndpointDescription(
         self.svc_ref,
         {pelix.remote.PROP_ENDPOINT_ID: "toto",
          pelix.remote.PROP_IMPORTED_CONFIGS: ['titi'],
          pelix.constants.OBJECTCLASS: "spec"})
     for key in original.get_properties().keys():
         self.assertFalse(key.startswith("service.exported"),
                          "An export property has been found")