mirror of
https://github.com/google/nomulus
synced 2026-09-06 16:17:13 +00:00
Convert most poll message queries to QueryComposer (#1151)
* Convert most poll message queries to QueryComposer * Add unit test and a better exception for datastore * Remove datastorePollMessageQuery from PollFlowUtils * Reformatted. * Improved test equality checks * Changes for review * Converted concatenated string to String.format()
This commit is contained in:
@@ -21,7 +21,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
|
||||
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
@@ -169,7 +168,7 @@ public class QueryComposerTest {
|
||||
.where("name", Comparator.EQ, "alpha")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.isEqualTo(ImmutableList.of(alpha));
|
||||
.containsExactly(alpha);
|
||||
assertThat(
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
@@ -178,7 +177,7 @@ public class QueryComposerTest {
|
||||
.where("name", Comparator.GT, "alpha")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.isEqualTo(ImmutableList.of(bravo, charlie));
|
||||
.containsExactly(bravo, charlie);
|
||||
assertThat(
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
@@ -187,7 +186,7 @@ public class QueryComposerTest {
|
||||
.where("name", Comparator.GTE, "bravo")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.isEqualTo(ImmutableList.of(bravo, charlie));
|
||||
.containsExactly(bravo, charlie);
|
||||
assertThat(
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
@@ -196,7 +195,7 @@ public class QueryComposerTest {
|
||||
.where("name", Comparator.LT, "charlie")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.isEqualTo(ImmutableList.of(alpha, bravo));
|
||||
.containsExactly(alpha, bravo);
|
||||
assertThat(
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
@@ -205,7 +204,7 @@ public class QueryComposerTest {
|
||||
.where("name", Comparator.LTE, "bravo")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.isEqualTo(ImmutableList.of(alpha, bravo));
|
||||
.containsExactly(alpha, bravo);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@@ -216,7 +215,7 @@ public class QueryComposerTest {
|
||||
tm().createQueryComposer(TestEntity.class)
|
||||
.where("name", Comparator.GT, "alpha")
|
||||
.list()))
|
||||
.isEqualTo(ImmutableList.of(bravo, charlie));
|
||||
.containsExactly(bravo, charlie);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@@ -242,7 +241,7 @@ public class QueryComposerTest {
|
||||
.orderBy("val")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.isEqualTo(ImmutableList.of(bravo, alpha));
|
||||
.containsExactly(bravo, alpha);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@@ -262,7 +261,7 @@ public class QueryComposerTest {
|
||||
.where("name", Comparator.GT, "foxtrot")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.isEqualTo(ImmutableList.of());
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
@@ -292,6 +291,65 @@ public class QueryComposerTest {
|
||||
.containsExactly(alpha);
|
||||
}
|
||||
|
||||
@TestSqlOnly
|
||||
public void testLikeQueries() {
|
||||
assertThat(
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
tm()
|
||||
.createQueryComposer(TestEntity.class)
|
||||
.where("name", Comparator.LIKE, "%harl%")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.containsExactly(charlie);
|
||||
|
||||
// Verify that full matches work.
|
||||
assertThat(
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
tm()
|
||||
.createQueryComposer(TestEntity.class)
|
||||
.where("name", Comparator.LIKE, "alpha")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.containsExactly(alpha);
|
||||
|
||||
// verify that we don't do partial matches.
|
||||
assertThat(
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
tm()
|
||||
.createQueryComposer(TestEntity.class)
|
||||
.where("name", Comparator.LIKE, "%harl")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.isEmpty();
|
||||
assertThat(
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
tm()
|
||||
.createQueryComposer(TestEntity.class)
|
||||
.where("name", Comparator.LIKE, "harl%")
|
||||
.stream()
|
||||
.collect(toImmutableList())))
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
public void testLikeQueries_failsOnOfy() {
|
||||
UnsupportedOperationException thrown =
|
||||
assertThrows(
|
||||
UnsupportedOperationException.class,
|
||||
() ->
|
||||
tm()
|
||||
.createQueryComposer(TestEntity.class)
|
||||
.where("name", Comparator.LIKE, "%")
|
||||
.stream());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("The LIKE operation is not supported on Datastore.");
|
||||
}
|
||||
|
||||
@javax.persistence.Entity
|
||||
@Entity(name = "QueryComposerTestEntity")
|
||||
private static class TestEntity extends ImmutableObject {
|
||||
|
||||
Reference in New Issue
Block a user