Refactor ICANN reporting and billing into common package

This moves the default yearMonth logic into a common ReportingModule, rather than the coarse-scoped BackendModule, which may not want the default parameter extraction logic, as well as moving the 'yearMonth' parameter constant to the common package it's used in. This also provides a basis for future consolidation of the ReportingEmailUtils and BillingEmailUtils classes, which have modest overlap.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183130311
This commit is contained in:
larryruili 2018-01-24 13:16:51 -08:00 committed by Ben McIlwain
parent 9d532cb507
commit 74ced1e907
71 changed files with 233 additions and 142 deletions

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.module.backend;
package google.registry.reporting;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.expectThrows;
@ -31,9 +31,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link BackendModule}. */
/** Unit tests for {@link ReportingModule}. */
@RunWith(JUnit4.class)
public class BackendModuleTest {
public class ReportingModuleTest {
private HttpServletRequest req = mock(HttpServletRequest.class);
private Clock clock;
@ -45,7 +45,7 @@ public class BackendModuleTest {
@Test
public void testEmptyYearMonthParameter_returnsEmptyYearMonthOptional() {
when(req.getParameter("yearMonth")).thenReturn("");
assertThat(BackendModule.provideYearMonthOptional(req)).isEqualTo(Optional.empty());
assertThat(ReportingModule.provideYearMonthOptional(req)).isEqualTo(Optional.empty());
}
@Test
@ -53,7 +53,7 @@ public class BackendModuleTest {
when(req.getParameter("yearMonth")).thenReturn("201705");
BadRequestException thrown =
expectThrows(
BadRequestException.class, () -> BackendModule.provideYearMonthOptional(req));
BadRequestException.class, () -> ReportingModule.provideYearMonthOptional(req));
assertThat(thrown)
.hasMessageThat()
.contains("yearMonth must be in yyyy-MM format, got 201705 instead");
@ -61,13 +61,13 @@ public class BackendModuleTest {
@Test
public void testEmptyYearMonth_returnsLastMonth() {
assertThat(BackendModule.provideYearMonth(Optional.empty(), clock))
assertThat(ReportingModule.provideYearMonth(Optional.empty(), clock))
.isEqualTo(new YearMonth(2017, 6));
}
@Test
public void testGivenYearMonth_returnsThatMonth() {
assertThat(BackendModule.provideYearMonth(Optional.of(new YearMonth(2017, 5)), clock))
assertThat(ReportingModule.provideYearMonth(Optional.of(new YearMonth(2017, 5)), clock))
.isEqualTo(new YearMonth(2017, 5));
}

View file

@ -11,8 +11,8 @@ java_library(
name = "billing",
srcs = glob(["*.java"]),
deps = [
"//java/google/registry/billing",
"//java/google/registry/gcs",
"//java/google/registry/reporting/billing",
"//java/google/registry/storage/drive",
"//java/google/registry/util",
"//javatests/google/registry/testing",

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.billing;
package google.registry.reporting.billing;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
@ -50,7 +50,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/** Unit tests for {@link BillingEmailUtils}. */
/** Unit tests for {@link google.registry.reporting.billing.BillingEmailUtils}. */
@RunWith(JUnit4.class)
public class BillingEmailUtilsTest {

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.billing;
package google.registry.reporting.billing;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
@ -47,7 +47,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link CopyDetailReportsAction}. */
/** Unit tests for {@link google.registry.reporting.billing.CopyDetailReportsAction}. */
@RunWith(JUnit4.class)
public class CopyDetailReportsActionTest {

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.billing;
package google.registry.reporting.billing;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
@ -41,7 +41,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link GenerateInvoicesAction}. */
/** Unit tests for {@link google.registry.reporting.billing.GenerateInvoicesAction}. */
@RunWith(JUnit4.class)
public class GenerateInvoicesActionTest {

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.billing;
package google.registry.reporting.billing;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
package google.registry.reporting.icann;
import static com.google.common.truth.Truth.assertThat;

View file

@ -0,0 +1,42 @@
package(
default_testonly = 1,
default_visibility = ["//java/google/registry:registry_project"],
)
licenses(["notice"]) # Apache 2.0
load("//java/com/google/testing/builddefs:GenTestRules.bzl", "GenTestRules")
java_library(
name = "icann",
srcs = glob(["*.java"]),
resources = glob(["testdata/*"]),
deps = [
"//java/google/registry/bigquery",
"//java/google/registry/gcs",
"//java/google/registry/reporting/icann",
"//java/google/registry/request",
"//java/google/registry/util",
"//javatests/google/registry/testing",
"@com_google_apis_google_api_services_bigquery",
"@com_google_appengine_api_1_0_sdk",
"@com_google_appengine_tools_appengine_gcs_client",
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_guava",
"@com_google_http_client",
"@com_google_truth",
"@com_google_truth_extensions_truth_java8_extension",
"@javax_servlet_api",
"@joda_time",
"@junit",
"@org_mockito_all",
],
)
GenTestRules(
name = "GeneratedTestRules",
default_test_size = "small",
test_files = glob(["*Test.java"]),
deps = [":icann"],
)

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
package google.registry.reporting.icann;
import static com.google.common.net.MediaType.CSV_UTF_8;
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
@ -40,7 +40,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Unit tests for {@link google.registry.reporting.IcannHttpReporter}.
* Unit tests for {@link IcannHttpReporter}.
*/
@RunWith(JUnit4.class)
public class IcannHttpReporterTest {

View file

@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
package google.registry.reporting.icann;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.reporting.IcannReportingModule.ReportType;
import google.registry.reporting.icann.IcannReportingModule.ReportType;
import google.registry.request.HttpException.BadRequestException;
import java.util.Optional;
import org.joda.time.YearMonth;
@ -25,7 +25,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link google.registry.reporting.IcannReportingModule}. */
/** Unit tests for {@link google.registry.reporting.icann.IcannReportingModule}. */
@RunWith(JUnit4.class)
public class IcannReportingModuleTest {

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
package google.registry.reporting.icann;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.GcsTestingUtils.readGcsFile;
@ -32,7 +32,7 @@ import google.registry.bigquery.BigqueryConnection;
import google.registry.bigquery.BigqueryConnection.DestinationTable;
import google.registry.bigquery.BigqueryUtils.TableType;
import google.registry.gcs.GcsUtils;
import google.registry.reporting.IcannReportingModule.ReportType;
import google.registry.reporting.icann.IcannReportingModule.ReportType;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeResponse;
import java.util.concurrent.ExecutionException;
@ -45,7 +45,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link google.registry.reporting.IcannReportingStager}. */
/** Unit tests for {@link google.registry.reporting.icann.IcannReportingStager}. */
@RunWith(JUnit4.class)
public class IcannReportingStagerTest {

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
package google.registry.reporting.icann;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.expectThrows;
@ -25,7 +25,7 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
import google.registry.bigquery.BigqueryJobFailureException;
import google.registry.reporting.IcannReportingModule.ReportType;
import google.registry.reporting.icann.IcannReportingModule.ReportType;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
@ -39,9 +39,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Unit tests for {@link google.registry.reporting.IcannReportingStagingAction}.
*/
/** Unit tests for {@link google.registry.reporting.icann.IcannReportingStagingAction}. */
@RunWith(JUnit4.class)
public class IcannReportingStagingActionTest {

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
package google.registry.reporting.icann;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.GcsTestingUtils.writeGcsFile;
@ -40,7 +40,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link google.registry.reporting.IcannReportingUploadAction} */
/** Unit tests for {@link google.registry.reporting.icann.IcannReportingUploadAction} */
@RunWith(JUnit4.class)
public class IcannReportingUploadActionTest {

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
package google.registry.reporting.icann;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
@ -30,7 +30,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link ReportingEmailUtils}. */
/** Unit tests for {@link google.registry.reporting.icann.ReportingEmailUtils}. */
@RunWith(JUnit4.class)
public class ReportingEmailUtilsTest {
private Message msg;

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
package google.registry.reporting.icann;
import com.google.common.io.ByteSource;
import google.registry.testing.TestDataHelper;

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
package google.registry.reporting.icann;
import static com.google.common.truth.Truth.assertThat;