Skip to content

Commit

Permalink
feat: refactoring test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Dec 5, 2023
1 parent 5a2d711 commit 8dfe5ca
Show file tree
Hide file tree
Showing 23 changed files with 142 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.validation.ConstraintViolationException;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;

import org.jboss.resteasy.reactive.RestResponse;
Expand All @@ -23,7 +22,6 @@
import io.github.onecx.theme.rs.exim.v1.mappers.ExportImportMapperV1;

@LogService
@Path("/exim/v1/themes")
@ApplicationScoped
@Transactional(Transactional.TxType.NOT_SUPPORTED)
public class ExportImportRestControllerV1 implements ThemesExportImportApi {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.onecx.theme.rs.exim.v1.log;

import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;

import org.tkit.quarkus.log.cdi.LogParam;

import gen.io.github.onecx.theme.rs.exim.v1.model.EximExportRequestDTOV1;
import gen.io.github.onecx.theme.rs.exim.v1.model.EximImportRequestDTOV1;

@ApplicationScoped
public class ExportImportLogParam implements LogParam {

@Override
public List<Item> getClasses() {
return List.of(
item(10, EximExportRequestDTOV1.class, x -> x.getClass().getSimpleName()),
item(10, EximImportRequestDTOV1.class,
x -> x.getClass().getSimpleName() + ":" + ((EximImportRequestDTOV1) x).getId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;

import org.tkit.quarkus.log.cdi.LogService;
Expand All @@ -13,7 +12,6 @@
import io.github.onecx.theme.rs.external.v1.mappers.ThemeMapper;

@LogService
@Path("/v1/themes")
@ApplicationScoped
@Transactional(Transactional.TxType.NOT_SUPPORTED)
public class ThemesRestControllerV1 implements ThemesV1Api {
Expand All @@ -25,7 +23,7 @@ public class ThemesRestControllerV1 implements ThemesV1Api {
ThemeMapper mapper;

@Override
public Response getThemeByThemeDefinitionName(String name) {
public Response getThemeByName(String name) {
var theme = dao.findThemeByName(name);
if (theme == null) {
return Response.status(Response.Status.NOT_FOUND).build();
Expand All @@ -34,7 +32,7 @@ public Response getThemeByThemeDefinitionName(String name) {
}

@Override
public Response getThemeInfoList() {
public Response getThemesInfo() {
var items = dao.findAllInfos();
return Response.ok(mapper.mapInfoList(items)).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.validation.ConstraintViolationException;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;

import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import org.tkit.quarkus.jpa.exceptions.ConstraintException;
import org.tkit.quarkus.log.cdi.LogService;

import gen.io.github.onecx.theme.rs.internal.ThemesInternalApi;
import gen.io.github.onecx.theme.rs.internal.model.*;
Expand All @@ -23,7 +23,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Path("/internal/themes") // remove this after quarkus fix ServiceExceptionMapper for impl classes
@LogService
@ApplicationScoped
@Transactional(value = NOT_SUPPORTED)
public class ThemesRestController implements ThemesInternalApi {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.onecx.theme.rs.internal.log;

import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;

import org.tkit.quarkus.log.cdi.LogParam;

import gen.io.github.onecx.theme.rs.internal.model.CreateThemeDTO;
import gen.io.github.onecx.theme.rs.internal.model.ThemeSearchCriteriaDTO;
import gen.io.github.onecx.theme.rs.internal.model.UpdateThemeDTO;

@ApplicationScoped
public class ThemesLogParam implements LogParam {

@Override
public List<Item> getClasses() {
return List.of(
item(10, CreateThemeDTO.class, x -> x.getClass().getSimpleName() + ":" + ((CreateThemeDTO) x).getName()),
item(10, ThemeSearchCriteriaDTO.class, x -> {
ThemeSearchCriteriaDTO d = (ThemeSearchCriteriaDTO) x;
return ThemeSearchCriteriaDTO.class.getSimpleName() + "[" + d.getPageNumber() + "," + d.getPageSize() + "]";
}),
item(10, UpdateThemeDTO.class, x -> x.getClass().getSimpleName() + ":" + ((UpdateThemeDTO) x).getName()));
}
}
4 changes: 2 additions & 2 deletions src/main/openapi/onecx-theme-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ paths:
tags:
- themes
description: Get list of all themes
operationId: getThemeInfoList
operationId: getThemesInfo
responses:
"200":
description: OK
Expand All @@ -28,7 +28,7 @@ paths:
tags:
- themes
description: Load a single theme definition
operationId: getThemeByThemeDefinitionName
operationId: getThemeByName
parameters:
- name: name
in: path
Expand Down
24 changes: 23 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,29 @@ tkit.rs.context.tenant-id.enabled=true
%dev.tkit.rs.context.tenant-id.mock.data.org1=tenant100

# TEST
%test.tkit.rs.context.tenant-id.enabled=false
%test.tkit.dataimport.enabled=true
%test.tkit.dataimport.configurations.theme.enabled=true
%test.tkit.dataimport.configurations.theme.file=./src/test/resources/import/theme-import.json
%test.tkit.dataimport.configurations.theme.metadata.operation=CLEAN_INSERT
%test.tkit.dataimport.configurations.theme.stop-at-error=true

%test.tkit.rs.context.tenant-id.enabled=true
%test.tkit.rs.context.tenant-id.mock.enabled=true
%test.tkit.rs.context.tenant-id.mock.default-tenant=default
%test.tkit.rs.context.tenant-id.mock.claim-org-id=orgId
%test.tkit.rs.context.tenant-id.mock.token-header-param=apm-principal-token
%test.tkit.rs.context.tenant-id.mock.data.org1=tenant-100
%test.tkit.rs.context.tenant-id.mock.data.org2=tenant-200

# TEST-IT
quarkus.test.integration-test-profile=test-it
%test-it.tkit.log.json.enabled=false
%test-it.tkit.rs.context.tenant-id.mock.enabled=true
%test-it.tkit.rs.context.tenant-id.mock.default-tenant=default
%test-it.tkit.rs.context.tenant-id.mock.claim-org-id=orgId
%test-it.tkit.rs.context.tenant-id.mock.token-header-param=apm-principal-token
%test-it.tkit.rs.context.tenant-id.mock.data.org1=tenant-100
%test-it.tkit.rs.context.tenant-id.mock.data.org2=tenant-200

# PIPE CONFIG

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.github.onecx.theme;

import static org.assertj.core.api.Assertions.assertThat;

import jakarta.inject.Inject;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import io.github.onecx.theme.domain.daos.ThemeDAO;
import io.github.onecx.theme.test.AbstractTest;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@DisplayName("Theme data import test from example file")
class AfterStartThemeDataImportTest extends AbstractTest {

@Inject
ThemeDAO dao;

@Test
@DisplayName("Import theme data from file")
void importDataFromFileTest() {
var data = dao.findAll().toList();
assertThat(data).isNotNull().hasSize(2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import org.mockito.Mockito;
import org.tkit.quarkus.jpa.exceptions.DAOException;

import io.github.onecx.theme.test.AbstractTest;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class ThemeDAOTest {
class ThemeDAOTest extends AbstractTest {
@Inject
ThemeDAO dao;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void exportThemesExceptionTest() {
.contentType(APPLICATION_JSON)
.body(request)
.post("export")
.then().log().all()
.then()
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode());

}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
import io.github.onecx.theme.test.AbstractTest;
import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestHTTPEndpoint(ExportImportRestControllerV1.class)
@WithDBData(value = "data/testdata-exim-tenant.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true)
@TestProfile(AbstractTest.TenantTestProfile.class)
@WithDBData(value = "data/testdata-exim.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true)
class ExportImportRestControllerV1TenantTest extends AbstractTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
import io.github.onecx.theme.test.AbstractTest;
import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestHTTPEndpoint(ThemesRestControllerV1.class)
@WithDBData(value = "data/testdata-external-tenant.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true)
@TestProfile(AbstractTest.TenantTestProfile.class)
@WithDBData(value = "data/testdata-external.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true)
class ThemesRestControllerV1TenantTest extends AbstractTest {

@Test
Expand All @@ -36,7 +34,7 @@ void getThemeByThemeDefinitionNameTest() {

assertThat(dto).isNotNull();
assertThat(dto.getName()).isEqualTo("themeWithoutPortal");
assertThat(dto.getId()).isEqualTo("22-222");
assertThat(dto.getId()).isEqualTo("t-22-222");

given()
.contentType(APPLICATION_JSON)
Expand Down Expand Up @@ -70,6 +68,6 @@ void getThemeInfoListTest() {
.as(ThemeInfoListDTOV1.class);

assertThat(data).isNotNull();
assertThat(data.getThemes()).isNotNull().isEmpty();
assertThat(data.getThemes()).hasSize(3);
}
}
Loading

0 comments on commit 8dfe5ca

Please sign in to comment.