Skip to content

Commit

Permalink
feat: dao tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteenke committed Mar 4, 2024
1 parent 4f70906 commit 1891356
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/tkit/onecx/theme/domain/daos/ImageDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ public void deleteQueryByRefId(String refId) throws DAOException {

@Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = DAOException.class)
public void deleteQueryByRefIdAndRefType(String refId, RefTypeDTO refType) throws DAOException {
if (refId == null || refType == null) {
return;
}
try {
var cq = deleteQuery();
var root = cq.from(Image.class);
Expand All @@ -66,7 +63,7 @@ public void deleteQueryByRefIdAndRefType(String refId, RefTypeDTO refType) throw
getEntityManager().createQuery(cq).executeUpdate();
getEntityManager().flush();
} catch (Exception e) {
throw handleConstraint(e, ErrorKeys.FAILED_TO_DELETE_BY_REF_ID_QUERY);
throw handleConstraint(e, ErrorKeys.FAILED_TO_DELETE_BY_REF_ID_REF_TYPE_QUERY);
}
}

Expand All @@ -76,5 +73,7 @@ public enum ErrorKeys {

FIND_ENTITY_BY_REF_ID_REF_TYPE_FAILED,

FAILED_TO_DELETE_BY_REF_ID_REF_TYPE_QUERY

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.tkit.onecx.theme.test.AbstractTest;
import org.tkit.quarkus.jpa.exceptions.DAOException;

import gen.org.tkit.onecx.image.rs.internal.model.RefTypeDTO;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;

Expand All @@ -29,11 +30,14 @@ void beforeAll() {

@Test
void methodExceptionTests() {
Assertions.assertDoesNotThrow(() -> dao.deleteQueryByRefId(null));
methodExceptionTests(() -> dao.deleteQueryByRefId("1"),
ImageDAO.ErrorKeys.FAILED_TO_DELETE_BY_REF_ID_QUERY);
methodExceptionTests(() -> dao.findByRefIdAndRefType(null, null),
ImageDAO.ErrorKeys.FIND_ENTITY_BY_REF_ID_REF_TYPE_FAILED);
methodExceptionTests(() -> dao.findByRefIdAndRefType(null, null),
ImageDAO.ErrorKeys.FIND_ENTITY_BY_REF_ID_REF_TYPE_FAILED);
methodExceptionTests(() -> dao.deleteQueryByRefIdAndRefType("1", RefTypeDTO.LOGO),
ImageDAO.ErrorKeys.FAILED_TO_DELETE_BY_REF_ID_REF_TYPE_QUERY);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import java.util.Objects;
import java.util.Random;

import jakarta.inject.Inject;
import jakarta.ws.rs.core.HttpHeaders;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.tkit.onecx.theme.domain.daos.ImageDAO;
import org.tkit.onecx.theme.test.AbstractTest;
import org.tkit.quarkus.test.WithDBData;

Expand All @@ -31,6 +33,9 @@ class ImageRestControllerTest extends AbstractTest {
private static final String MEDIA_TYPE_IMAGE_PNG = "image/png";
private static final String MEDIA_TYPE_IMAGE_JPG = "image/jpg";

@Inject
ImageDAO imageDAO;

private static final File FILE = new File(
Objects.requireNonNull(ImageRestControllerTest.class.getResource("/images/Testimage.png")).getFile());

Expand Down

0 comments on commit 1891356

Please sign in to comment.