def test_xp_create_then_delete_xs(self):

        # xp needs an xs first
        exchange_space = ExchangeSpace(name="doink")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_point = ExchangePoint(name="hammer")
        epid = self.ems.create_exchange_point(exchange_point, esid)

        # delete xs
        self.ems.delete_exchange_space(esid)

        # should no longer have an association
        xslist2, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                           PRED.hasExchangePoint,
                                           epid,
                                           id_only=True)
        self.assertEquals(len(xslist2), 0)

        # TEST ONLY: have to clean up the xp or we leave junk on the broker
        # we have to do it manually because the xs is gone
        #self.ems.delete_exchange_point(epid)
        # @TODO: reaching into ex manager for transport is clunky
        xs = exchange.ExchangeSpace(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_space.name)
        xp = exchange.ExchangePoint(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_point.name, xs, 'ttree')
        self.container.ex_manager.delete_xp(xp, use_ems=False)
    def delete_exchange_point(self, exchange_point_id=''):
        """Delete an existing exchange point resource.

        @param exchange_point_id    str
        @throws NotFound    object with specified id does not exist
        """
        exchange_point = self.clients.resource_registry.read(exchange_point_id)
        if not exchange_point:
            raise NotFound("Exchange Point %s does not exist" %
                           exchange_point_id)

        # get associated XS first
        exchange_space_list, assoc_list = self.clients.resource_registry.find_subjects(
            RT.ExchangeSpace, PRED.hasExchangePoint, exchange_point_id)
        if not len(exchange_space_list) == 1:
            raise NotFound(
                "Associated Exchange Space to Exchange Point %s does not exist"
                % exchange_point_id)

        exchange_space = exchange_space_list[0]

        # delete association to XS
        for assoc in assoc_list:
            self.clients.resource_registry.delete_association(assoc._id)

        # delete from RR
        self.clients.resource_registry.delete(exchange_point_id)

        # call container API
        xs = exchange.ExchangeSpace(self.container.ex_manager,
                                    exchange_space.name)
        xp = exchange.ExchangePoint(self.container.ex_manager,
                                    exchange_point.name, xs, 'ttree')
        self.container.ex_manager.delete_xp(xp, use_ems=False)