Search in sources :

Example 16 with KogitoBuildContext

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

the class PredictionCodegenTest method isEmpty.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void isEmpty(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext context = contextBuilder.build();
    PredictionCodegen emptyCodeGenerator = PredictionCodegen.ofCollectedResources(context, Collections.emptyList());
    assertThat(emptyCodeGenerator.isEmpty()).isTrue();
    assertThat(emptyCodeGenerator.isEnabled()).isFalse();
    Collection<GeneratedFile> emptyGeneratedFiles = emptyCodeGenerator.generate();
    assertThat(emptyGeneratedFiles.size()).isEqualTo(0);
    PredictionCodegen codeGenerator = PredictionCodegen.ofCollectedResources(context, CollectedResourceProducer.fromFiles(BASE_PATH, REGRESSION_FULL_SOURCE.toFile()));
    assertThat(codeGenerator.isEmpty()).isFalse();
    assertThat(codeGenerator.isEnabled()).isTrue();
    Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
    assertThat(generatedFiles.size()).isGreaterThanOrEqualTo(1);
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with KogitoBuildContext

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

the class PredictionCodegenTest method generateAllFilesScorecard.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
void generateAllFilesScorecard(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext context = contextBuilder.build();
    PredictionCodegen codeGenerator = PredictionCodegen.ofCollectedResources(context, CollectedResourceProducer.fromFiles(BASE_PATH, SCORECARD_FULL_SOURCE.toFile()));
    generateAllFiles(context, codeGenerator, 5, 3, 1, false);
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 18 with KogitoBuildContext

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

the class PredictionCodegenTest method generateAllFilesRegression.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
void generateAllFilesRegression(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext context = contextBuilder.build();
    PredictionCodegen codeGenerator = PredictionCodegen.ofCollectedResources(context, CollectedResourceProducer.fromFiles(BASE_PATH, REGRESSION_FULL_SOURCE.toFile()));
    generateAllFiles(context, codeGenerator, 5, 3, 1, false);
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 19 with KogitoBuildContext

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

the class RuleUnitCompilerIT method checckPropertyReactvity.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void checckPropertyReactvity(boolean usePropertyReactivity) throws Exception {
    // KOGITO-5101
    KogitoBuildContext context = newContext();
    if (!usePropertyReactivity) {
        context.setApplicationProperty(PropertySpecificOption.PROPERTY_NAME, PropertySpecificOption.DISABLED.toString());
    }
    Application application = createApplication(context, "org/kie/kogito/codegen/unit/RuleUnitNoPropReact.drl");
    AdultUnit adults = new AdultUnit();
    Person mario = new Person("Mario", 45);
    adults.getPersons().add(mario);
    RuleUnit<AdultUnit> unit = application.get(RuleUnits.class).create(AdultUnit.class);
    RuleUnitInstance<AdultUnit> instance = unit.createInstance(adults);
    instance.fire();
    assertEquals(usePropertyReactivity ? 46 : 50, mario.getAge());
}
Also used : RuleUnits(org.kie.kogito.rules.RuleUnits) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) AdultUnit(org.kie.kogito.codegen.unit.AdultUnit) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with KogitoBuildContext

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

the class PathResolverTest method verifyFileResolver.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
void verifyFileResolver(final KogitoBuildContext.Builder contextBuilder) {
    final String resource = "specs/__files/petstore.json";
    final KogitoBuildContext context = contextBuilder.build();
    final String classpathPath = requireNonNull(getClass().getClassLoader().getResource(resource)).getPath();
    final OpenApiSpecDescriptor openApiSpecDescriptor = new OpenApiSpecDescriptor("file://" + classpathPath);
    final PathResolver resolver = PathResolverFactory.newResolver(openApiSpecDescriptor, context);
    assertThat(resolver).isInstanceOf(FileResolver.class);
    final String path = resolver.resolve(openApiSpecDescriptor);
    this.assertResolverPath(path);
}
Also used : OpenApiSpecDescriptor(org.kie.kogito.codegen.openapi.client.OpenApiSpecDescriptor) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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