Skip to content

Commit

Permalink
KOGITO-6116: Not possible to override kogito.service.url parameter on… (
Browse files Browse the repository at this point in the history
apache#2246)

* KOGITO-6116: Not possible to override kogito.service.url parameter on native image

* Split config into runtime and build time

Co-authored-by: Cristiano Nicolai <570894+cristianonicolai@users.noreply.github.com>
  • Loading branch information
nmirasch and cristianonicolai committed Jun 14, 2022
1 parent 0fa3fbc commit 723bf73
Show file tree
Hide file tree
Showing 21 changed files with 343 additions and 141 deletions.
4 changes: 4 additions & 0 deletions integration-tests/integration-tests-quarkus-processes/pom.xml
Expand Up @@ -73,6 +73,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging-kafka</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.reactivemessaging.http</groupId>
<artifactId>quarkus-reactive-messaging-http</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.kie.kogito.Addons;
import org.kie.kogito.codegen.api.ConfigGenerator;
import org.kie.kogito.codegen.api.context.KogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext;
import org.kie.kogito.codegen.api.template.InvalidTemplateException;
import org.kie.kogito.codegen.api.template.TemplatedGenerator;

Expand Down Expand Up @@ -56,7 +57,9 @@ public ApplicationConfigGenerator(KogitoBuildContext context) {
.build(context, CLASS_NAME);
this.context = context;

this.configGenerators.add(new ConfigBeanGenerator(context));
if (!QuarkusKogitoBuildContext.CONTEXT_NAME.equals(context.name())) {
this.configGenerators.add(new ConfigBeanGenerator(context));
}
}

public ApplicationConfigGenerator addConfigGenerator(ConfigGenerator configGenerator) {
Expand Down

This file was deleted.

Expand Up @@ -32,7 +32,7 @@
public class GlobalObjectMapper implements ObjectMapperCustomizer {

@Inject
ConfigBean configBean;
org.kie.kogito.conf.ConfigBean configBean;

public void customize(ObjectMapper mapper) {
if (!configBean.failOnEmptyBean()) {
Expand Down
Expand Up @@ -15,11 +15,16 @@
*/
package org.kie.kogito.codegen.core;

import java.util.Collection;

import org.drools.codegen.common.GeneratedFile;
import org.junit.jupiter.api.Test;
import org.kie.kogito.codegen.api.AddonsConfig;
import org.kie.kogito.codegen.api.ConfigGenerator;
import org.kie.kogito.codegen.api.context.KogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.JavaKogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.SpringBootKogitoBuildContext;
import org.mockito.Mockito;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -50,4 +55,40 @@ public void withConfigNull() {
.isSameAs(generator);
}

@Test
public void configBeanGenerationInJavaContextTest() {
final ApplicationConfigGenerator generator = new ApplicationConfigGenerator(context);
Collection<GeneratedFile> files = generator.generate();
assertThat(containsGeneratedFile("ConfigBean", files)).isTrue();
assertThat(containsGeneratedFile("ApplicationConfig", files)).isTrue();
}

@Test
public void configBeanGenerationInSpringContextTest() {
KogitoBuildContext context = SpringBootKogitoBuildContext.builder()
.withPackageName("org.kie.kogito.test")
.withAddonsConfig(AddonsConfig.DEFAULT)
.build();
final ApplicationConfigGenerator generator = new ApplicationConfigGenerator(context);
Collection<GeneratedFile> files = generator.generate();
assertThat(containsGeneratedFile("ConfigBean", files)).isTrue();
assertThat(containsGeneratedFile("ApplicationConfig", files)).isTrue();
}

@Test
public void avoidConfigBeanGenerationInQuarkusContextTest() {
KogitoBuildContext context = QuarkusKogitoBuildContext.builder()
.withPackageName("org.kie.kogito.test")
.withAddonsConfig(AddonsConfig.DEFAULT)
.build();
final ApplicationConfigGenerator generator = new ApplicationConfigGenerator(context);
Collection<GeneratedFile> files = generator.generate();
assertThat(containsGeneratedFile("ConfigBean", files)).isFalse();
assertThat(containsGeneratedFile("ApplicationConfig", files)).isTrue();
}

private boolean containsGeneratedFile(String className, Collection<GeneratedFile> files) {
return files.stream().anyMatch(generatedFile -> generatedFile.relativePath().endsWith(className + ".java"));
}

}
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.kogito.KogitoGAV;
import org.kie.kogito.codegen.api.context.KogitoBuildContext;
import org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.expr.MethodCallExpr;
Expand All @@ -32,19 +33,21 @@ public class ConfigBeanGeneratorTest {
@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void generate(KogitoBuildContext.Builder contextBuilder) {
// null GAV
assertThat(contextBuilder.build().getGAV()).isEmpty();
Optional<MethodCallExpr> setGavNull = getGavMethodCallExpr(contextBuilder);
setGavNull.ifPresent(methodCallExpr -> assertThat(methodCallExpr.toString()).contains("null"));

// with GAV
KogitoGAV kogitoGAV = new KogitoGAV("groupId", "artifactId", "version");
contextBuilder.withGAV(kogitoGAV);
Optional<MethodCallExpr> setGav = getGavMethodCallExpr(contextBuilder);
setGav.ifPresent(methodCallExpr -> assertThat(methodCallExpr.toString())
.contains(kogitoGAV.getGroupId())
.contains(kogitoGAV.getArtifactId())
.contains(kogitoGAV.getVersion()));
if (!QuarkusKogitoBuildContext.CONTEXT_NAME.equals(contextBuilder.build().name())) {
// null GAV
assertThat(contextBuilder.build().getGAV()).isEmpty();
Optional<MethodCallExpr> setGavNull = getGavMethodCallExpr(contextBuilder);
setGavNull.ifPresent(methodCallExpr -> assertThat(methodCallExpr.toString()).contains("null"));

// with GAV
KogitoGAV kogitoGAV = new KogitoGAV("groupId", "artifactId", "version");
contextBuilder.withGAV(kogitoGAV);
Optional<MethodCallExpr> setGav = getGavMethodCallExpr(contextBuilder);
setGav.ifPresent(methodCallExpr -> assertThat(methodCallExpr.toString())
.contains(kogitoGAV.getGroupId())
.contains(kogitoGAV.getArtifactId())
.contains(kogitoGAV.getVersion()));
}
}

private Optional<MethodCallExpr> getGavMethodCallExpr(KogitoBuildContext.Builder contextBuilder) {
Expand Down
Expand Up @@ -36,7 +36,7 @@ public ProcessConfig(
Instance<ProcessEventListenerConfig> processEventListenerConfigs,
Instance<ProcessEventListener> processEventListeners,
Instance<EventPublisher> eventPublishers,
ConfigBean configBean,
org.kie.kogito.conf.ConfigBean configBean,
Instance<UnitOfWorkEventListener> unitOfWorkEventListeners) {

super(workItemHandlerConfig,
Expand Down
Expand Up @@ -36,7 +36,7 @@ public ProcessConfig(
List<ProcessEventListenerConfig> processEventListenerConfigs,
List<ProcessEventListener> processEventListeners,
List<EventPublisher> eventPublishers,
ConfigBean configBean,
org.kie.kogito.conf.ConfigBean configBean,
List<UnitOfWorkEventListener> unitOfWorkEventListeners) {

super(workItemHandlerConfig,
Expand Down
83 changes: 83 additions & 0 deletions quarkus/addons/explainability/integration-tests/pom.xml
@@ -0,0 +1,83 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-explainability-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>kogito-addons-quarkus-explainability-it</artifactId>
<name>Kogito Add-On Explainability - Integration tests</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-quarkus-decisions</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-explainability</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>

</project>
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
* Copyright 2022 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@
import org.kie.kogito.conf.StaticConfigBean;
import org.kie.kogito.explainability.model.PredictOutput;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.common.mapper.TypeRef;
import io.restassured.http.ContentType;

Expand All @@ -40,7 +40,7 @@
import static org.kie.kogito.explainability.Constants.MODEL_NAME;
import static org.kie.kogito.explainability.Constants.MODEL_NAMESPACE;

@QuarkusTest
@QuarkusIntegrationTest
public class QuarkusExplainableResourceIT {

@Singleton
Expand Down Expand Up @@ -147,6 +147,6 @@ void explainServiceFail() {
.then()
.statusCode(Response.Status.BAD_REQUEST.getStatusCode())
.body(Matchers.isA(String.class))
.body(Matchers.containsString("Model " + unknownResourceId + " not found."));
.body(Matchers.containsString("DMN model 'model' not found with namespace 'unknown'"));
}
}
1 change: 1 addition & 0 deletions quarkus/addons/explainability/pom.xml
Expand Up @@ -16,6 +16,7 @@
<modules>
<module>runtime</module>
<module>deployment</module>
<module>integration-tests</module>
</modules>

</project>

This file was deleted.

2 changes: 1 addition & 1 deletion quarkus/addons/tracing-decision/integration-tests/pom.xml
Expand Up @@ -8,7 +8,7 @@
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>kogito-addons-quarkus-tracing-decision-it</artifactId>
<name>Integration tests for the Tracing Decision Add-On (Quarkus)</name>
<name>Kogito Add-On Tracing Decision - Integration tests</name>

<dependencies>
<dependency>
Expand Down

0 comments on commit 723bf73

Please sign in to comment.