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);
}
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));
}
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();
}
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));
}
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));
}
Aggregations