Skip to content

Commit

Permalink
- apply AdditionalStaticResourceBuildItem for static resource
Browse files Browse the repository at this point in the history
- fix test cases
- temporarily disabled validateAvailableCapabilities
  • Loading branch information
tkobayas committed Nov 29, 2021
1 parent 3273607 commit b86c4ea
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;

@QuarkusTest
@QuarkusIntegrationTest
class BasicAddIT {

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

import static io.restassured.RestAssured.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

@QuarkusTest
@QuarkusIntegrationTest
class DSCoercionIT {

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

Expand All @@ -26,7 +26,7 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

@QuarkusTest
@QuarkusIntegrationTest
class ElementAtIndexIT {

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.junit.jupiter.api.Test;

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

import static io.restassured.RestAssured.given;
Expand All @@ -29,7 +29,7 @@
* Part of build certification process. Please do not remove.
* Smoke test of kogito end-to-end scenarios.
*/
@QuarkusTest
@QuarkusIntegrationTest
public class FaceMaskIT {

@Test
Expand Down Expand Up @@ -140,4 +140,4 @@ public void testSurgicalMaskNeededInCity() {
.statusCode(200)
.body("'Face Mask Needed'", equalTo("Surgical Mask"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.junit.jupiter.api.Test;

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

import static io.restassured.RestAssured.given;
Expand All @@ -30,7 +30,7 @@
* Part of build certification process. Please do not remove.
* Smoke test of kogito end-to-end scenarios.
*/
@QuarkusTest
@QuarkusIntegrationTest
public class HospitalsIT {

@Test
Expand Down Expand Up @@ -121,4 +121,4 @@ public void testDiabetes() {
"National Hospital",
"University Hospital")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.junit.jupiter.api.Test;

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

import static io.restassured.RestAssured.given;
Expand All @@ -27,7 +27,7 @@
* Part of build certification process. Please do not remove.
* Smoke test of kogito end-to-end scenarios.
*/
@QuarkusTest
@QuarkusIntegrationTest
public class HospitalsStatusIT {

@Test
Expand All @@ -45,4 +45,4 @@ public void testHospitalStatus() {
.statusCode(200)
.body("'Current Status'", equalTo("red"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.path.json.config.JsonPathConfig;
Expand All @@ -28,7 +28,7 @@
import static io.restassured.config.JsonConfig.jsonConfig;
import static org.hamcrest.Matchers.closeTo;

@QuarkusTest
@QuarkusIntegrationTest
class JavaFNctxIT {

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.junit.jupiter.api.Test;

import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.PathItem;
Expand All @@ -32,7 +32,7 @@
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.greaterThan;

@QuarkusTest
@QuarkusIntegrationTest
class OASIT {

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

import static org.hamcrest.CoreMatchers.is;

@QuarkusTest
@QuarkusIntegrationTest
class OneOfEachTypeIT {

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

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

import static io.restassured.RestAssured.given;

@QuarkusTest
@QuarkusIntegrationTest
public class CustomEndpointIT {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;

@QuarkusTest
@QuarkusIntegrationTest
public class DMNIT {

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<artifactId>quarkus-arc-deployment</artifactId>
<version>${version.io.quarkus}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment-spi</artifactId>
<version>${version.io.quarkus}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.index.IndexingUtil;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceBuildItem;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceBuildItem;
import io.quarkus.vertx.http.deployment.spi.AdditionalStaticResourceBuildItem;

import static org.kie.kogito.quarkus.common.deployment.KogitoQuarkusResourceUtils.*;

Expand Down Expand Up @@ -72,13 +73,16 @@ public List<KogitoGeneratedClassesBuildItem> generateModel(
Capabilities capabilities,
BuildProducer<GeneratedBeanBuildItem> generatedBeans,
BuildProducer<GeneratedJaxRsResourceBuildItem> jaxrsProducer,
BuildProducer<AdditionalStaticResourceBuildItem> staticResProducer,
BuildProducer<NativeImageResourceBuildItem> resource,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<GeneratedResourceBuildItem> genResBI) throws IOException {

// configure the application generator
KogitoBuildContext context = kogitoBuildContext(root.getPaths(), combinedIndexBuildItem.getIndex(), curateOutcomeBuildItem.getApplicationModel().getAppArtifact());

//validateAvailableCapabilities(context, capabilities);

Collection<GeneratedFile> generatedFiles = generateFiles(context);

// The HotReloadSupportClass has to be generated only during the first model generation
Expand All @@ -100,7 +104,7 @@ public List<KogitoGeneratedClassesBuildItem> generateModel(

registerDataEventsForReflection(optionalIndex.map(KogitoGeneratedClassesBuildItem::getIndexedClasses), context, reflectiveClass);

registerResources(generatedFiles, resource, genResBI);
registerResources(generatedFiles, staticResProducer, resource, genResBI);

return optionalIndex
.map(Collections::singletonList)
Expand All @@ -118,11 +122,12 @@ void validateAvailableCapabilities(KogitoBuildContext context, Capabilities capa
LOGGER.info("Disabling Kogito REST generation because OptaPlanner extension is available, specify `kogito.generate.rest = true` to re-enable it");
}

if (!hasRestCapabilities && kogitoGenerateRest(context).orElse(true)) {
boolean kogitoGenerateRestEnabled = kogitoGenerateRest(context).orElse(true);
if (!hasRestCapabilities && kogitoGenerateRestEnabled) {
throw new MissingRestCapabilityException();
}
if (capabilities.isPresent(Capability.RESTEASY) && capabilities.isMissing(Capability.SERVLET)) {

if (capabilities.isPresent(Capability.RESTEASY) && capabilities.isMissing(Capability.SERVLET) && kogitoGenerateRestEnabled) {
throw new MissingServletCapabilityException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.maven.dependency.Dependency;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.vertx.http.deployment.spi.AdditionalStaticResourceBuildItem;

import static java.util.stream.Collectors.toList;

Expand All @@ -59,6 +60,7 @@ public class KogitoQuarkusResourceUtils {
static final String HOT_RELOAD_SUPPORT_CLASS = "HotReloadSupportClass";
static final String HOT_RELOAD_SUPPORT_FQN = HOT_RELOAD_SUPPORT_PACKAGE + "." + HOT_RELOAD_SUPPORT_CLASS;
static final String HOT_RELOAD_SUPPORT_PATH = HOT_RELOAD_SUPPORT_FQN.replace('.', '/');
static final String STATIC_RESOURCE_DIR = "META-INF/resources";

private KogitoQuarkusResourceUtils() {
// utility class
Expand Down Expand Up @@ -135,10 +137,15 @@ public static void dumpFilesToDisk(AppPaths appPaths, Collection<GeneratedFile>
}

public static void registerResources(Collection<GeneratedFile> generatedFiles,
BuildProducer<AdditionalStaticResourceBuildItem> staticResProducer,
BuildProducer<NativeImageResourceBuildItem> resource,
BuildProducer<GeneratedResourceBuildItem> genResBI) {
for (GeneratedFile f : generatedFiles) {
if (f.category() == GeneratedFileType.Category.RESOURCE) {
if (f.relativePath().startsWith(STATIC_RESOURCE_DIR)) {
String resoucePath = f.relativePath().substring(STATIC_RESOURCE_DIR.length());
staticResProducer.produce(new AdditionalStaticResourceBuildItem(resoucePath, false));
}
genResBI.produce(new GeneratedResourceBuildItem(f.relativePath(), f.contents()));
resource.produce(new NativeImageResourceBuildItem(f.relativePath()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
public class MissingRestCapabilityException extends RuntimeException {
public MissingRestCapabilityException() {
super("No REST capability detected! \n" +
"Add the RestEasy (quarkus-resteasy) and RestEasy Jackson (quarkus-resteasy-jackson) extensions if you want " +
"Add the RestEasy (quarkus-resteasy), RestEasy Jackson (quarkus-resteasy-jackson) and Undertow (quarkus-undertow) extensions if you want " +
"Kogito to generate REST endpoints automatically. \n" +
"RestEasy Reactive extension is currently not supported: see https://issues.redhat.com/browse/KOGITO-6131 \n" +
"If you want to use RestEasy Reactive, add RestEasy Reactive (quarkus-resteasy-reactive) " +
"and RestEasy Reactive Jackson (quarkus-resteasy-reactive-jackson) extensions without Undertow extension. \n"
+
"You may also disable automated REST generation by setting `kogito.generate.rest = false`. \n" +
"You may also override this notice by setting `kogito.generate.rest = true` ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.vertx.http.deployment.spi.AdditionalStaticResourceBuildItem;

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.joining;
Expand Down Expand Up @@ -152,6 +153,7 @@ public AdditionalBeanBuildItem additionalBeans() {
public void postGenerationProcessing(
List<KogitoGeneratedClassesBuildItem> generatedKogitoClasses,
BuildProducer<GeneratedBeanBuildItem> generatedBeans,
BuildProducer<AdditionalStaticResourceBuildItem> staticResProducer,
BuildProducer<NativeImageResourceBuildItem> resource,
BuildProducer<NativeImageResourcePatternsBuildItem> resourcePatterns,
BuildProducer<GeneratedResourceBuildItem> genResBI,
Expand Down Expand Up @@ -184,7 +186,7 @@ public void postGenerationProcessing(
dumpFilesToDisk(context.getAppPaths(), generatedFiles);

// register resources to the Quarkus environment
registerResources(generatedFiles, resource, genResBI);
registerResources(generatedFiles, staticResProducer, resource, genResBI);

registerProcessSVG(context, resource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void validateAvailableCapabilitiesWithOptaPlannerNoRest() {
@Test
public void validateAvailableCapabilitiesWithOptaPlannerWithRest() {
KogitoBuildContext context = QuarkusKogitoBuildContext.builder().build();
Capabilities capabilities = capabilities(Capability.RESTEASY, Capability.RESTEASY_JSON_JACKSON, "org.optaplanner.optaplanner-quarkus");
Capabilities capabilities = capabilities(Capability.RESTEASY, Capability.RESTEASY_JSON_JACKSON, Capability.SERVLET, "org.optaplanner.optaplanner-quarkus");
KogitoAssetsProcessor processor = new KogitoAssetsProcessor();

assertThat(context.getApplicationProperty(KogitoBuildContext.KOGITO_GENERATE_REST)).isEmpty();
Expand All @@ -54,7 +54,7 @@ public void validateAvailableCapabilitiesWithOptaPlannerWithRest() {
@Test
public void validateAvailableCapabilitiesWithoutOptaPlanner() {
KogitoBuildContext context = QuarkusKogitoBuildContext.builder().build();
Capabilities capabilities = capabilities(Capability.RESTEASY, Capability.RESTEASY_JSON_JACKSON);
Capabilities capabilities = capabilities(Capability.RESTEASY, Capability.RESTEASY_JSON_JACKSON, Capability.SERVLET);
KogitoAssetsProcessor processor = new KogitoAssetsProcessor();

assertThat(context.getApplicationProperty(KogitoBuildContext.KOGITO_GENERATE_REST)).isEmpty();
Expand All @@ -77,7 +77,10 @@ public void validateAvailableCapabilitiesRest() {
assertThatThrownBy(() -> processor.validateAvailableCapabilities(context, capabilities(Capability.RESTEASY_JSON_JACKSON)))
.isInstanceOf(MissingRestCapabilityException.class);

processor.validateAvailableCapabilities(context, capabilities(Capability.RESTEASY, Capability.RESTEASY_JSON_JACKSON));
assertThatThrownBy(() -> processor.validateAvailableCapabilities(context, capabilities(Capability.RESTEASY, Capability.RESTEASY_JSON_JACKSON)))
.isInstanceOf(MissingServletCapabilityException.class);

processor.validateAvailableCapabilities(context, capabilities(Capability.RESTEASY, Capability.RESTEASY_JSON_JACKSON, Capability.SERVLET));
assertThat(context.getApplicationProperty(KogitoBuildContext.KOGITO_GENERATE_REST)).isEmpty();
}

Expand Down

0 comments on commit b86c4ea

Please sign in to comment.