### Question:
CodeGenerator { public void generate() { JsonNode metaJsons = metaReader.getMetaJson(); if (metaJsons.isArray()) { MetadataManager metaManager = MetadataManager.load(metaJsons); for (JsonNode metaNode : metaJsons) { EntityGenerator entityGenerator = new EntityGenerator(metaNode, packagePrefix, metaManager); entityGenerator.build(); output(entityGenerator.getEntity()); } } } CodeGenerator(MetaJsonReader reader, String outputDirectory, String packagePrefix); void generate(); final static String DEFAULT_PACKAGE_PREFIX; }### Answer:
@Test public void testGenerate() { String folder = EntityGeneratorTest.class.getResource("/").getFile(); MetaJsonReader reader = new OnlineMetaJsonReader("http: CodeGenerator generator = new CodeGenerator(reader, folder, "test.cloud"); generator.generate(); URL packageUrl = CodeGeneratorTest.class.getResource("/test/cloud/"); Assert.assertNotNull(packageUrl); File f = new File(packageUrl.getPath()); Assert.assertTrue(f.exists()); }
@Test public void testGenerate2() { String folder = EntityGeneratorTest.class.getResource("/").getFile(); MetaJsonReader reader = new OnlineMetaJsonReader("http: "user:fjao"); CodeGenerator generator = new CodeGenerator(reader, folder, "test.cloud"); generator.generate(); URL packageUrl = CodeGeneratorTest.class.getResource("/test/cloud/"); Assert.assertNotNull(packageUrl); File f = new File(packageUrl.getPath()); Assert.assertTrue(f.exists()); }
@Test public void testGenerate3() { String metaFolder = EntityGeneratorTest.class.getResource("/raptor-paas.json").getFile(); String genFolder = EntityGeneratorTest.class.getResource("/").getFile(); MetaJsonReader reader = new FileMetaJsonReader(metaFolder); CodeGenerator generator = new CodeGenerator(reader, genFolder, "test.filegen.cloud"); generator.generate(); URL packageUrl = CodeGeneratorTest.class.getResource("/test/filegen/cloud/"); Assert.assertNotNull(packageUrl); File f = new File(packageUrl.getPath()); Assert.assertTrue(f.exists()); File[] javaFiles = f.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(".java"); } }); Assert.assertTrue(javaFiles.length > 0); Assert.assertEquals(10, javaFiles.length); }
@Test public void testGenerate4() { String metaFolder = EntityGeneratorTest.class.getResource("/").getFile(); String genFolder = EntityGeneratorTest.class.getResource("/").getFile(); MetaJsonReader reader = new FileMetaJsonReader(metaFolder); CodeGenerator generator = new CodeGenerator(reader, genFolder, "test2.filegen.cloud"); generator.generate(); URL packageUrl = CodeGeneratorTest.class.getResource("/test2/filegen/cloud/"); Assert.assertNotNull(packageUrl); File f = new File(packageUrl.getPath()); Assert.assertTrue(f.exists()); File[] javaFiles = f.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(".java"); } }); Assert.assertTrue(javaFiles.length > 0); Assert.assertEquals(10, javaFiles.length); }
@Test public void testPackageGeneration() { String metaPackage = "com.ebay.cloud.cms.model.metadata"; String genFolder = EntityGeneratorTest.class.getResource("/").getFile(); MetaJsonReader reader = new FileMetaJsonReader(metaPackage); CodeGenerator generator = new CodeGenerator(reader, genFolder, "test3.packagegenerate"); generator.generate(); URL packageUrl = CodeGeneratorTest.class.getResource("/test3/packagegenerate/"); Assert.assertNotNull(packageUrl); File f = new File(packageUrl.getPath()); Assert.assertTrue(f.exists()); File[] javaFiles = f.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(".java"); } }); Assert.assertTrue(javaFiles.length > 0); Assert.assertEquals(73, javaFiles.length); }