Search in sources :

Example 1 with GeneratedFile

use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.

the class CustomDashboardGeneratedUtilsTest method loadCustomGrafanaDashboardsList.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
void loadCustomGrafanaDashboardsList(KogitoBuildContext.Builder contextBuilder) {
    final KogitoBuildContext context = contextBuilder.withAppPaths(AppPaths.fromTestDir(new File(".").toPath())).build();
    Collection<GeneratedFile> retrieved = CustomDashboardGeneratedUtils.loadCustomGrafanaDashboardsList(context);
    assertNotNull(retrieved);
    // 2 = valid *.json files inside src/test/META-INF/dashboards
    assertEquals(2, retrieved.size());
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) File(java.io.File) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with GeneratedFile

use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.

the class CustomDashboardGeneratedUtilsTest method addToGeneratedFiles.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
void addToGeneratedFiles(KogitoBuildContext.Builder contextBuilder) {
    final KogitoBuildContext context = contextBuilder.withAppPaths(AppPaths.fromTestDir(new File(".").toPath())).build();
    Collection<CollectedResource> collectedResources = CollectedResourceProducer.fromPaths(context.getAppPaths().getPaths());
    Map<String, List<Resource>> dashboardJsonsMap = CustomDashboardGeneratedUtils.getMappedJsons(collectedResources);
    Collection<GeneratedFile> toPopulate = new ArrayList<>();
    CustomDashboardGeneratedUtils.addToGeneratedFiles(dashboardJsonsMap.get(OPERATIONAL_DASHBOARD_PREFIX), toPopulate, operationalFunction, OPERATIONAL_DASHBOARD_PREFIX);
    assertEquals(dashboardJsonsMap.get(OPERATIONAL_DASHBOARD_PREFIX).size(), toPopulate.size());
    String sourcePath = dashboardJsonsMap.get(OPERATIONAL_DASHBOARD_PREFIX).get(0).getSourcePath();
    String originalFileName = sourcePath.substring(sourcePath.lastIndexOf(File.separator) + 1);
    validateGeneratedFile(toPopulate.iterator().next(), OPERATIONAL_DASHBOARD_PREFIX, originalFileName);
    toPopulate = new ArrayList<>();
    CustomDashboardGeneratedUtils.addToGeneratedFiles(dashboardJsonsMap.get(DOMAIN_DASHBOARD_PREFIX), toPopulate, domainFunction, DOMAIN_DASHBOARD_PREFIX);
    assertEquals(dashboardJsonsMap.get(DOMAIN_DASHBOARD_PREFIX).size(), toPopulate.size());
    sourcePath = dashboardJsonsMap.get(DOMAIN_DASHBOARD_PREFIX).get(0).getSourcePath();
    originalFileName = sourcePath.substring(sourcePath.lastIndexOf(File.separator) + 1);
    validateGeneratedFile(toPopulate.iterator().next(), DOMAIN_DASHBOARD_PREFIX, originalFileName);
}
Also used : CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) ArrayList(java.util.ArrayList) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with GeneratedFile

use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.

the class GeneratedFileValidationTest method validateGeneratedFileTypes.

@Test
public void validateGeneratedFileTypes() {
    List<GeneratedFile> generatedFiles = Arrays.asList(new GeneratedFile(GeneratedFileType.SOURCE, "myPath1", ""), new GeneratedFile(GeneratedFileType.INTERNAL_RESOURCE, "myPath2", ""), new GeneratedFile(GeneratedFileType.COMPILED_CLASS, "myPath3", ""), new GeneratedFile(GeneratedFileType.STATIC_HTTP_RESOURCE, "myPath4", ""));
    GeneratedFileValidation.validateGeneratedFileTypes(generatedFiles, Arrays.asList(GeneratedFileType.Category.SOURCE, GeneratedFileType.Category.INTERNAL_RESOURCE, GeneratedFileType.Category.STATIC_HTTP_RESOURCE, GeneratedFileType.Category.COMPILED_CLASS));
    Set<GeneratedFileType.Category> categories = Collections.singleton(GeneratedFileType.Category.SOURCE);
    Assertions.assertThatThrownBy(() -> GeneratedFileValidation.validateGeneratedFileTypes(generatedFiles, categories)).isInstanceOf(IllegalStateException.class).hasMessageContaining("myPath2").hasMessageContaining("myPath3").hasMessageContaining("myPath4");
}
Also used : GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) Test(org.junit.jupiter.api.Test)

Example 4 with GeneratedFile

use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.

the class DashboardGeneratedFileUtils method operational.

public static List<GeneratedFile> operational(String operationalDashboard, String name) {
    List<GeneratedFile> generatedFiles = new ArrayList<>();
    generatedFiles.add(new GeneratedFile(DASHBOARD_TYPE, STATIC_RESOURCE_PATH + OPERATIONAL_DASHBOARD_PREFIX + name.replaceAll(DASHBOARD_NAME_REGEX, ""), operationalDashboard));
    return generatedFiles;
}
Also used : ArrayList(java.util.ArrayList) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile)

Example 5 with GeneratedFile

use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.

the class DashboardGeneratedFileUtils method domain.

public static List<GeneratedFile> domain(String domainDashboard, String name) {
    List<GeneratedFile> generatedFiles = new ArrayList<>();
    generatedFiles.add(new GeneratedFile(DASHBOARD_TYPE, STATIC_RESOURCE_PATH + DOMAIN_DASHBOARD_PREFIX + name.replaceAll(DASHBOARD_NAME_REGEX, ""), domainDashboard));
    return generatedFiles;
}
Also used : ArrayList(java.util.ArrayList) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile)

Aggregations

GeneratedFile (org.kie.kogito.codegen.api.GeneratedFile)83 KogitoBuildContext (org.kie.kogito.codegen.api.context.KogitoBuildContext)43 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 MethodSource (org.junit.jupiter.params.provider.MethodSource)36 CompilationUnit (com.github.javaparser.ast.CompilationUnit)32 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)26 ArrayList (java.util.ArrayList)24 Collection (java.util.Collection)23 List (java.util.List)21 Optional (java.util.Optional)18 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 Collectors (java.util.stream.Collectors)15 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)14 Collections (java.util.Collections)14 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)12 File (java.io.File)12 Test (org.junit.jupiter.api.Test)11 GeneratedFileType (org.kie.kogito.codegen.api.GeneratedFileType)11 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)10 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)9