diff --git a/dao/src/main/java/se/fortnox/reactivewizard/db/query/ParameterizedQuery.java b/dao/src/main/java/se/fortnox/reactivewizard/db/query/ParameterizedQuery.java index 9ddae799..30f4ba82 100644 --- a/dao/src/main/java/se/fortnox/reactivewizard/db/query/ParameterizedQuery.java +++ b/dao/src/main/java/se/fortnox/reactivewizard/db/query/ParameterizedQuery.java @@ -41,10 +41,6 @@ private List createQueryParts(String sqlInput, Method method) throws sqlInput = sqlPreProcess(sqlInput); - if (sqlInput.indexOf('?') != -1) { - throw new RuntimeException("Unnamed parameters are not supported: " + sqlInput); - } - int pos = 0; Matcher matcher = NAMED_PARAMETER_PATTERN.matcher(sqlInput); if (matcher.find()) { diff --git a/dao/src/test/java/se/fortnox/reactivewizard/db/ParameterizedQueryTest.java b/dao/src/test/java/se/fortnox/reactivewizard/db/ParameterizedQueryTest.java index 0c0e0b4b..08cf6c94 100644 --- a/dao/src/test/java/se/fortnox/reactivewizard/db/ParameterizedQueryTest.java +++ b/dao/src/test/java/se/fortnox/reactivewizard/db/ParameterizedQueryTest.java @@ -14,8 +14,8 @@ import java.util.Map; import java.util.UUID; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -23,7 +23,6 @@ import static org.mockito.Mockito.when; class ParameterizedQueryTest { - MockDb db = new MockDb(); DbProxy dbProxy = new DbProxy(new DatabaseConfig(), db.getConnectionProvider()); TestDao dao = dbProxy.create(TestDao.class); @@ -65,25 +64,21 @@ void shouldResolveParametersWithoutAnnotationFromQuery() throws SQLException { } @Test - void shouldThrowExceptionIfUnnamedParamsUsedInQuery() { - try { - dao.unnamedParameters("myid", "myname").blockLast(); - fail("Exptected exception"); - } catch (Exception e) { - assertThat(e.getMessage()) - .isEqualTo("Unnamed parameters are not supported: SELECT * FROM foo WHERE id=? AND name=?"); - } + void shouldNotThrowExceptionIfUnnamedParamsUsedInQuery() { + assertThatNoException() + .isThrownBy(() -> dao.unnamedParameters("myid", "myname").blockLast()); + } + + @Test + void shouldAllowJsonOperators() { + assertThatNoException().isThrownBy(() -> dao.jsonOperators().blockLast()); } @Test void shouldThrowExceptionIfNotAllParametersAreFound() { - try { - dao.missingParamName("myid", "myname").blockLast(); - fail("Exptected exception"); - } catch (Exception e) { - assertThat(e.getMessage()).isEqualTo( - "Query contains placeholder \"name\" but method noes not have such argument"); - } + assertThatExceptionOfType(RuntimeException.class) + .isThrownBy(() -> dao.missingParamName("myid", "myname").blockLast()) + .withMessage("Query contains placeholder \"name\" but method noes not have such argument"); } @Test @@ -323,10 +318,11 @@ interface TestDao { @Query("SELECT x FROM y WHERE z IN (:param)") Flux inClauseUuid(List param); - @Query("SELECT x FROM y WHERE z IN (:param)") - Flux unsupportedArrayType(List param); + @Query("SELECT * FROM message_projections WHERE message_json->'categories' ?| array['newsletter', 'spam']") + Flux jsonOperators(); } + @SuppressWarnings("unused") public class TestObject { TestEnum myEnum; boolean finished;