@Test public void testGenerate() throws DependencyResolutionRequiredException, IOException, TimeoutException, InterruptedException { File demoPath = this.resources.getBasedir(TEST_PROJECT); ClassMaker.compile(demoPath.getCanonicalPath()); MavenProject project = mock(MavenProject.class); List<String> runtimeUrlPath = new ArrayList<>(); runtimeUrlPath.add(demoPath + File.separator + "target/classes"); Map<String, Object> config = new HashMap<>(); given(project.getRuntimeClasspathElements()).willReturn(runtimeUrlPath); config.put("classpathUrls", project.getRuntimeClasspathElements()); config.put("outputDir", "target"); config.put("contractfileType", "yaml"); DefaultContractsGenerator defaultContractsGenerator = new DefaultContractsGenerator(); defaultContractsGenerator.configure(config); try { defaultContractsGenerator.generate(); } catch (RuntimeException e) { fail("Run 'testGenerate' failed and unexpected to catch RuntimeException: " + e.getMessage()); } }
@SuppressWarnings("ResultOfMethodCallIgnored") @Override public void generate() throws RuntimeException { URL[] runtimeUrls = new URL[classpathUrls.size()]; for (int i = 0; i < classpathUrls.size(); i++) { String element = classpathUrls.get(i); try { runtimeUrls[i] = new File(element).toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Wrong element in classpath", e); } } if (!checkConfig()) { throw new IllegalArgumentException("Cannot found configuration"); } ImmediateClassLoader immediateClassLoader = new ImmediateClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader()); try { Vector allClass = getAllClass(immediateClassLoader); for (int i = 0; i < allClass.size(); i++) { Class loadClass = (Class) allClass.get(i); if (!canProcess(loadClass)) { continue; } OasGenerator oasGenerator = new OasGenerator(); OpenAPI oas = oasGenerator.generate(loadClass); if (oas == null) { continue; } String oasPretty = Yaml.pretty(oas); File outputFile = new File( outputDir + File.separator + loadClass.getSimpleName() + contractfileType .getFileSuffix()); if (!outputFile.exists()) { if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } outputFile.createNewFile(); } Files.write(Paths.get(outputFile.toURI()), oasPretty.getBytes()); } } catch (IOException e) { throw new RuntimeException(e); } }
DefaultContractsGenerator implements ContractsGenerator { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void generate() throws RuntimeException { URL[] runtimeUrls = new URL[classpathUrls.size()]; for (int i = 0; i < classpathUrls.size(); i++) { String element = classpathUrls.get(i); try { runtimeUrls[i] = new File(element).toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Wrong element in classpath", e); } } if (!checkConfig()) { throw new IllegalArgumentException("Cannot found configuration"); } ImmediateClassLoader immediateClassLoader = new ImmediateClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader()); try { Vector allClass = getAllClass(immediateClassLoader); for (int i = 0; i < allClass.size(); i++) { Class loadClass = (Class) allClass.get(i); if (!canProcess(loadClass)) { continue; } OasGenerator oasGenerator = new OasGenerator(); OpenAPI oas = oasGenerator.generate(loadClass); if (oas == null) { continue; } String oasPretty = Yaml.pretty(oas); File outputFile = new File( outputDir + File.separator + loadClass.getSimpleName() + contractfileType .getFileSuffix()); if (!outputFile.exists()) { if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } outputFile.createNewFile(); } Files.write(Paths.get(outputFile.toURI()), oasPretty.getBytes()); } } catch (IOException e) { throw new RuntimeException(e); } } }
DefaultContractsGenerator implements ContractsGenerator { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void generate() throws RuntimeException { URL[] runtimeUrls = new URL[classpathUrls.size()]; for (int i = 0; i < classpathUrls.size(); i++) { String element = classpathUrls.get(i); try { runtimeUrls[i] = new File(element).toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Wrong element in classpath", e); } } if (!checkConfig()) { throw new IllegalArgumentException("Cannot found configuration"); } ImmediateClassLoader immediateClassLoader = new ImmediateClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader()); try { Vector allClass = getAllClass(immediateClassLoader); for (int i = 0; i < allClass.size(); i++) { Class loadClass = (Class) allClass.get(i); if (!canProcess(loadClass)) { continue; } OasGenerator oasGenerator = new OasGenerator(); OpenAPI oas = oasGenerator.generate(loadClass); if (oas == null) { continue; } String oasPretty = Yaml.pretty(oas); File outputFile = new File( outputDir + File.separator + loadClass.getSimpleName() + contractfileType .getFileSuffix()); if (!outputFile.exists()) { if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } outputFile.createNewFile(); } Files.write(Paths.get(outputFile.toURI()), oasPretty.getBytes()); } } catch (IOException e) { throw new RuntimeException(e); } }  }
DefaultContractsGenerator implements ContractsGenerator { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void generate() throws RuntimeException { URL[] runtimeUrls = new URL[classpathUrls.size()]; for (int i = 0; i < classpathUrls.size(); i++) { String element = classpathUrls.get(i); try { runtimeUrls[i] = new File(element).toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Wrong element in classpath", e); } } if (!checkConfig()) { throw new IllegalArgumentException("Cannot found configuration"); } ImmediateClassLoader immediateClassLoader = new ImmediateClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader()); try { Vector allClass = getAllClass(immediateClassLoader); for (int i = 0; i < allClass.size(); i++) { Class loadClass = (Class) allClass.get(i); if (!canProcess(loadClass)) { continue; } OasGenerator oasGenerator = new OasGenerator(); OpenAPI oas = oasGenerator.generate(loadClass); if (oas == null) { continue; } String oasPretty = Yaml.pretty(oas); File outputFile = new File( outputDir + File.separator + loadClass.getSimpleName() + contractfileType .getFileSuffix()); if (!outputFile.exists()) { if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } outputFile.createNewFile(); } Files.write(Paths.get(outputFile.toURI()), oasPretty.getBytes()); } } catch (IOException e) { throw new RuntimeException(e); } }  @Override boolean canProcess(String type); @SuppressWarnings("unchecked") @Override void configure(Map<String, Object> config); @SuppressWarnings("ResultOfMethodCallIgnored") @Override void generate(); }
DefaultContractsGenerator implements ContractsGenerator { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void generate() throws RuntimeException { URL[] runtimeUrls = new URL[classpathUrls.size()]; for (int i = 0; i < classpathUrls.size(); i++) { String element = classpathUrls.get(i); try { runtimeUrls[i] = new File(element).toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Wrong element in classpath", e); } } if (!checkConfig()) { throw new IllegalArgumentException("Cannot found configuration"); } ImmediateClassLoader immediateClassLoader = new ImmediateClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader()); try { Vector allClass = getAllClass(immediateClassLoader); for (int i = 0; i < allClass.size(); i++) { Class loadClass = (Class) allClass.get(i); if (!canProcess(loadClass)) { continue; } OasGenerator oasGenerator = new OasGenerator(); OpenAPI oas = oasGenerator.generate(loadClass); if (oas == null) { continue; } String oasPretty = Yaml.pretty(oas); File outputFile = new File( outputDir + File.separator + loadClass.getSimpleName() + contractfileType .getFileSuffix()); if (!outputFile.exists()) { if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } outputFile.createNewFile(); } Files.write(Paths.get(outputFile.toURI()), oasPretty.getBytes()); } } catch (IOException e) { throw new RuntimeException(e); } }  @Override boolean canProcess(String type); @SuppressWarnings("unchecked") @Override void configure(Map<String, Object> config); @SuppressWarnings("ResultOfMethodCallIgnored") @Override void generate();  }