Convert CountDomainsCommand to tm (#1092)

* Convert CountDomainsCommand to tm

As part of this, implement "select count(*)" queries in the QueryComposer.

* Replaced kludgy trick for objectify count
This commit is contained in:
Michael Muller 2021-04-20 10:38:38 -04:00 committed by GitHub
parent 48732c51e8
commit 4657be21b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 16 deletions

View file

@ -111,6 +111,17 @@ public class QueryComposerTest {
.isEqualTo(alpha);
}
@TestOfyAndSql
public void testCount() {
assertThat(
transactIfJpaTm(
() ->
tm().createQueryComposer(TestEntity.class)
.where("name", Comparator.GTE, "bravo")
.count()))
.isEqualTo(2L);
}
@TestOfyAndSql
public void testGetSingleResult() {
assertThat(

View file

@ -19,12 +19,14 @@ import static google.registry.testing.DatabaseHelper.persistActiveDomain;
import static google.registry.testing.DatabaseHelper.persistDeletedDomain;
import google.registry.model.ofy.Ofy;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.InjectExtension;
import google.registry.testing.TestOfyAndSql;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link CountDomainsCommand}. */
@DualDatabaseTest
public class CountDomainsCommandTest extends CommandTestCase<CountDomainsCommand> {
@RegisterExtension public final InjectExtension inject = new InjectExtension();
@ -36,7 +38,7 @@ public class CountDomainsCommandTest extends CommandTestCase<CountDomainsCommand
createTlds("foo", "bar", "baz", "qux");
}
@Test
@TestOfyAndSql
void testSuccess_singleTld() throws Exception {
for (int i = 0; i < 51; i++) {
persistActiveDomain(String.format("test-%d.foo", i));
@ -48,7 +50,7 @@ public class CountDomainsCommandTest extends CommandTestCase<CountDomainsCommand
assertStdoutIs("foo,51\n");
}
@Test
@TestOfyAndSql
void testSuccess_multipleTlds() throws Exception {
for (int i = 0; i < 29; i++) {
persistActiveDomain(String.format("test-%d.foo", i));