def MakeGen(host):
     gen = java_generator.BaseJavaGenerator({
         'name': 'fake',
         'version': 'v1',
         'rootUrl': 'https://%s/' % host,
         'servicePath': 'fake/v1',
         'ownerDomain': host,
     })
     gen.AnnotateApiForLanguage(gen.api)
     return gen
        def TestApi(api_def):
            gen = java_generator.BaseJavaGenerator(
                api_def, options={'google_api': True})
            gen.AnnotateApiForLanguage(gen.api)
            api = gen.api

            # drop the leading com
            expected = '-'.join(api.module.path.split('/')[1:])
            actual = maven_utils.GetMavenArtifactId(
                api_def['name'],
                package_path=api_def.get('packagePath'),
                canonical_name=api_def.get('canonicalName'),
                owner_domain=api_def['ownerDomain'])
            self.assertEquals(expected, actual)
    def testImportsForArray(self):
        """Test if we get the right imports for an array.

    The goal is to see that an array of a primative type which requires an
    import really works.
    """
        gen = java_generator.BaseJavaGenerator({
            'name': 'dummy',
            'version': 'v1',
            'resources': {},
            'schemas': {
                'Bar': {
                    'id': 'Bar',
                    'type': 'object',
                    'properties': {
                        'p1': {
                            'type': 'array',
                            'items': {
                                'type': 'string',
                                'format': 'uint64'
                            }
                        },
                        'p2': {
                            'type': 'array',
                            'items': {
                                'type': 'array',
                                'items': {
                                    'type': 'string',
                                    'format': 'date-time'
                                }
                            }
                        }
                    }
                }
            }
        })
        gen.AnnotateApiForLanguage(gen.api)
        found_big_integer = False
        found_date_time = False
        for schema in gen._api._schemas.values():
            import_manager = schema.values.get('importManager')
            for import_list in import_manager.ImportLists():
                for import_def in import_list:
                    print import_def
                    if import_def.find('BigInteger'):
                        found_big_integer = True
                    if import_def.find('DateTime'):
                        found_date_time = True
        self.assertTrue(found_big_integer)
        self.assertTrue(found_date_time)
 def MakeGen():
     api_def = {
         'name': 'fake',
         'version': 'v1',
         'rootUrl': 'https://www.googleapis.com/',
         'servicePath': 'fake/v1',
         'ownerDomain': 'google.com',
         'packagePath': 'my/path',
         'canonicalName': 'Canonical Name'
     }
     gen = java_generator.BaseJavaGenerator(
         api_def, options={'google_api': True})
     gen.AnnotateApiForLanguage(gen.api)
     return gen