diff --git a/quarkus/pom.xml b/quarkus/pom.xml
index 09eb90d110..67356abdef 100644
--- a/quarkus/pom.xml
+++ b/quarkus/pom.xml
@@ -30,9 +30,48 @@
io.quarkus
quarkus-resteasy
+
+ io.quarkus
+ quarkus-resteasy-jackson
+ ${quarkus.version}
+
+
+ io.quarkus
+ quarkus-hibernate-orm-panache
+ ${quarkus.version}
+
+
+ io.quarkus
+ quarkus-jdbc-h2
+ ${quarkus.version}
+
+
+ org.apache.commons
+ commons-lang3
+ 3.9
+
+
+ org.projectlombok
+ lombok
+ 1.18.6
+ provided
+
io.quarkus
quarkus-junit5
+ ${quarkus.version}
+ test
+
+
+ io.quarkus
+ quarkus-junit5-mockito
+ ${quarkus.version}
+ test
+
+
+ io.quarkus
+ quarkus-test-h2
+ ${quarkus.version}
test
@@ -117,7 +156,8 @@
2.22.0
- 0.15.0
+ 1.7.0.Final
+ 5.6.0
diff --git a/quarkus/src/main/java/com/baeldung/quarkus/LibraryResource.java b/quarkus/src/main/java/com/baeldung/quarkus/LibraryResource.java
new file mode 100644
index 0000000000..88c3f0ed6e
--- /dev/null
+++ b/quarkus/src/main/java/com/baeldung/quarkus/LibraryResource.java
@@ -0,0 +1,25 @@
+package com.baeldung.quarkus;
+
+import com.baeldung.quarkus.model.Book;
+import com.baeldung.quarkus.service.LibraryService;
+
+import javax.inject.Inject;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import java.util.Set;
+
+@Path("/library")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class LibraryResource {
+
+ @Inject
+ LibraryService libraryService;
+
+ @GET
+ @Path("/book")
+ public Set findBooks(@QueryParam("query") String query) {
+ return libraryService.find(query);
+ }
+
+}
diff --git a/quarkus/src/main/java/com/baeldung/quarkus/model/Book.java b/quarkus/src/main/java/com/baeldung/quarkus/model/Book.java
new file mode 100644
index 0000000000..7d258c1934
--- /dev/null
+++ b/quarkus/src/main/java/com/baeldung/quarkus/model/Book.java
@@ -0,0 +1,17 @@
+package com.baeldung.quarkus.model;
+
+import io.quarkus.hibernate.orm.panache.PanacheEntity;
+import lombok.*;
+
+import javax.persistence.Entity;
+
+@Data
+@Entity
+@AllArgsConstructor
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor(access = AccessLevel.PROTECTED)
+public class Book extends PanacheEntity {
+ private String title;
+ private String author;
+}
+
diff --git a/quarkus/src/main/java/com/baeldung/quarkus/repository/BookRepository.java b/quarkus/src/main/java/com/baeldung/quarkus/repository/BookRepository.java
new file mode 100644
index 0000000000..b142fa569b
--- /dev/null
+++ b/quarkus/src/main/java/com/baeldung/quarkus/repository/BookRepository.java
@@ -0,0 +1,18 @@
+package com.baeldung.quarkus.repository;
+
+import com.baeldung.quarkus.model.Book;
+import io.quarkus.hibernate.orm.panache.PanacheRepository;
+
+import javax.enterprise.context.ApplicationScoped;
+import java.util.stream.Stream;
+
+import static io.quarkus.panache.common.Parameters.with;
+
+@ApplicationScoped
+public class BookRepository implements PanacheRepository {
+
+ public Stream findBy(String query) {
+ return find("author like :query or title like :query", with("query", "%"+query+"%")).stream();
+ }
+
+}
diff --git a/quarkus/src/main/java/com/baeldung/quarkus/service/LibraryService.java b/quarkus/src/main/java/com/baeldung/quarkus/service/LibraryService.java
new file mode 100644
index 0000000000..be687589bf
--- /dev/null
+++ b/quarkus/src/main/java/com/baeldung/quarkus/service/LibraryService.java
@@ -0,0 +1,28 @@
+package com.baeldung.quarkus.service;
+
+import com.baeldung.quarkus.model.Book;
+import com.baeldung.quarkus.repository.BookRepository;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.transaction.Transactional;
+import java.util.Set;
+
+import static java.util.stream.Collectors.toSet;
+
+@Transactional
+@ApplicationScoped
+public class LibraryService {
+
+ @Inject
+ BookRepository bookRepository;
+
+ public Set find(String query) {
+ if (query == null) {
+ return bookRepository.findAll().stream().collect(toSet());
+ }
+
+ return bookRepository.findBy(query).collect(toSet());
+ }
+
+}
diff --git a/quarkus/src/main/resources/application.properties b/quarkus/src/main/resources/application.properties
index 3f05d2198f..283cf763b9 100644
--- a/quarkus/src/main/resources/application.properties
+++ b/quarkus/src/main/resources/application.properties
@@ -1,3 +1,12 @@
# Configuration file
# key = value
-greeting=Good morning
\ No newline at end of file
+greeting=Good morning
+
+quarkus.datasource.db-kind = h2
+quarkus.datasource.jdbc.url = jdbc:h2:tcp://localhost/mem:test
+
+quarkus.hibernate-orm.database.generation = drop-and-create
+
+%custom-profile.quarkus.datasource.jdbc.url = jdbc:h2:file:./testdb
+
+quarkus.http.test-port=0
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/CustomLibraryResourceManualTest.java b/quarkus/src/test/java/com/baeldung/quarkus/CustomLibraryResourceManualTest.java
new file mode 100644
index 0000000000..b9175ae457
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/CustomLibraryResourceManualTest.java
@@ -0,0 +1,27 @@
+package com.baeldung.quarkus;
+
+import com.baeldung.quarkus.utils.CustomTestProfile;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.hasItems;
+
+@QuarkusTest
+@TestProfile(CustomTestProfile.class)
+class CustomLibraryResourceManualTest {
+
+ public static final String BOOKSTORE_ENDPOINT = "/custom/library/book";
+
+ @Test
+ void whenGetBooksGivenNoQuery_thenAllBooksShouldBeReturned() {
+ given().contentType(ContentType.JSON)
+ .when().get(BOOKSTORE_ENDPOINT)
+ .then().statusCode(200)
+ .body("size()", is(2))
+ .body("title", hasItems("Foundation", "Dune"));
+ }
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/LibraryHttpEndpointIntegrationTest.java b/quarkus/src/test/java/com/baeldung/quarkus/LibraryHttpEndpointIntegrationTest.java
new file mode 100644
index 0000000000..f3a30a2383
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/LibraryHttpEndpointIntegrationTest.java
@@ -0,0 +1,21 @@
+package com.baeldung.quarkus;
+
+import io.quarkus.test.common.http.TestHTTPEndpoint;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+
+@QuarkusTest
+@TestHTTPEndpoint(LibraryResource.class)
+class LibraryHttpEndpointIntegrationTest {
+
+ @Test
+ void whenGetBooks_thenShouldReturnSuccessfully() {
+ given().contentType(ContentType.JSON)
+ .when().get("book")
+ .then().statusCode(200);
+ }
+
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/LibraryResourceHttpResourceIntegrationTest.java b/quarkus/src/test/java/com/baeldung/quarkus/LibraryResourceHttpResourceIntegrationTest.java
new file mode 100644
index 0000000000..1931460aaa
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/LibraryResourceHttpResourceIntegrationTest.java
@@ -0,0 +1,40 @@
+package com.baeldung.quarkus;
+
+import io.quarkus.test.common.http.TestHTTPEndpoint;
+import io.quarkus.test.common.http.TestHTTPResource;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.http.ContentType;
+import org.apache.commons.io.IOUtils;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.net.URL;
+
+import static io.restassured.RestAssured.given;
+import static java.nio.charset.Charset.defaultCharset;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.hasItem;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class LibraryResourceHttpResourceIntegrationTest {
+
+ @TestHTTPEndpoint(LibraryResource.class)
+ @TestHTTPResource("book")
+ URL libraryEndpoint;
+
+ @Test
+ void whenGetBooksByTitle_thenBookShouldBeFound() {
+ given().contentType(ContentType.JSON).param("query", "Dune")
+ .when().get(libraryEndpoint)
+ .then().statusCode(200)
+ .body("size()", is(1))
+ .body("title", hasItem("Dune"))
+ .body("author", hasItem("Frank Herbert"));
+ }
+
+ @Test
+ void whenGetBooks_thenBooksShouldBeFound() throws IOException {
+ assertTrue(IOUtils.toString(libraryEndpoint.openStream(), defaultCharset()).contains("Asimov"));
+ }
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/LibraryResourceInjectSpyIntegrationTest.java b/quarkus/src/test/java/com/baeldung/quarkus/LibraryResourceInjectSpyIntegrationTest.java
new file mode 100644
index 0000000000..48ec1786fa
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/LibraryResourceInjectSpyIntegrationTest.java
@@ -0,0 +1,27 @@
+package com.baeldung.quarkus;
+
+import com.baeldung.quarkus.service.LibraryService;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.mockito.InjectSpy;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.mockito.Mockito.verify;
+
+@QuarkusTest
+class LibraryResourceInjectSpyIntegrationTest {
+
+ @InjectSpy
+ LibraryService libraryService;
+
+ @Test
+ void whenGetBooksByAuthor_thenBookShouldBeFound() {
+ given().contentType(ContentType.JSON).param("query", "Asimov")
+ .when().get("/library/book")
+ .then().statusCode(200);
+
+ verify(libraryService).find("Asimov");
+ }
+
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/LibraryResourceIntegrationTest.java b/quarkus/src/test/java/com/baeldung/quarkus/LibraryResourceIntegrationTest.java
new file mode 100644
index 0000000000..28eba8da44
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/LibraryResourceIntegrationTest.java
@@ -0,0 +1,24 @@
+package com.baeldung.quarkus;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.hasItem;
+
+@QuarkusTest
+class LibraryResourceIntegrationTest {
+
+ @Test
+ void whenGetBooksByTitle_thenBookShouldBeFound() {
+ given().contentType(ContentType.JSON).param("query", "Dune")
+ .when().get("/library/book")
+ .then().statusCode(200)
+ .body("size()", is(1))
+ .body("title", hasItem("Dune"))
+ .body("author", hasItem("Frank Herbert"));
+ }
+
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java b/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java
index 9ada64b6a5..e6c8a3b8fb 100644
--- a/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java
+++ b/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java
@@ -1,8 +1,11 @@
package com.baeldung.quarkus;
-import io.quarkus.test.junit.SubstrateTest;
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.h2.H2DatabaseTestResource;
+import io.quarkus.test.junit.NativeImageTest;
-@SubstrateTest
+@NativeImageTest
+@QuarkusTestResource(H2DatabaseTestResource.class)
public class NativeHelloResourceIT extends HelloResourceUnitTest {
// Execute the same tests but in native mode.
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java b/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java
new file mode 100644
index 0000000000..0c11fa6fb4
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java
@@ -0,0 +1,10 @@
+package com.baeldung.quarkus;
+
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.h2.H2DatabaseTestResource;
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+@QuarkusTestResource(H2DatabaseTestResource.class)
+class NativeLibraryResourceIT extends LibraryHttpEndpointIntegrationTest {
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/repository/BookRepositoryIntegrationTest.java b/quarkus/src/test/java/com/baeldung/quarkus/repository/BookRepositoryIntegrationTest.java
new file mode 100644
index 0000000000..7d811b2268
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/repository/BookRepositoryIntegrationTest.java
@@ -0,0 +1,20 @@
+package com.baeldung.quarkus.repository;
+
+import com.baeldung.quarkus.utils.QuarkusTransactionalTest;
+import org.junit.jupiter.api.Test;
+
+import javax.inject.Inject;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTransactionalTest
+class BookRepositoryIntegrationTest {
+
+ @Inject
+ BookRepository bookRepository;
+
+ @Test
+ void givenBookInRepository_whenFindByAuthor_thenShouldReturnBookFromRepository() {
+ assertTrue(bookRepository.findBy("Herbert").findAny().isPresent());
+ }
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/service/LibraryServiceInjectMockUnitTest.java b/quarkus/src/test/java/com/baeldung/quarkus/service/LibraryServiceInjectMockUnitTest.java
new file mode 100644
index 0000000000..f0b7260c7d
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/service/LibraryServiceInjectMockUnitTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.quarkus.service;
+
+import com.baeldung.quarkus.model.Book;
+import com.baeldung.quarkus.repository.BookRepository;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.mockito.InjectMock;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.when;
+
+@QuarkusTest
+class LibraryServiceInjectMockUnitTest {
+
+ @Inject
+ LibraryService libraryService;
+
+ @InjectMock
+ BookRepository bookRepository;
+
+ @BeforeEach
+ void setUp() {
+ when(bookRepository.findBy("Frank Herbert"))
+ .thenReturn(Arrays.stream(new Book[] {
+ new Book("Dune", "Frank Herbert"),
+ new Book("Children of Dune", "Frank Herbert")}));
+ }
+
+ @Test
+ void whenFindByAuthor_thenBooksShouldBeFound() {
+ assertEquals(2, libraryService.find("Frank Herbert").size());
+ }
+
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/service/LibraryServiceIntegrationTest.java b/quarkus/src/test/java/com/baeldung/quarkus/service/LibraryServiceIntegrationTest.java
new file mode 100644
index 0000000000..16cce4d726
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/service/LibraryServiceIntegrationTest.java
@@ -0,0 +1,21 @@
+package com.baeldung.quarkus.service;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.Test;
+
+import javax.inject.Inject;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+@QuarkusTest
+class LibraryServiceIntegrationTest {
+
+ @Inject
+ LibraryService libraryService;
+
+ @Test
+ void whenFindByAuthor_thenBookShouldBeFound() {
+ assertFalse(libraryService.find("Frank Herbert").isEmpty());
+ }
+
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/service/LibraryServiceQuarkusMockUnitTest.java b/quarkus/src/test/java/com/baeldung/quarkus/service/LibraryServiceQuarkusMockUnitTest.java
new file mode 100644
index 0000000000..e2d40a0a0b
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/service/LibraryServiceQuarkusMockUnitTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.quarkus.service;
+
+import com.baeldung.quarkus.model.Book;
+import com.baeldung.quarkus.repository.BookRepository;
+import com.baeldung.quarkus.utils.TestBookRepository;
+import io.quarkus.test.junit.QuarkusMock;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@QuarkusTest
+class LibraryServiceQuarkusMockUnitTest {
+
+ @Inject
+ LibraryService libraryService;
+
+ @BeforeEach
+ void setUp() {
+ BookRepository mock = Mockito.mock(TestBookRepository.class);
+ Mockito.when(mock.findBy("Asimov"))
+ .thenReturn(Arrays.stream(new Book[] {
+ new Book("Foundation", "Isaac Asimov"),
+ new Book("I Robot", "Isaac Asimov")}));
+ QuarkusMock.installMockForType(mock, BookRepository.class);
+ }
+
+ @Test
+ void whenFindByAuthor_thenBooksShouldBeFound() {
+ assertEquals(2, libraryService.find("Asimov").size());
+ }
+
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/utils/CustomTestProfile.java b/quarkus/src/test/java/com/baeldung/quarkus/utils/CustomTestProfile.java
new file mode 100644
index 0000000000..75fb736acc
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/utils/CustomTestProfile.java
@@ -0,0 +1,26 @@
+package com.baeldung.quarkus.utils;
+
+import io.quarkus.test.junit.QuarkusTestProfile;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+public class CustomTestProfile implements QuarkusTestProfile {
+
+ @Override
+ public Map getConfigOverrides() {
+ return Collections.singletonMap("quarkus.resteasy.path", "/custom");
+ }
+
+ @Override
+ public Set> getEnabledAlternatives() {
+ return Collections.singleton(TestBookRepository.class);
+ }
+
+ @Override
+ public String getConfigProfile() {
+ return "custom-profile";
+ }
+
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/utils/QuarkusTransactionalTest.java b/quarkus/src/test/java/com/baeldung/quarkus/utils/QuarkusTransactionalTest.java
new file mode 100644
index 0000000000..d02cff2662
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/utils/QuarkusTransactionalTest.java
@@ -0,0 +1,18 @@
+package com.baeldung.quarkus.utils;
+
+import io.quarkus.test.junit.QuarkusTest;
+
+import javax.enterprise.inject.Stereotype;
+import javax.transaction.Transactional;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@QuarkusTest
+@Stereotype
+@Transactional
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface QuarkusTransactionalTest {
+}
diff --git a/quarkus/src/test/java/com/baeldung/quarkus/utils/TestBookRepository.java b/quarkus/src/test/java/com/baeldung/quarkus/utils/TestBookRepository.java
new file mode 100644
index 0000000000..baaa9fd005
--- /dev/null
+++ b/quarkus/src/test/java/com/baeldung/quarkus/utils/TestBookRepository.java
@@ -0,0 +1,22 @@
+package com.baeldung.quarkus.utils;
+
+import com.baeldung.quarkus.model.Book;
+import com.baeldung.quarkus.repository.BookRepository;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Priority;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Alternative;
+
+@Priority(1)
+@Alternative
+@ApplicationScoped
+public class TestBookRepository extends BookRepository {
+
+ @PostConstruct
+ public void init() {
+ persist(new Book("Dune", "Frank Herbert"),
+ new Book("Foundation", "Isaac Asimov"));
+ }
+
+}