ModelBuilderImpl extends KnowledgeBuilderImpl { protected PackageModel getPackageModel(PackageDescr packageDescr, PackageRegistry pkgRegistry, String pkgName) { return packageModels.computeIfAbsent(pkgName, s -> { final DialectCompiletimeRegistry dialectCompiletimeRegistry = pkgRegistry.getDialectCompiletimeRegistry(); return packageDescr.getPreferredPkgUUID() .map(pkgUUI -> new PackageModel(pkgName, this.getBuilderConfiguration(), isPattern, dialectCompiletimeRegistry, exprIdGenerator, pkgUUI)) .orElse(new PackageModel(releaseId, pkgName, this.getBuilderConfiguration(), isPattern, dialectCompiletimeRegistry, exprIdGenerator)); }); } ModelBuilderImpl(Function<PackageModel, T> sourcesGenerator, KnowledgeBuilderConfigurationImpl configuration, ReleaseId releaseId, boolean isPattern, boolean oneClassPerRule); @Override void buildPackages(Collection<CompositePackageDescr> packages); @Override void addPackage(final PackageDescr packageDescr); @Override void postBuild(); static void registerType( TypeResolver typeResolver, Class<?> clazz); Collection<T> getPackageSources();  }
@Test public void getPackageModelWithPkgUUID() { String pkgUUID = generateUUID(); PackageDescr packageDescr = getPackageDescr(pkgUUID); PackageModel retrieved = modelBuilder.getPackageModel(packageDescr, packageRegistry, internalKnowledgePackage.getName()); assertNotNull(retrieved); assertEquals(pkgUUID, retrieved.getPackageUUID()); }
@Test public void getPackageModelWithoutPkgUUID() { PackageDescr packageDescr = getPackageDescr(null); PackageModel retrieved = modelBuilder.getPackageModel(packageDescr, packageRegistry, internalKnowledgePackage.getName()); assertNotNull(retrieved); String expected = getPkgUUID(RELEASE_ID, internalKnowledgePackage.getName()); assertEquals(expected, retrieved.getPackageUUID()); }