Skip to content

Commit 81066e7

Browse files
committed
Use Quarkus application framework - step 3: DI in bootstrap + Maven plugin
1 parent 1aa25a6 commit 81066e7

File tree

10 files changed

+44
-218
lines changed

10 files changed

+44
-218
lines changed

adapter/src/main/java/eu/happycoders/shop/adapter/out/persistence/jpa/EntityManagerFactoryFactory.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

adapter/src/test/java/eu/happycoders/shop/adapter/in/rest/HttpTestCommons.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
public final class HttpTestCommons {
99

10-
// So the tests can run when the application runs on port 8080:
11-
public static final int TEST_PORT = 8082;
12-
1310
private HttpTestCommons() {}
1411

1512
public static void assertThatResponseIsError(

bootstrap/pom.xml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@
3232
<version>${project.version}</version>
3333
</dependency>
3434

35-
<!-- External -->
36-
<!-- Required temporarily during migration -->
37-
<dependency>
38-
<groupId>org.jboss.resteasy</groupId>
39-
<artifactId>resteasy-undertow</artifactId>
40-
<exclusions>
41-
<!-- Conflicts with io.smallrye:jandex, a dependency from Hibernate -->
42-
<exclusion>
43-
<groupId>org.jboss</groupId>
44-
<artifactId>jandex</artifactId>
45-
</exclusion>
46-
</exclusions>
47-
</dependency>
48-
4935
<!-- Test scope -->
5036
<dependency>
5137
<groupId>io.quarkus</groupId>
@@ -79,6 +65,25 @@
7965
</dependency>
8066
</dependencies>
8167

68+
<build>
69+
<plugins>
70+
<plugin>
71+
<groupId>io.quarkus.platform</groupId>
72+
<artifactId>quarkus-maven-plugin</artifactId>
73+
<extensions>true</extensions>
74+
<executions>
75+
<execution>
76+
<goals>
77+
<goal>build</goal>
78+
<goal>generate-code</goal>
79+
<goal>generate-code-tests</goal>
80+
</goals>
81+
</execution>
82+
</executions>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
8287
<profiles>
8388
<profile>
8489
<id>test-coverage</id>

bootstrap/src/main/java/eu/happycoders/shop/bootstrap/Launcher.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

bootstrap/src/main/java/eu/happycoders/shop/bootstrap/RestEasyUndertowShopApplication.java

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# No properties required for this demo application
2+
# You would put database connection parameters here, for example.
3+
# But in dev mode, Quarkus creates those auto-magically.

bootstrap/src/test/java/eu/happycoders/shop/bootstrap/e2e/CartTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package eu.happycoders.shop.bootstrap.e2e;
22

3-
import static eu.happycoders.shop.adapter.in.rest.HttpTestCommons.TEST_PORT;
43
import static eu.happycoders.shop.adapter.in.rest.cart.CartsControllerAssertions.assertThatResponseIsCart;
54
import static eu.happycoders.shop.adapter.out.persistence.DemoProducts.LED_LIGHTS;
65
import static eu.happycoders.shop.adapter.out.persistence.DemoProducts.MONITOR_DESK_MOUNT;
76
import static io.restassured.RestAssured.given;
87
import static jakarta.ws.rs.core.Response.Status.NO_CONTENT;
98

9+
import eu.happycoders.shop.adapter.TestProfileWithMySQL;
1010
import eu.happycoders.shop.model.cart.Cart;
1111
import eu.happycoders.shop.model.cart.NotEnoughItemsInStockException;
1212
import eu.happycoders.shop.model.customer.CustomerId;
13+
import io.quarkus.test.junit.QuarkusTest;
14+
import io.quarkus.test.junit.TestProfile;
1315
import io.restassured.response.Response;
1416
import org.junit.jupiter.api.MethodOrderer;
1517
import org.junit.jupiter.api.Order;
1618
import org.junit.jupiter.api.Test;
1719
import org.junit.jupiter.api.TestMethodOrder;
1820

21+
@QuarkusTest
22+
@TestProfile(TestProfileWithMySQL.class)
1923
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
20-
class CartTest extends EndToEndTest {
24+
class CartTest {
2125

2226
private static final CustomerId TEST_CUSTOMER_ID = new CustomerId(61157);
2327
private static final String CARTS_PATH = "/carts/" + TEST_CUSTOMER_ID.value();
@@ -28,7 +32,6 @@ void givenAnEmptyCart_addLineItem_addsTheLineItemAndReturnsTheCartWithTheAddedIt
2832
throws NotEnoughItemsInStockException {
2933
Response response =
3034
given()
31-
.port(TEST_PORT)
3235
.queryParam("productId", LED_LIGHTS.id().value())
3336
.queryParam("quantity", 3)
3437
.post(CARTS_PATH + "/line-items")
@@ -48,7 +51,6 @@ void givenACartWithOneLineItem_addLineItem_addsTheLineItemAndReturnsACartWithTwo
4851
throws NotEnoughItemsInStockException {
4952
Response response =
5053
given()
51-
.port(TEST_PORT)
5254
.queryParam("productId", MONITOR_DESK_MOUNT.id().value())
5355
.queryParam("quantity", 1)
5456
.post(CARTS_PATH + "/line-items")
@@ -66,7 +68,7 @@ void givenACartWithOneLineItem_addLineItem_addsTheLineItemAndReturnsACartWithTwo
6668
@Test
6769
@Order(3)
6870
void givenACartWithTwoLineItems_getCart_returnsTheCart() throws NotEnoughItemsInStockException {
69-
Response response = given().port(TEST_PORT).get(CARTS_PATH).then().extract().response();
71+
Response response = given().get(CARTS_PATH).then().extract().response();
7072

7173
Cart expectedCart = new Cart(TEST_CUSTOMER_ID);
7274
expectedCart.addProduct(LED_LIGHTS, 3);
@@ -78,13 +80,13 @@ void givenACartWithTwoLineItems_getCart_returnsTheCart() throws NotEnoughItemsIn
7880
@Test
7981
@Order(4)
8082
void givenACartWithTwoLineItems_delete_returnsStatusCodeNoContent() {
81-
given().port(TEST_PORT).delete(CARTS_PATH).then().statusCode(NO_CONTENT.getStatusCode());
83+
given().delete(CARTS_PATH).then().statusCode(NO_CONTENT.getStatusCode());
8284
}
8385

8486
@Test
8587
@Order(5)
8688
void givenAnEmptiedCart_getCart_returnsAnEmptyCart() {
87-
Response response = given().port(TEST_PORT).get(CARTS_PATH).then().extract().response();
89+
Response response = given().get(CARTS_PATH).then().extract().response();
8890

8991
assertThatResponseIsCart(response, new Cart(TEST_CUSTOMER_ID));
9092
}

bootstrap/src/test/java/eu/happycoders/shop/bootstrap/e2e/EndToEndTest.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

bootstrap/src/test/java/eu/happycoders/shop/bootstrap/e2e/FindProductsTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
package eu.happycoders.shop.bootstrap.e2e;
22

3-
import static eu.happycoders.shop.adapter.in.rest.HttpTestCommons.TEST_PORT;
43
import static eu.happycoders.shop.adapter.in.rest.product.ProductsControllerAssertions.assertThatResponseIsProductList;
54
import static eu.happycoders.shop.adapter.out.persistence.DemoProducts.COMPUTER_MONITOR;
65
import static eu.happycoders.shop.adapter.out.persistence.DemoProducts.MONITOR_DESK_MOUNT;
76
import static io.restassured.RestAssured.given;
87

8+
import eu.happycoders.shop.adapter.TestProfileWithMySQL;
9+
import io.quarkus.test.junit.QuarkusTest;
10+
import io.quarkus.test.junit.TestProfile;
911
import io.restassured.response.Response;
1012
import java.util.List;
1113
import org.junit.jupiter.api.Test;
1214

13-
class FindProductsTest extends EndToEndTest {
15+
@QuarkusTest
16+
@TestProfile(TestProfileWithMySQL.class)
17+
class FindProductsTest {
1418

1519
@Test
1620
void givenTestProductsAndAQuery_findProducts_returnsMatchingProducts() {
1721
String query = "monitor";
1822

1923
Response response =
20-
given()
21-
.port(TEST_PORT)
22-
.queryParam("query", query)
23-
.get("/products")
24-
.then()
25-
.extract()
26-
.response();
24+
given().queryParam("query", query).get("/products").then().extract().response();
2725

2826
assertThatResponseIsProductList(response, List.of(COMPUTER_MONITOR, MONITOR_DESK_MOUNT));
2927
}

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888

8989
<build>
9090
<plugins>
91+
<plugin>
92+
<groupId>io.quarkus.platform</groupId>
93+
<artifactId>quarkus-maven-plugin</artifactId>
94+
<version>${quarkus.platform.version}</version>
95+
</plugin>
96+
9197
<!-- Make sure to use the latest compiler and surefire plugins
9298
(their versions otherwise depends on the Maven version in use). -->
9399
<plugin>

0 commit comments

Comments
 (0)