chore: add test
This commit is contained in:
@@ -23,4 +23,4 @@
|
|||||||
"containerEnv": {
|
"containerEnv": {
|
||||||
"TESTCONTAINERS_RYUK_DISABLED": "true"
|
"TESTCONTAINERS_RYUK_DISABLED": "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-4
@@ -1,16 +1,15 @@
|
|||||||
package com.drinkool;
|
package com.drinkool.services;
|
||||||
|
|
||||||
import com.drinkool.dtos.*;
|
import com.drinkool.dtos.*;
|
||||||
import com.drinkool.entities.CustomerEntity;
|
import com.drinkool.entities.CustomerEntity;
|
||||||
import com.drinkool.entities.CustomerEntity;
|
|
||||||
import com.drinkool.services.*;
|
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
import jakarta.ws.rs.core.*;
|
import jakarta.ws.rs.core.*;
|
||||||
|
|
||||||
@Path("/api")
|
@Path("/api")
|
||||||
public class RestAPI {
|
public class AuthenticationService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
OtpService otpService;
|
OtpService otpService;
|
||||||
+11
-15
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project
|
<project
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||||
>
|
>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -20,11 +20,9 @@
|
|||||||
<compiler-plugin.version>3.15.0</compiler-plugin.version>
|
<compiler-plugin.version>3.15.0</compiler-plugin.version>
|
||||||
<maven.compiler.release>21</maven.compiler.release>
|
<maven.compiler.release>21</maven.compiler.release>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||||
<quarkus.platform.group-id
|
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||||
>io.quarkus.platform</quarkus.platform.group-id>
|
|
||||||
<quarkus.platform.version>3.32.4</quarkus.platform.version>
|
<quarkus.platform.version>3.32.4</quarkus.platform.version>
|
||||||
<skipITs>true</skipITs>
|
<skipITs>true</skipITs>
|
||||||
<surefire-plugin.version>3.5.4</surefire-plugin.version>
|
<surefire-plugin.version>3.5.4</surefire-plugin.version>
|
||||||
@@ -49,8 +47,8 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.awaitility</groupId>
|
<groupId>io.rest-assured</groupId>
|
||||||
<artifactId>awaitility</artifactId>
|
<artifactId>rest-assured</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -109,8 +107,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<argLine>@{argLine}</argLine>
|
<argLine>@{argLine}</argLine>
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<java.util.logging.manager
|
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||||
>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
|
||||||
<maven.home>${maven.home}</maven.home>
|
<maven.home>${maven.home}</maven.home>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -131,8 +128,7 @@
|
|||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<native.image.path>
|
<native.image.path>
|
||||||
${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||||
<java.util.logging.manager
|
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||||
>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
|
||||||
<maven.home>${maven.home}</maven.home>
|
<maven.home>${maven.home}</maven.home>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -155,4 +151,4 @@
|
|||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package com.drinkool;
|
|
||||||
|
|
||||||
import com.drinkool.dtos.SendReview;
|
|
||||||
import com.drinkool.entities.ReviewEntity;
|
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.eclipse.microprofile.reactive.messaging.Incoming;
|
|
||||||
|
|
||||||
@ApplicationScoped
|
|
||||||
public class ReviewService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injects an emitter to send messages to the "words-out" channel.
|
|
||||||
*/
|
|
||||||
// @Channel("words-out")
|
|
||||||
// Emitter<String> emitter;
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Sends message to the "words-out" channel, can be used from a JAX-RS resource or any bean of your application.
|
|
||||||
// * Messages are sent to the broker.
|
|
||||||
// **/
|
|
||||||
// void onStart(@Observes StartupEvent ev) {
|
|
||||||
// Stream.of("Hello", "with", "Quarkus", "Messaging", "message").forEach(
|
|
||||||
// string -> emitter.send(string)
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Consume the message from the "words-in" channel, uppercase it and send it to the uppercase channel.
|
|
||||||
* This method is called by the framework when a message is received on the "words-in" channel (from the broker).
|
|
||||||
**/
|
|
||||||
// @Incoming("words-in")
|
|
||||||
// @Outgoing("uppercase")
|
|
||||||
// public String toUpperCase(String message) {
|
|
||||||
// return message.toUpperCase();
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Consume the uppercase channel (coming from within the application) and print the messages to the console.
|
|
||||||
**/
|
|
||||||
// @Incoming("uppercase")
|
|
||||||
// public void sink(String word) {
|
|
||||||
// System.out.println(">> " + word);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Incoming("review")
|
|
||||||
@Transactional
|
|
||||||
public void receiveReview(SendReview input) {
|
|
||||||
ReviewEntity newReview = new ReviewEntity();
|
|
||||||
|
|
||||||
newReview.receive(input.reviewerId, input.orderId, input.review);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.drinkool.services;
|
||||||
|
|
||||||
|
import com.drinkool.dtos.SendReview;
|
||||||
|
import com.drinkool.entities.ReviewEntity;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
import jakarta.ws.rs.*;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("/api")
|
||||||
|
public class ReviewService {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/leaveReview")
|
||||||
|
@Transactional
|
||||||
|
public Response leaveReview(SendReview input) {
|
||||||
|
ReviewEntity newReview = new ReviewEntity();
|
||||||
|
|
||||||
|
newReview.receive(input.reviewerId, input.orderId, input.review);
|
||||||
|
|
||||||
|
return Response.status(201).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.drinkool.utils;
|
|
||||||
|
|
||||||
import com.drinkool.dtos.SendReview;
|
|
||||||
import io.quarkus.kafka.client.serialization.ObjectMapperDeserializer;
|
|
||||||
|
|
||||||
public class SendReviewDeserializer
|
|
||||||
extends ObjectMapperDeserializer<SendReview>
|
|
||||||
{
|
|
||||||
|
|
||||||
public SendReviewDeserializer() {
|
|
||||||
super(SendReview.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +1,14 @@
|
|||||||
# Cấu hình Database
|
|
||||||
|
|
||||||
# Kafka
|
# Kafka
|
||||||
# Địa chỉ server Kafka
|
|
||||||
kafka.bootstrap.servers=localhost:9092
|
kafka.bootstrap.servers=localhost:9092
|
||||||
|
|
||||||
# --- CẤU HÌNH GỬI TIN (OUTGOING) ---
|
|
||||||
# Kênh "eatery-out" sẽ gửi vào topic "eatery-events"
|
|
||||||
# mp.messaging.outgoing.eatery-out.connector=smallrye-kafka
|
|
||||||
# mp.messaging.outgoing.eatery-out.topic=eatery-events
|
|
||||||
# # Tự động biến Object thành JSON
|
|
||||||
# mp.messaging.outgoing.eatery-out.value.serializer=io.quarkus.kafka.client.serialization.ObjectMapperSerializer
|
|
||||||
|
|
||||||
# --- CẤU HÌNH NHẬN TIN (INCOMING) ---
|
|
||||||
# Kênh "review-in" sẽ nhận từ topic "review-topic"
|
|
||||||
mp.messaging.incoming.review.connector=smallrye-kafka
|
|
||||||
mp.messaging.incoming.review.topic=review-topic
|
|
||||||
# Tự động biến JSON thành Object (giả sử là class ReviewModel)
|
|
||||||
mp.messaging.incoming.review.value.deserializer=com.drinkool.utils.SendReviewDeserializer
|
|
||||||
|
|
||||||
# Postgress
|
# Postgress
|
||||||
# Cấu hình Database
|
## Cấu hình Database
|
||||||
quarkus.datasource.db-kind=postgresql
|
quarkus.datasource.db-kind=postgresql
|
||||||
quarkus.datasource.username=postgres
|
quarkus.datasource.username=postgres
|
||||||
quarkus.datasource.password=password
|
quarkus.datasource.password=password
|
||||||
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/eatery
|
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/eatery
|
||||||
|
|
||||||
# Tự động tạo bảng từ Entity (chỉ dùng cho môi trường dev)
|
## Tự động tạo bảng từ Entity (chỉ dùng cho môi trường dev)
|
||||||
quarkus.hibernate-orm.database.generation=update
|
quarkus.hibernate-orm.database.generation=update
|
||||||
|
|
||||||
# Dependency
|
# Dependency
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.drinkool;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
|
||||||
import jakarta.inject.Inject;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
@QuarkusTest
|
|
||||||
class MyMessagingApplicationTest {
|
|
||||||
// @Inject
|
|
||||||
// MyMessagingApplication application;
|
|
||||||
// @Test
|
|
||||||
// void test() {
|
|
||||||
// assertEquals("HELLO", application.toUpperCase("Hello"));
|
|
||||||
// assertEquals("BONJOUR", application.toUpperCase("bonjour"));
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
+11
-23
@@ -1,30 +1,20 @@
|
|||||||
package com.drinkool;
|
package com.drinkool.services;
|
||||||
|
|
||||||
|
import static io.restassured.RestAssured.given;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import com.drinkool.dtos.SendReview;
|
import com.drinkool.dtos.SendReview;
|
||||||
import com.drinkool.entities.ReviewEntity;
|
import com.drinkool.entities.ReviewEntity;
|
||||||
import com.drinkool.models.ReviewModel;
|
import com.drinkool.models.ReviewModel;
|
||||||
import io.quarkus.narayana.jta.QuarkusTransaction;
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import jakarta.inject.Inject;
|
import io.restassured.http.ContentType;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import org.junit.jupiter.api.*;
|
||||||
import org.awaitility.Awaitility;
|
|
||||||
import org.eclipse.microprofile.reactive.messaging.*;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
public class ReviewServiceTest {
|
public class ReviewServiceTest {
|
||||||
|
|
||||||
@Inject
|
|
||||||
ReviewService service;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
@Channel("review-test")
|
|
||||||
Emitter<SendReview> producer;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void receiveReview() {
|
void receiveReview() {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
@@ -42,15 +32,13 @@ public class ReviewServiceTest {
|
|||||||
reviewModel.rating = rating;
|
reviewModel.rating = rating;
|
||||||
input.review = reviewModel;
|
input.review = reviewModel;
|
||||||
|
|
||||||
producer.send(input);
|
given()
|
||||||
|
.contentType(ContentType.JSON)
|
||||||
|
.body(input)
|
||||||
|
.when()
|
||||||
|
.post("/api/leaveReview")
|
||||||
|
.then();
|
||||||
|
|
||||||
Awaitility.await()
|
assertEquals(1, ReviewEntity.find("reviewerId", reviewerId).count());
|
||||||
.atMost(5, TimeUnit.SECONDS)
|
|
||||||
.untilAsserted(() -> {
|
|
||||||
ReviewEntity saved = QuarkusTransaction.requiringNew().call(() ->
|
|
||||||
ReviewEntity.find("reviewerId", reviewerId).firstResult()
|
|
||||||
);
|
|
||||||
assertNotNull(saved);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,2 @@
|
|||||||
# Kafka
|
# Quarkus
|
||||||
kafka.bootstrap.servers=localhost:9092
|
quarkus.http.host=0.0.0.0
|
||||||
|
|
||||||
# --- CẤU HÌNH GỬI TIN (OUTGOING) ---
|
|
||||||
# Kênh "eatery-out" sẽ gửi vào topic "eatery-events"
|
|
||||||
# mp.messaging.outgoing.eatery-out.connector=smallrye-kafka
|
|
||||||
# mp.messaging.outgoing.eatery-out.topic=eatery-events
|
|
||||||
# # Tự động biến Object thành JSON
|
|
||||||
# mp.messaging.outgoing.eatery-out.value.serializer=io.quarkus.kafka.client.serialization.ObjectMapperSerializer
|
|
||||||
|
|
||||||
# --- CẤU HÌNH NHẬN TIN (INCOMING) ---
|
|
||||||
mp.messaging.outgoing.review-test.connector=smallrye-kafka
|
|
||||||
mp.messaging.outgoing.review-test.topic=review-topic
|
|
||||||
# Sửa serializer cho đúng loại dành cho việc GỬI
|
|
||||||
mp.messaging.outgoing.review-test.value.serializer=io.quarkus.kafka.client.serialization.ObjectMapperSerializer
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
||||||
|
|
||||||
@Entity
|
@MappedSuperclass
|
||||||
public abstract class BaseEntity extends PanacheEntityBase {
|
public class BaseEntity extends PanacheEntityBase {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.UUID)
|
@GeneratedValue(strategy = GenerationType.UUID)
|
||||||
|
|||||||
Reference in New Issue
Block a user