chore: add test
This commit is contained in:
+3
-4
@@ -1,16 +1,15 @@
|
||||
package com.drinkool;
|
||||
package com.drinkool.services;
|
||||
|
||||
import com.drinkool.dtos.*;
|
||||
import com.drinkool.entities.CustomerEntity;
|
||||
import com.drinkool.entities.CustomerEntity;
|
||||
import com.drinkool.services.*;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.*;
|
||||
|
||||
@Path("/api")
|
||||
public class RestAPI {
|
||||
public class AuthenticationService {
|
||||
|
||||
@Inject
|
||||
OtpService otpService;
|
||||
+10
-14
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -20,11 +20,9 @@
|
||||
<compiler-plugin.version>3.15.0</compiler-plugin.version>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding
|
||||
>UTF-8</project.reporting.outputEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||
<quarkus.platform.group-id
|
||||
>io.quarkus.platform</quarkus.platform.group-id>
|
||||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||
<quarkus.platform.version>3.32.4</quarkus.platform.version>
|
||||
<skipITs>true</skipITs>
|
||||
<surefire-plugin.version>3.5.4</surefire-plugin.version>
|
||||
@@ -49,8 +47,8 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -109,8 +107,7 @@
|
||||
<configuration>
|
||||
<argLine>@{argLine}</argLine>
|
||||
<systemPropertyVariables>
|
||||
<java.util.logging.manager
|
||||
>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
@@ -131,8 +128,7 @@
|
||||
<systemPropertyVariables>
|
||||
<native.image.path>
|
||||
${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
<java.util.logging.manager
|
||||
>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
|
||||
@@ -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
|
||||
# Địa chỉ server Kafka
|
||||
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
|
||||
# Cấu hình Database
|
||||
## Cấu hình Database
|
||||
quarkus.datasource.db-kind=postgresql
|
||||
quarkus.datasource.username=postgres
|
||||
quarkus.datasource.password=password
|
||||
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
|
||||
|
||||
# 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 com.drinkool.dtos.SendReview;
|
||||
import com.drinkool.entities.ReviewEntity;
|
||||
import com.drinkool.models.ReviewModel;
|
||||
import io.quarkus.narayana.jta.QuarkusTransaction;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import io.restassured.http.ContentType;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.eclipse.microprofile.reactive.messaging.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
@QuarkusTest
|
||||
public class ReviewServiceTest {
|
||||
|
||||
@Inject
|
||||
ReviewService service;
|
||||
|
||||
@Inject
|
||||
@Channel("review-test")
|
||||
Emitter<SendReview> producer;
|
||||
|
||||
@Test
|
||||
void receiveReview() {
|
||||
Random random = new Random();
|
||||
@@ -42,15 +32,13 @@ public class ReviewServiceTest {
|
||||
reviewModel.rating = rating;
|
||||
input.review = reviewModel;
|
||||
|
||||
producer.send(input);
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(input)
|
||||
.when()
|
||||
.post("/api/leaveReview")
|
||||
.then();
|
||||
|
||||
Awaitility.await()
|
||||
.atMost(5, TimeUnit.SECONDS)
|
||||
.untilAsserted(() -> {
|
||||
ReviewEntity saved = QuarkusTransaction.requiringNew().call(() ->
|
||||
ReviewEntity.find("reviewerId", reviewerId).firstResult()
|
||||
);
|
||||
assertNotNull(saved);
|
||||
});
|
||||
assertEquals(1, ReviewEntity.find("reviewerId", reviewerId).count());
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,2 @@
|
||||
# Kafka
|
||||
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) ---
|
||||
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
|
||||
# Quarkus
|
||||
quarkus.http.host=0.0.0.0
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.util.UUID;
|
||||
|
||||
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
||||
|
||||
@Entity
|
||||
public abstract class BaseEntity extends PanacheEntityBase {
|
||||
@MappedSuperclass
|
||||
public class BaseEntity extends PanacheEntityBase {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
|
||||
Reference in New Issue
Block a user