mirror of
https://github.com/google/nomulus.git
synced 2025-08-20 16:34:11 +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
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue