import json

from oneview_redfish_toolkit.api.composition_service import CompositionService
from oneview_redfish_toolkit.tests.base_test import BaseTest


class TestCompositionService(BaseTest):
    """Tests for CompositionService class"""

    def setUp(self):
        """Tests preparation"""

        # Loading CompositionService mockup result
        with open(
            'oneview_redfish_toolkit/mockups/redfish/CompositionService.json'
        ) as f:
            self.composition_service_mockup = json.load(f)

    def test_class_instantiation(self):
        # Tests if class is correctly instantiated

        try:
            compostion_service = CompositionService()
        except Exception as e:
            self.fail("Failed to instantiate CompositionService class."
                      " Error: {}".format(e))
        self.assertIsInstance(compostion_service, CompositionService)

    def test_serialize(self):
        # Tests the serialize function result against known result

        try:
            compostion_service = CompositionService()
        except Exception as e:
            self.fail("Failed to instantiate CompositionService class."
                      " Error: {}".format(e))

        try:
            expected_result = json.loads(compostion_service.serialize())
        except Exception as e:
            self.fail("Failed to serialize. Error: ".format(e))

        self.assertEqualMockup(self.composition_service_mockup,
                               expected_result)
