private ClassModel getClassModel( LibraryModelBuilder expectedModelBuilder, PackageResource packageResource, String className) { for (PackageModelBuilder packageModelBuilder : expectedModelBuilder.getAllPackages()) { if (packageModelBuilder.buildModel().getResource().equals(packageResource)) return packageModelBuilder.findClass(className).buildModel(); } fail("could not find " + packageResource + "." + className); return null; }
@Test public void testHappyPath() throws IOException, URISyntaxException, InternalException { LibraryModelBuilder libraryModelBuilder = new LibraryModelBuilder( new LibraryVersionResource( "com.pongasoft", "com.pongasoft.kiwidoc.builder.doclet", "1.0")); SourceCodeParser sourceCodeParser = new SourceCodeParser(); FileObject sources = VFS.getManager().toFileObject(new File("../com.pongasoft.kiwidoc.testdata/src/main/java")); sourceCodeParser.parseSources( libraryModelBuilder, sources, "overview.html", null, Collections.<FileObject>emptyList()); for (PackageModelBuilder packageModelBuilder : libraryModelBuilder.getAllPackages()) { for (ClassModelBuilder classModelBuilder : packageModelBuilder.getAllClasses()) { System.out.println(classModelBuilder.buildModel().getGenericTypeVariables()); } } // sourceCodeParser.parse(new // File("../com.pongasoft.kiwidoc.testdata/src/main/java/com/pongasoft/kiwidoc/testdata/pubdir1/I1G.java")); }
private void readLibrary( LibraryModelBuilder expectedModelBuilder, KiwidocLibraryStore kiwidocLibraryStore, LibraryVersionResource libraryVersion) throws StoreException, NoSuchContentException, IOException { LibraryVersionModel libraryVersionModel = (LibraryVersionModel) kiwidocLibraryStore.loadContent(libraryVersion); LibraryVersionModel elvm = expectedModelBuilder.buildModel(); Map<PackageResource, PackageModel> expectedPackages = new HashMap<PackageResource, PackageModel>(); for (SimplePackageModel packageModel : elvm.getAllPackages()) { PackageModelBuilder packageModelBuilder = expectedModelBuilder.findPackage(packageModel.getName()); expectedPackages.put(packageModel.getResource(), packageModelBuilder.buildModel()); } for (SimplePackageModel packageModel : libraryVersionModel.getAllPackages()) { PackageModel expectedPackageModel = expectedPackages.remove(packageModel.getResource()); Map<String, ClassDefinitionModel> expectedClasses = new HashMap<String, ClassDefinitionModel>(); for (ClassDefinitionModel cdm : expectedPackageModel.getAllClasses()) { expectedClasses.put(cdm.getName(), cdm); } PackageModel loadedPackageModel = (PackageModel) kiwidocLibraryStore.loadContent(packageModel.getResource()); loadedPackageModel = kiwidocLibraryStore.resolve(DependenciesModel.NO_DEPENDENCIES, loadedPackageModel); assertEquals(expectedClasses.size(), loadedPackageModel.getAllClasses().size()); for (ClassDefinitionModel cdm : loadedPackageModel.getAllClasses()) { ClassDefinitionModel expectedClassDefinitionModel = expectedClasses.get(cdm.getName()); assertEquals(expectedClassDefinitionModel.getType().toString(), cdm.getType().toString()); assertEquals(expectedClassDefinitionModel.getClassResource(), cdm.getClassResource()); assertEquals(expectedClassDefinitionModel.getAccess(), cdm.getAccess()); } for (String className : packageModel.getAllClasses()) { expectedClasses.remove(className); ClassModel expectedClassModel = getClassModel(expectedModelBuilder, loadedPackageModel.getResource(), className); ClassModel classModel = (ClassModel) kiwidocLibraryStore.loadContent( new ClassResource(loadedPackageModel.getResource(), className)); checkDoc(expectedClassModel, classModel); assertEquals(expectedClassModel.getAllMethods().size(), classModel.getAllMethods().size()); for (MethodModel methodModel : classModel.getAllMethods()) { MethodModel expectedMethodModel = expectedClassModel.findMethod(methodModel.getMemberName()); checkDoc(expectedMethodModel, methodModel); } InheritanceModel inheritanceModel = kiwidocLibraryStore.resolveWithInheritance( DependenciesModel.NO_DEPENDENCIES, classModel); inheritanceModel = inheritanceModel.inheritDoc(); assertNotNull(inheritanceModel); } assertTrue(expectedClasses.isEmpty()); } assertTrue(expectedPackages.isEmpty()); }
@Test public void testWithTestData() throws Exception { System.out.println(System.getProperty("testdata.build.dir")); System.out.println(System.getProperty("testdata.src.dir")); FileObject classes = _manager.resolveFile(new File(System.getProperty("testdata.build.dir")).toURI().toString()); // FileObject classes = null; FileObject javadoc = null; FileObject sources = _manager.resolveFile(new File(System.getProperty("testdata.src.dir")).toURI().toString()); // FileObject sources = null; LibraryVersionResource libraryVersionResource = new LibraryVersionResource("com.pongasoft", "com.pongasoft.kiwidoc.testdata", "1.0.0"); FileObject store = _manager.resolveFile("ram://testWithTestData/kiwidoc"); KiwidocLibraryStore kiwidocLibraryStore = new KiwidocLibraryStoreImpl(new ContentHandlersImpl(store)); KiwidocBuilder builder = new KiwidocBuilder(); KiwidocBuilder.Library library = new KiwidocBuilder.Library(); library.libraryVersionResource = libraryVersionResource; library.classes = classes; library.javadoc = javadoc; library.sources = sources; LibraryModelBuilder modelBuilder = builder.buildKiwidoc(library); assertEquals(5, modelBuilder.getJdkVersion()); LibraryVersionResource computedLibraryVersionResource = kiwidocLibraryStore.storeLibrary(modelBuilder); assertEquals( libraryVersionResource.getOrganisation(), computedLibraryVersionResource.getOrganisation()); assertEquals(libraryVersionResource.getName(), computedLibraryVersionResource.getName()); assertEquals(libraryVersionResource.getVersion(), computedLibraryVersionResource.getVersion()); // System.out.println(IOUtils.asString(store)); ClassModel classModel = kiwidocLibraryStore.loadContent( new ClassResource( new PackageResource( libraryVersionResource, "com.pongasoft.kiwidoc.testdata.pubdir1"), "I1G")); RepositoryModel repository = kiwidocLibraryStore.loadContent(RepositoryResource.INSTANCE); assertEquals(1, repository.getOrganisationResources().size()); assertEquals( libraryVersionResource.getOrganisationResource(), repository.getOrganisationResources().iterator().next()); readLibrary(modelBuilder, kiwidocLibraryStore, libraryVersionResource); classModel = kiwidocLibraryStore.loadContent( new ClassResource( new PackageResource( libraryVersionResource, "com.pongasoft.kiwidoc.testdata.pubdir1"), "Pub1Class3")); MethodModel method = classModel.findMethod("method1(Ljava/lang/Integer;Ljava/util/List;)"); // before applying inheritance... should have the data as defined in the class assertEquals("This is the javadoc in Pub1Class3", method.getDoc().getDoc().getText()); assertEquals(1, method.getDoc().getTags().size()); assertEquals("{@inheritDoc}", method.getDoc().findReturnTag().getText()); InheritanceModel inheritanceModel = kiwidocLibraryStore.resolveWithInheritance(DependenciesModel.NO_DEPENDENCIES, classModel); inheritanceModel = inheritanceModel.inheritDoc(); method = inheritanceModel.getBaseClass().findMethod("method1(Ljava/lang/Integer;Ljava/util/List;)"); MethodModel inheritedMethod = inheritanceModel .getSuperClass() .getBaseClass() .findMethod("method1(Ljava/lang/Integer;Ljava/util/List;)"); Resource expectedOrigin = inheritedMethod.getDoc().findReturnTag().getOrigin(); // after applying inheritance... the data has been populated/replaced System.out.println(method.getDoc()); assertEquals("This is the javadoc in Pub1Class3", method.getDoc().getDoc().getText()); assertEquals(3, method.getDoc().getTags().size()); assertEquals("return value (from Pub1Class1)", method.getDoc().findReturnTag().getText()); assertEquals(expectedOrigin, method.getDoc().findReturnTag().getOrigin()); assertEquals("parameter 1", method.getDoc().findParamTag("p1").getText()); assertEquals(expectedOrigin, method.getDoc().findParamTag("p1").getOrigin()); assertEquals("parameter 2", method.getDoc().findParamTag("p2").getText()); assertEquals(expectedOrigin, method.getDoc().findParamTag("p2").getOrigin()); // superclass of Pub1Class3 is Puib1Class1 (should be resolved) assertEquals( "com.pongasoft.kiwidoc.testdata.pubdir1.Pub1Class1", inheritanceModel.getSuperClass().getBaseClass().getFQCN()); // superclass of Pub1Class1 is Object (not resolved as in this test the jdk is not present!) assertNull(inheritanceModel.getSuperClass().getSuperClass().getBaseClass()); assertEquals( "java.lang.Object", inheritanceModel.getSuperClass().getSuperClass().getBaseResource().getFqcn()); assertTrue(kiwidocLibraryStore.deleteLibraryVersion(libraryVersionResource)); repository = (RepositoryModel) kiwidocLibraryStore.loadContent(RepositoryResource.INSTANCE); assertEquals(0, repository.getOrganisationResources().size()); }