diff --git a/src/main/java/org/tkit/onecx/theme/domain/daos/ImageDAO.java b/src/main/java/org/tkit/onecx/theme/domain/daos/ImageDAO.java index 3e1dd5e..8227da4 100644 --- a/src/main/java/org/tkit/onecx/theme/domain/daos/ImageDAO.java +++ b/src/main/java/org/tkit/onecx/theme/domain/daos/ImageDAO.java @@ -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); @@ -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); } } @@ -76,5 +73,7 @@ public enum ErrorKeys { FIND_ENTITY_BY_REF_ID_REF_TYPE_FAILED, + FAILED_TO_DELETE_BY_REF_ID_REF_TYPE_QUERY + } } diff --git a/src/test/java/org/tkit/onecx/theme/domain/daos/ImageDAOTest.java b/src/test/java/org/tkit/onecx/theme/domain/daos/ImageDAOTest.java index 585b31e..5e4621c 100644 --- a/src/test/java/org/tkit/onecx/theme/domain/daos/ImageDAOTest.java +++ b/src/test/java/org/tkit/onecx/theme/domain/daos/ImageDAOTest.java @@ -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; @@ -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); } diff --git a/src/test/java/org/tkit/onecx/theme/rs/internal/controllers/ImageRestControllerTest.java b/src/test/java/org/tkit/onecx/theme/rs/internal/controllers/ImageRestControllerTest.java index ee9a2a1..f2e0767 100644 --- a/src/test/java/org/tkit/onecx/theme/rs/internal/controllers/ImageRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/theme/rs/internal/controllers/ImageRestControllerTest.java @@ -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; @@ -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());