Search in sources :

Example 11 with KogitoBuildContext

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

the class RuleUnitCompilerIT method createApplication.

private Application createApplication(SessionType sessionType, String... drls) throws Exception {
    KogitoBuildContext context = newContext();
    context.setApplicationProperty(KOGITO_USE_LEGACY_SESSION, "" + (sessionType == SessionType.LEGACY));
    return createApplication(context, drls);
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext)

Example 12 with KogitoBuildContext

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

the class PredictionCodegenTest method generateThrowsExceptionWithInvalidModel.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
void generateThrowsExceptionWithInvalidModel(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext context = contextBuilder.build();
    KiePMMLModel nullNameMock = buildInvalidMockedModel(null);
    assertThrows(IllegalArgumentException.class, buildMockedGenerateExecutable(context, nullNameMock));
    KiePMMLModel emptyNameMock = buildInvalidMockedModel(EMPTY);
    assertThrows(IllegalArgumentException.class, buildMockedGenerateExecutable(context, emptyNameMock));
    KiePMMLModel invalidClassMock = buildInvalidMockedModel(MOCK);
    assertThrows(IllegalStateException.class, buildMockedGenerateExecutable(context, invalidClassMock));
}
Also used : KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with KogitoBuildContext

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

the class OpenApiClientServerlessWorkflowIT method openApiSpecInClasspath.

@ParameterizedTest
@ValueSource(strings = { "openapi/petstore-classpath.sw.json" })
public void openApiSpecInClasspath(final String resource) {
    final KogitoBuildContext context = this.newContext();
    final Collection<CollectedResource> resources = toCollectedResources(Collections.singletonList(resource));
    // OpenApi Generation
    final OpenApiClientCodegen openApiClientCodegen = OpenApiClientCodegen.ofCollectedResources(context, resources);
    assertThat(openApiClientCodegen.getOpenAPISpecResources()).isNotEmpty();
    Collection<GeneratedFile> openApiGeneratedFiles = openApiClientCodegen.generate();
    assertThat(openApiGeneratedFiles).isNotEmpty();
    assertThat(context.getContextAttribute(ContextAttributesConstants.OPENAPI_DESCRIPTORS, List.class)).isNotEmpty();
    // Process Code Generation
    final ProcessCodegen processCodegen = ProcessCodegen.ofCollectedResources(context, resources);
    Collection<GeneratedFile> processGeneratedFiles = processCodegen.generate();
    assertThat(processGeneratedFiles).isNotEmpty();
}
Also used : CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) OpenApiClientCodegen(org.kie.kogito.codegen.openapi.client.OpenApiClientCodegen) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with KogitoBuildContext

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

the class PMMLRestResourceGeneratorTest method setSpringDescriptiveOASAnnotations.

@Test
void setSpringDescriptiveOASAnnotations() {
    ClassOrInterfaceDeclaration springTemplate = getClassOrInterfaceDeclaration(SpringBootKogitoBuildContext.builder().build());
    KogitoBuildContext springContext = SpringBootKogitoBuildContext.builder().build();
    PMMLRestResourceGenerator springPMMLRestResourceGenerator = new PMMLRestResourceGenerator(springContext, KIE_PMML_MODEL, APP_CANONICAL_NAME);
    NodeList<AnnotationExpr> annotations = springTemplate.getMethodsByName("descriptive").get(0).getAnnotations();
    springPMMLRestResourceGenerator.setSpringOASAnnotations(annotations, INPUT_REF, OUTPUT_REF);
    String retrieved = springTemplate.toString();
    String expected = String.format("@%1$s(%2$s = @io.swagger.v3.oas.annotations.media.Content(mediaType = " + "\"application/json\", " + "%3$s = @%4$s(%5$s = \"%6$s\")), description = \"PMML input\")", SPRING_REQUEST_BODY, CONTENT, SCHEMA, SPRING_SCHEMA, REF, INPUT_REF);
    assertTrue(retrieved.contains(expected));
    expected = String.format("@%1$s(%2$s = @io.swagger.v3.oas.annotations.media.Content(mediaType = " + "\"application/json\", " + "%3$s = @%4$s(%5$s = \"%6$s\")), description = \"PMML full output\")", SPRING_API_RESPONSE, CONTENT, SCHEMA, SPRING_SCHEMA, REF, OUTPUT_REF);
    assertTrue(retrieved.contains(expected));
}
Also used : AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) SpringBootKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.SpringBootKogitoBuildContext) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) QuarkusKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext) Test(org.junit.jupiter.api.Test)

Example 15 with KogitoBuildContext

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

the class PMMLRestResourceGeneratorTest method setSpringResultOASAnnotations.

@Test
void setSpringResultOASAnnotations() {
    ClassOrInterfaceDeclaration springTemplate = getClassOrInterfaceDeclaration(SpringBootKogitoBuildContext.builder().build());
    KogitoBuildContext springContext = SpringBootKogitoBuildContext.builder().build();
    PMMLRestResourceGenerator springPMMLRestResourceGenerator = new PMMLRestResourceGenerator(springContext, KIE_PMML_MODEL, APP_CANONICAL_NAME);
    NodeList<AnnotationExpr> annotations = springTemplate.getMethodsByName("result").get(0).getAnnotations();
    springPMMLRestResourceGenerator.setSpringOASAnnotations(annotations, INPUT_REF, RESULT_REF);
    String retrieved = springTemplate.toString();
    String expected = String.format("@%1$s(%2$s = @io.swagger.v3.oas.annotations.media.Content(mediaType = " + "\"application/json\", " + "%3$s = @%4$s(%5$s = \"%6$s\")), description = \"PMML input\")", SPRING_REQUEST_BODY, CONTENT, SCHEMA, SPRING_SCHEMA, REF, INPUT_REF);
    assertTrue(retrieved.contains(expected));
    expected = String.format("@%1$s(%2$s = @io.swagger.v3.oas.annotations.media.Content(mediaType = " + "\"application/json\", " + "%3$s = @%4$s(%5$s = \"%6$s\")), description = \"PMML result\")", SPRING_API_RESPONSE, CONTENT, SCHEMA, SPRING_SCHEMA, REF, RESULT_REF);
    assertTrue(retrieved.contains(expected));
}
Also used : AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) SpringBootKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.SpringBootKogitoBuildContext) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) QuarkusKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext) Test(org.junit.jupiter.api.Test)

Aggregations

KogitoBuildContext (org.kie.kogito.codegen.api.context.KogitoBuildContext)83 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)53 MethodSource (org.junit.jupiter.params.provider.MethodSource)51 GeneratedFile (org.kie.kogito.codegen.api.GeneratedFile)41 Collection (java.util.Collection)20 Test (org.junit.jupiter.api.Test)19 List (java.util.List)17 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)17 QuarkusKogitoBuildContext (org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext)17 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)16 CompilationUnit (com.github.javaparser.ast.CompilationUnit)15 Collectors (java.util.stream.Collectors)14 Collections (java.util.Collections)11 Optional (java.util.Optional)11 Paths (java.nio.file.Paths)10 Path (java.nio.file.Path)9 GeneratedFileType (org.kie.kogito.codegen.api.GeneratedFileType)9 SpringBootKogitoBuildContext (org.kie.kogito.codegen.api.context.impl.SpringBootKogitoBuildContext)9 CollectedResource (org.kie.kogito.codegen.api.io.CollectedResource)9 ReflectionMarshallerGenerator (org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator)8