Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz committed Dec 10, 2024
1 parent b1a9ecb commit 6a6bfbd
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 42 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
QUARKUS_DATASOURCE_PASSWORD: onecx_chat
QUARKUS_DATASOURCE_JDBC_URL: "jdbc:postgresql://postgresdb:5432/onecx-chat?sslmode=disable"
QUARKUS_REST_CLIENT_ONECX_AI_SVC_URL: "http://onecx-ai-svc:8080/internal/ai/"
QUARKUS_OIDC_AUTH_SERVER_URL: "http://keycloak-app:8080/realms/onecx"
ports:
- "8081:8080"
depends_on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import jakarta.ws.rs.core.UriInfo;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.ClientWebApplicationException;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import org.tkit.quarkus.jpa.exceptions.ConstraintException;
Expand Down Expand Up @@ -155,9 +156,6 @@ public Response createChatMessage(String chatId, CreateMessageDTO createMessageD
var responseMessage = mapper.mapAiSvcMessage(chatResponse);
responseMessage.setChat(chat);
msgDao.create(responseMessage);
} catch (Exception e) {
throw new ConstraintException(e.getMessage(), ChatErrorKeys.ERROR_CALLING_AI_CHAT_SERVICE,
null);
}
}

Expand All @@ -171,7 +169,7 @@ public Response createChatMessage(String chatId, CreateMessageDTO createMessageD
public Response getChatMessages(String chatId) {
var chat = dao.findById(chatId);

if (chat == null || chat.getMessages() == null) {
if (chat == null || chat.getMessages().isEmpty()) {
// Handle the case where chat or its messages are null
return Response.status(Response.Status.NOT_FOUND).build();
}
Expand Down Expand Up @@ -206,7 +204,7 @@ public Response getChatParticipants(String chatId) {

var chat = dao.findById(chatId);

if (chat == null || chat.getParticipants() == null) {
if (chat == null || chat.getParticipants().isEmpty()) {
// Handle the case where chat or its messages are null
return Response.status(Response.Status.NOT_FOUND).build();
}
Expand All @@ -227,9 +225,13 @@ public RestResponse<ProblemDetailResponseDTO> constraint(ConstraintViolationExce
return exceptionMapper.constraint(ex);
}

@ServerExceptionMapper
public RestResponse<ProblemDetailResponseDTO> restException(ClientWebApplicationException ex) {
return exceptionMapper.clientException(ex);
}

enum ChatErrorKeys {
CHAT_DOES_NOT_EXIST,
ERROR_CALLING_AI_CHAT_SERVICE
CHAT_DOES_NOT_EXIST
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.validation.Path;
import jakarta.ws.rs.core.Response;

import org.jboss.resteasy.reactive.ClientWebApplicationException;
import org.jboss.resteasy.reactive.RestResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
Expand All @@ -34,6 +35,11 @@ default RestResponse<ProblemDetailResponseDTO> exception(ConstraintException ex)
return RestResponse.status(Response.Status.BAD_REQUEST, dto);
}

default RestResponse<ProblemDetailResponseDTO> clientException(ClientWebApplicationException ex) {
ProblemDetailResponseDTO dto = exception("ERROR_CALLING_AI_CHAT_SERVICE", ex.getMessage());
return RestResponse.status(Response.Status.BAD_REQUEST, dto);
}

@Mapping(target = "removeParamsItem", ignore = true)
@Mapping(target = "params", ignore = true)
@Mapping(target = "invalidParams", ignore = true)
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ quarkus.openapi-generator.codegen.spec.onecx_ai_svc_openapi_yaml.additional-api-

# TEST
quarkus.test.integration-test-profile=test
quarkus.test.enable-callbacks-for-integration-tests=true

%test.tkit.rs.context.tenant-id.enabled=true
%test.tkit.rs.context.tenant-id.mock.enabled=true
Expand All @@ -60,6 +61,5 @@ quarkus.test.integration-test-profile=test
%test.quarkus.mockserver.devservices.reuse=true

%test.quarkus.rest-client.onecx_ai_svc.url=${quarkus.mockserver.endpoint}/ai
#%test.quarkus.oidc-client.auth-server-url=${quarkus.oidc.auth-server-url}
quarkus.test.enable-callbacks-for-integration-tests=true
%test.quarkus.oidc-client.auth-server-url=${quarkus.oidc.auth-server-url}
# PIPE CONFIG
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ void getChatsNoTenantTest() {
.as(ChatPageResultDTO.class);

assertThat(data).isNotNull();
assertThat(data.getTotalElements()).isEqualTo(3);
assertThat(data.getStream()).isNotNull().hasSize(3);
assertThat(data.getTotalElements()).isEqualTo(4);
assertThat(data.getStream()).isNotNull().hasSize(4);

}

Expand Down Expand Up @@ -360,5 +360,4 @@ void updateChatWithoutBodyTest() {
Assertions.assertNotNull(exception.getInvalidParams());
Assertions.assertEquals(1, exception.getInvalidParams().size());
}

}
Loading

0 comments on commit 6a6bfbd

Please sign in to comment.