# Path: f8a_worker/data_normalizer/java.py
# class MavenDataNormalizer(AbstractDataNormalizer):
#     """Maven data normalizer.
# 
#     This normalizer handles data extracted from pom.xml files by mercator-go.
#     """
# 
#     _key_map = (
#         ('name',),
#         ('version',),
#         ('description',),
#         ('url', 'homepage'),
#         ('licenses', 'declared_licenses')
#     )
# 
#     def __init__(self, mercator_json):
#         """Initialize function."""
#         pom = mercator_json.get('pom.xml', {})
#         super().__init__(pom)
# 
#     def normalize(self):
#         """Normalize output from Mercator for pom.xml (Maven)."""
#         if not self._raw_data:
#             return {}
# 
#         if self._data['name'] is None:
#             self._data['name'] = "{}:{}".format(
#                 self._raw_data.get('groupId'), self._raw_data.get('artifactId')
#             )
#         # dependencies with scope 'compile' and 'runtime' are needed at runtime;
#         # dependencies with scope 'provided' are not necessarily runtime dependencies,
#         # but they are commonly used for example in web applications
#         dependencies_dict = self._raw_data.get('dependencies', {}).get('compile', {})
#         dependencies_dict.update(self._raw_data.get('dependencies', {}).get('runtime', {}))
#         dependencies_dict.update(self._raw_data.get('dependencies', {}).get('provided', {}))
#         # dependencies with scope 'test' are only needed for testing;
#         dev_dependencies_dict = self._raw_data.get('dependencies', {}).get('test', {})
# 
#         self._data['dependencies'] = [
#             k.rstrip(':') + ' ' + v for k, v in dependencies_dict.items()
#         ]
# 
#         self._data['devel_dependencies'] = [
#             k.rstrip(':') + ' ' + v for k, v in dev_dependencies_dict.items()
#         ]
# 
#         # handle code_repository
#         if 'scm_url' in self._raw_data:
#             # TODO: there's no way we can tell 100 % what the type is, but we could
#             #  try to handle at least some cases, e.g. github will always be git etc
#             repo_type = 'git' if parse_gh_repo(self._raw_data['scm_url']) else 'unknown'
#             self._data['code_repository'] = {
#                 'url': self._raw_data['scm_url'], 'type': repo_type
#             }
# 
#         return self._data


import pytest
from f8a_worker.data_normalizer import MavenDataNormalizer
      'devel_dependencies': sorted(['t:t 0'])}),
    ({'pom.xml': {'scm_url': 'git@github.com:fabric8-analytics/fabric8-analytics-worker.git'}},
     {'code_repository': {'url':
                          'git@github.com:fabric8-analytics/fabric8-analytics-worker.git',
                          'type': 'git'}}),
    ({'pom.xml': {'licenses': ['ASL 2.0', 'MIT']}},
     {'declared_licenses': ['ASL 2.0', 'MIT']}),
    ({'pom.xml': {'description': 'Ich bin ein Bayesianer'}},
     {'description': 'Ich bin ein Bayesianer'}),
    ({'pom.xml': {'url': 'https://github.com/fabric8-analytics/fabric8-analytics-worker'}},
     {'homepage': 'https://github.com/fabric8-analytics/fabric8-analytics-worker'}),
])
def test_transforming_java_data(data, expected):
    """Test normalizing of pom.xml data."""
    transformed_data = MavenDataNormalizer(data).normalize()
    for key, value in expected.items():
        assert key in transformed_data
        transformed_value = sorted(transformed_data[key]) \
            if isinstance(transformed_data[key], list) else transformed_data[key]
        assert transformed_value == value, transformed_data


def test_constructor_error_input():
    """Test MavenDataNormalizer constructor for error input."""
    dn = MavenDataNormalizer({})
    assert dn is not None


def test_normalize_error_input():
    """Test MavenDataNormalizer constructor for error input."""

# Path: f8a_worker/data_normalizer/java.py
# class MavenDataNormalizer(AbstractDataNormalizer):
#     """Maven data normalizer.
# 
#     This normalizer handles data extracted from pom.xml files by mercator-go.
#     """
# 
#     _key_map = (
#         ('name',),
#         ('version',),
#         ('description',),
#         ('url', 'homepage'),
#         ('licenses', 'declared_licenses')
#     )
# 
#     def __init__(self, mercator_json):
#         """Initialize function."""
#         pom = mercator_json.get('pom.xml', {})
#         super().__init__(pom)
# 
#     def normalize(self):
#         """Normalize output from Mercator for pom.xml (Maven)."""
#         if not self._raw_data:
#             return {}
# 
#         if self._data['name'] is None:
#             self._data['name'] = "{}:{}".format(
#                 self._raw_data.get('groupId'), self._raw_data.get('artifactId')
#             )
#         # dependencies with scope 'compile' and 'runtime' are needed at runtime;
#         # dependencies with scope 'provided' are not necessarily runtime dependencies,
#         # but they are commonly used for example in web applications
#         dependencies_dict = self._raw_data.get('dependencies', {}).get('compile', {})
#         dependencies_dict.update(self._raw_data.get('dependencies', {}).get('runtime', {}))
#         dependencies_dict.update(self._raw_data.get('dependencies', {}).get('provided', {}))
#         # dependencies with scope 'test' are only needed for testing;
#         dev_dependencies_dict = self._raw_data.get('dependencies', {}).get('test', {})
# 
#         self._data['dependencies'] = [
#             k.rstrip(':') + ' ' + v for k, v in dependencies_dict.items()
#         ]
# 
#         self._data['devel_dependencies'] = [
#             k.rstrip(':') + ' ' + v for k, v in dev_dependencies_dict.items()
#         ]
# 
#         # handle code_repository
#         if 'scm_url' in self._raw_data:
#             # TODO: there's no way we can tell 100 % what the type is, but we could
#             #  try to handle at least some cases, e.g. github will always be git etc
#             repo_type = 'git' if parse_gh_repo(self._raw_data['scm_url']) else 'unknown'
#             self._data['code_repository'] = {
#                 'url': self._raw_data['scm_url'], 'type': repo_type
#             }
# 
#         return self._data


# Path: tests/data_normalizer/test_java.py
import pytest
from f8a_worker.data_normalizer import MavenDataNormalizer

      'devel_dependencies': sorted(['t:t 0'])}),
    ({'pom.xml': {'scm_url': 'git@github.com:fabric8-analytics/fabric8-analytics-worker.git'}},
     {'code_repository': {'url':
                          'git@github.com:fabric8-analytics/fabric8-analytics-worker.git',
                          'type': 'git'}}),
    ({'pom.xml': {'licenses': ['ASL 2.0', 'MIT']}},
     {'declared_licenses': ['ASL 2.0', 'MIT']}),
    ({'pom.xml': {'description': 'Ich bin ein Bayesianer'}},
     {'description': 'Ich bin ein Bayesianer'}),
    ({'pom.xml': {'url': 'https://github.com/fabric8-analytics/fabric8-analytics-worker'}},
     {'homepage': 'https://github.com/fabric8-analytics/fabric8-analytics-worker'}),
])
def test_transforming_java_data(data, expected):
    """Test normalizing of pom.xml data."""
    transformed_data = MavenDataNormalizer(data).normalize()
    for key, value in expected.items():
        assert key in transformed_data
        transformed_value = sorted(transformed_data[key]) \
            if isinstance(transformed_data[key], list) else transformed_data[key]
        assert transformed_value == value, transformed_data


def test_constructor_error_input():
    """Test MavenDataNormalizer constructor for error input."""
    dn = MavenDataNormalizer({})
    assert dn is not None


def test_normalize_error_input():
    """Test MavenDataNormalizer constructor for error input."""

    dn = MavenDataNormalizer({})