OWL2Java { public static void main(String[] args) { if (args.length == 0) { System.out.println("Syntax: OWL2Java <command> <args>. Run 'OWL2Java help' for more details"); return; } final Optional<Command> c = getCommand(args[0]); if (!c.isPresent()) { System.err .println("Invalid command " + args[0] + ", try 'OWL2Java help' for the list of available commands"); return; } final OptionParser op = c.get().parser; final OptionSet os = op.parse(args); final CliParams input = new CliParams(os); final OWL2JavaTransformer oj; switch (c.get()) { case help: if (args.length != 1) { final Optional<Command> cc = getCommand(args[1]); if (cc.isPresent()) { printHelp(cc.get()); } else { System.err.println("Invalid command " + args[0] + " " + args[1] + ", try 'OWL2Java help' for the list of available commands."); return; } } else { System.out.println("Available commands : " + Arrays.asList(Command.values())); } break; case list: if (invalidArgumentCount(input)) { break; } oj = getTransformer(input); System.out.println("Available contexts: " + oj.listContexts()); break; case transform: if (invalidArgumentCount(input)) { break; } transformOwlToJava(input); break; case vocabulary: if (invalidArgumentCount(input)) { break; } generateVocabulary(input); break; case version: System.out.println("OWL2Java version " + Constants.VERSION); break; default: System.err.println("Unknown command '" + args[0] + "', try 'OWL2Java help'."); } }  static void main(String[] args);  }
@Test public void vocabularyCommandGeneratesVocabularyFromICs() throws Exception { this.targetDir = TestUtils.getTempDirectory(); final String packageName = ""; final String[] args = new String[]{"vocabulary", TestUtils.IC_ONTOLOGY_IRI, "-m", mappingFilePath, "-p", packageName, "-c", TestUtils.CONTEXT, "-d", targetDir.getAbsolutePath()}; OWL2Java.main(args); final List<String> fileNames = Arrays.asList(targetDir.list()); assertEquals(1, fileNames.size()); assertEquals(VOCABULARY_FILE, fileNames.get(0)); }
@Test public void transformGeneratesClassesAndVocabularyFromICs() throws Exception { this.targetDir = TestUtils.getTempDirectory(); final String packageName = "cz.cvut.kbss.jopa.owl2java"; final String[] args = new String[]{"transform", TestUtils.IC_ONTOLOGY_IRI, "-m", mappingFilePath, "-p", packageName, "-c", TestUtils.CONTEXT, "-d", targetDir.getAbsolutePath()}; OWL2Java.main(args); assertTrue(targetDir.list().length > 0); }
@Test public void transformPrintsErrorAndQuitsWhenContextIsMissing() throws Exception { this.targetDir = TestUtils.getTempDirectory(); final String packageName = "cz.cvut.kbss.jopa.owl2java"; final String[] args = new String[]{"transform", TestUtils.IC_ONTOLOGY_IRI, "-m", mappingFilePath, "-p", packageName, "-d", targetDir.getAbsolutePath()}; OWL2Java.main(args); assertEquals(0, targetDir.list().length); verifyErrorContent("The parameter '-[a-z]' is obligatory"); }
@Test public void transformPrintsErrorAndQuitesWhenOntologyIriIsMissing() throws Exception { this.targetDir = TestUtils.getTempDirectory(); final String packageName = "cz.cvut.kbss.jopa.owl2java"; final String[] args = new String[]{"transform", "-m", mappingFilePath, "-p", packageName, "-c", TestUtils.CONTEXT, "-d", targetDir.getAbsolutePath()}; OWL2Java.main(args); assertEquals(0, targetDir.list().length); verifyErrorContent("Exactly one ontology IRI has to be specified, got 0"); }
@Test public void transformUsesCustomJavaClassNameSpecifiedByCustomAnnotation() throws Exception { this.targetDir = TestUtils.getTempDirectory(); final String packageName = ""; final String classNameAnnotation = "http: final String className = "Company.java"; final String[] args = new String[]{"transform", TestUtils.IC_ONTOLOGY_IRI, "-m", mappingFilePath, "-p", packageName, "-c", TestUtils.CONTEXT, "-jca", classNameAnnotation, "-d", targetDir.getAbsolutePath()}; OWL2Java.main(args); final File modelDir = new File(targetDir.getAbsolutePath() + File.separator + "model"); final Set<String> fileNames = new HashSet<>(Arrays.asList(modelDir.list())); assertTrue(fileNames.contains(className)); }