mirror of
https://github.com/google/nomulus.git
synced 2025-08-06 09:45:19 +02:00
Fix reporting module parameters and yearMonth usage
This is a final refactor to address Nick's comments in [] where YearMonth really should be injected as a Joda type instead of a raw string, and the HTTP parameters should be separate from the default-provided dependencies. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=173539965
This commit is contained in:
parent
d22986a0a3
commit
4a9b8b918a
14 changed files with 109 additions and 87 deletions
|
@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.io.IOException;
|
||||
import org.joda.time.YearMonth;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
@ -29,7 +30,7 @@ public class ActivityReportingQueryBuilderTest {
|
|||
|
||||
private ActivityReportingQueryBuilder getQueryBuilder() {
|
||||
ActivityReportingQueryBuilder queryBuilder = new ActivityReportingQueryBuilder();
|
||||
queryBuilder.yearMonth = "2017-09";
|
||||
queryBuilder.yearMonth = new YearMonth(2017, 9);
|
||||
queryBuilder.projectId = "domain-registry-alpha";
|
||||
return queryBuilder;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.reporting;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import google.registry.reporting.IcannReportingModule.ReportType;
|
||||
import google.registry.request.HttpException.BadRequestException;
|
||||
|
@ -25,6 +26,7 @@ import google.registry.util.Clock;
|
|||
import java.util.Optional;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.YearMonth;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -46,32 +48,41 @@ public class IcannReportingModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyYearMonth_returnsCurrentDate() {
|
||||
assertThat(IcannReportingModule.provideYearMonth(Optional.empty(), clock)).isEqualTo("2017-06");
|
||||
public void testEmptyYearMonthParameter_returnsEmptyYearMonthOptional() {
|
||||
when(req.getParameter("yearMonth")).thenReturn("");
|
||||
assertThat(IcannReportingModule.provideYearMonthOptional(req)).isEqualTo(Optional.empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidYearMonthParameter_throwsException() {
|
||||
when(req.getParameter("yearMonth")).thenReturn("201705");
|
||||
thrown.expect(
|
||||
BadRequestException.class, "yearMonth must be in yyyy-MM format, got 201705 instead");
|
||||
IcannReportingModule.provideYearMonthOptional(req);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyYearMonth_returnsLastMonth() {
|
||||
assertThat(IcannReportingModule.provideYearMonth(Optional.empty(), clock))
|
||||
.isEqualTo(new YearMonth(2017, 6));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGivenYearMonth_returnsThatMonth() {
|
||||
assertThat(IcannReportingModule.provideYearMonth(Optional.of("2017-05"), clock))
|
||||
.isEqualTo("2017-05");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidYearMonth_throwsException() {
|
||||
thrown.expect(
|
||||
BadRequestException.class, "yearMonth must be in yyyy-MM format, got 201705 instead");
|
||||
IcannReportingModule.provideYearMonth(Optional.of("201705"), clock);
|
||||
assertThat(IcannReportingModule.provideYearMonth(Optional.of(new YearMonth(2017, 5)), clock))
|
||||
.isEqualTo(new YearMonth(2017, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySubDir_returnsDefaultSubdir() {
|
||||
assertThat(IcannReportingModule.provideSubdir(Optional.empty(), "2017-06"))
|
||||
assertThat(IcannReportingModule.provideSubdir(Optional.empty(), new YearMonth(2017, 6)))
|
||||
.isEqualTo("icann/monthly/2017-06");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGivenSubdir_returnsManualSubdir() {
|
||||
assertThat(IcannReportingModule.provideSubdir(Optional.of("manual/dir"), "2017-06"))
|
||||
assertThat(
|
||||
IcannReportingModule.provideSubdir(Optional.of("manual/dir"), new YearMonth(2017, 6)))
|
||||
.isEqualTo("manual/dir");
|
||||
}
|
||||
|
||||
|
@ -80,7 +91,7 @@ public class IcannReportingModuleTest {
|
|||
thrown.expect(
|
||||
BadRequestException.class,
|
||||
"subdir must not start or end with a \"/\", got /whoops instead.");
|
||||
IcannReportingModule.provideSubdir(Optional.of("/whoops"), "2017-06");
|
||||
IcannReportingModule.provideSubdir(Optional.of("/whoops"), new YearMonth(2017, 6));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -39,6 +39,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import org.joda.time.YearMonth;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -62,14 +63,14 @@ public class IcannReportingStagerTest {
|
|||
IcannReportingStager action = new IcannReportingStager();
|
||||
ActivityReportingQueryBuilder activityBuilder = new ActivityReportingQueryBuilder();
|
||||
activityBuilder.projectId = "test-project";
|
||||
activityBuilder.yearMonth = "2017-06";
|
||||
activityBuilder.yearMonth = new YearMonth(2017, 6);
|
||||
action.activityQueryBuilder = activityBuilder;
|
||||
TransactionsReportingQueryBuilder transactionsBuilder = new TransactionsReportingQueryBuilder();
|
||||
transactionsBuilder.projectId = "test-project";
|
||||
transactionsBuilder.yearMonth = "2017-06";
|
||||
transactionsBuilder.yearMonth = new YearMonth(2017, 6);
|
||||
action.transactionsQueryBuilder = transactionsBuilder;
|
||||
action.reportingBucket = "test-bucket";
|
||||
action.yearMonth = "2017-06";
|
||||
action.yearMonth = new YearMonth(2017, 6);
|
||||
action.subdir = "icann/monthly/2017-06";
|
||||
action.bigquery = bigquery;
|
||||
action.gcsUtils = new GcsUtils(gcsService, 1024);
|
||||
|
|
|
@ -131,4 +131,3 @@ public class IcannReportingStagingActionTest {
|
|||
+ " check logs for more details.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.io.IOException;
|
||||
import org.joda.time.YearMonth;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
@ -29,7 +30,7 @@ public class TransactionsReportingQueryBuilderTest {
|
|||
|
||||
private TransactionsReportingQueryBuilder getQueryBuilder() {
|
||||
TransactionsReportingQueryBuilder queryBuilder = new TransactionsReportingQueryBuilder();
|
||||
queryBuilder.yearMonth = "2017-09";
|
||||
queryBuilder.yearMonth = new YearMonth(2017, 9);
|
||||
queryBuilder.projectId = "domain-registry-alpha";
|
||||
return queryBuilder;
|
||||
}
|
||||
|
|
|
@ -45,12 +45,12 @@ JOIN (
|
|||
`domain-registry-alpha.latest_datastore_export.DomainBase`,
|
||||
UNNEST(nsHosts) AS hosts
|
||||
WHERE _d = 'DomainResource'
|
||||
AND creationTime <= TIMESTAMP("2017-09-30 23:59:59")
|
||||
AND deletionTime > TIMESTAMP("2017-09-30 23:59:59") ) AS domain_table
|
||||
AND creationTime <= TIMESTAMP("2017-09-30 23:59:59.999")
|
||||
AND deletionTime > TIMESTAMP("2017-09-30 23:59:59.999") ) AS domain_table
|
||||
ON
|
||||
host_table.__key__.name = domain_table.referencedHostName
|
||||
WHERE creationTime <= TIMESTAMP("2017-09-30 23:59:59")
|
||||
AND deletionTime > TIMESTAMP("2017-09-30 23:59:59")
|
||||
WHERE creationTime <= TIMESTAMP("2017-09-30 23:59:59.999")
|
||||
AND deletionTime > TIMESTAMP("2017-09-30 23:59:59.999")
|
||||
GROUP BY tld, registrarName
|
||||
ORDER BY tld, registrarName
|
||||
|
||||
|
|
|
@ -63,8 +63,8 @@ FROM (
|
|||
WHERE entries.domainTransactionRecords IS NOT NULL )
|
||||
-- Only look at this month's data
|
||||
WHERE reportingTime
|
||||
BETWEEN TIMESTAMP('2017-09-01 00:00:00')
|
||||
AND TIMESTAMP('2017-09-30 23:59:59')
|
||||
BETWEEN TIMESTAMP('2017-09-01 00:00:00.000')
|
||||
AND TIMESTAMP('2017-09-30 23:59:59.999')
|
||||
GROUP BY
|
||||
tld,
|
||||
clientId,
|
||||
|
|
|
@ -63,8 +63,8 @@ FROM (
|
|||
WHERE entries.domainTransactionRecords IS NOT NULL )
|
||||
-- Only look at this month's data
|
||||
WHERE reportingTime
|
||||
BETWEEN TIMESTAMP('2017-09-01 00:00:00')
|
||||
AND TIMESTAMP('2017-09-30 23:59:59')
|
||||
BETWEEN TIMESTAMP('2017-09-01 00:00:00.000')
|
||||
AND TIMESTAMP('2017-09-30 23:59:59.999')
|
||||
GROUP BY
|
||||
tld,
|
||||
clientId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue